Add locale step

This commit is contained in:
Robin Ward
2016-09-22 09:52:19 -04:00
parent 3f6e3b9aff
commit c94e6f1b96
25 changed files with 746 additions and 90 deletions
@@ -68,7 +68,7 @@ export default Ember.Component.extend({
loaded: false,
logo: null,
colorScheme: Ember.computed.alias('step.fieldsById.color_scheme.value'),
themeId: Ember.computed.alias('step.fieldsById.theme_id.value'),
didInsertElement() {
this._super();
@@ -84,7 +84,7 @@ export default Ember.Component.extend({
});
},
@observes('colorScheme')
@observes('themeId')
triggerRepaint() {
Ember.run.scheduleOnce('afterRender', this, 'repaint');
},
@@ -95,10 +95,10 @@ export default Ember.Component.extend({
const { ctx } = this;
const headerHeight = HEIGHT * 0.15;
const colorScheme = this.get('colorScheme');
const options = this.get('step.fieldsById.color_scheme.options');
const option = options.findProperty('id', colorScheme);
if (!option) { return; }
const themeId = this.get('themeId');
const choices = this.get('step.fieldsById.theme_id.choices');
if (!choices) { return; }
const option = choices.findProperty('id', themeId);
const colors = option.data.colors;
if (!colors) { return; }
@@ -48,20 +48,6 @@ export default Ember.Component.extend({
});
},
saveStep() {
const step = this.get('step');
step.save()
.then(() => this.sendAction('goNext'))
.catch(response => {
const errors = response.responseJSON.errors;
if (errors && errors.length) {
errors.forEach(err => {
step.fieldError(err.field, err.description);
});
}
});
},
actions: {
backStep() {
if (this.get('saving')) { return; }
@@ -77,7 +63,7 @@ export default Ember.Component.extend({
if (step.get('valid')) {
this.set('saving', true);
step.save()
.then(() => this.sendAction('goNext'))
.then(response => this.sendAction('goNext', response))
.catch(() => null) // we can swallow because the form is already marked as invalid
.finally(() => this.set('saving', false));
} else {
@@ -3,8 +3,13 @@ export default Ember.Controller.extend({
step: null,
actions: {
goNext() {
this.transitionToRoute('step', this.get('step.next'));
goNext(response) {
const next = this.get('step.next');
if (response.refresh_required) {
document.location = `/wizard/steps/${next}`;
} else {
this.transitionToRoute('step', next);
}
},
goBack() {
this.transitionToRoute('step', this.get('step.previous'));
+4 -3
View File
@@ -1,9 +1,10 @@
const Router = Ember.Router.extend({
location: Ember.testing ? 'none': 'hash'
rootURL: '/wizard',
location: Ember.testing ? 'none': 'history'
});
Router.map(function () {
this.route('step', { path: '/step/:step_id' });
Router.map(function() {
this.route('step', { path: '/steps/:step_id' });
});
export default Router;
@@ -1 +1 @@
{{combo-box class=inputClassName value=field.value content=field.options nameProperty="label" width="400px"}}
{{combo-box class=inputClassName value=field.value content=field.choices nameProperty="label" width="400px"}}
@@ -9,7 +9,7 @@ test("Wizard starts", assert => {
});
test("Going back and forth in steps", assert => {
visit("/step/hello-world");
visit("/steps/hello-world");
andThen(() => {
assert.ok(exists('.wizard-step'));
assert.ok(exists('.wizard-step-hello-world'), 'it adds a class for the step id');
@@ -51,7 +51,7 @@ export default function() {
index: 1,
fields: [
{ id: 'snack', type: 'dropdown', required: true },
{ id: 'scheme-preview', type: 'component' }
{ id: 'theme-preview', type: 'component' }
],
previous: 'hello-world'
}]