2017-09-23 04:34:07 +02:00
|
|
|
import CustomWizard from '../models/custom-wizard';
|
2017-10-05 02:36:46 +02:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
export default Discourse.Route.extend({
|
2017-10-13 15:02:34 +02:00
|
|
|
beforeModel() {
|
|
|
|
const param = this.paramsFor('adminWizard').wizard_id;
|
|
|
|
const wizards = this.modelFor('admin-wizards-custom');
|
|
|
|
|
|
|
|
if (wizards.length && (param === 'first' || param === 'last')) {
|
|
|
|
const wizard = wizards.get(`${param}Object`);
|
|
|
|
if (wizard) {
|
|
|
|
this.transitionTo('adminWizard', wizard.id.dasherize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
model(params) {
|
2017-10-13 15:02:34 +02:00
|
|
|
const wizardId = params.wizard_id;
|
|
|
|
|
|
|
|
if (wizardId === 'new') {
|
2017-10-07 04:27:38 +02:00
|
|
|
this.set('newWizard', true);
|
2017-09-29 13:27:03 +02:00
|
|
|
return CustomWizard.create();
|
2017-10-09 07:52:09 +02:00
|
|
|
};
|
2017-10-07 04:27:38 +02:00
|
|
|
this.set('newWizard', false);
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2017-10-13 15:02:34 +02:00
|
|
|
const wizard = this.modelFor('admin-wizards-custom').findBy('id', wizardId.underscore());
|
|
|
|
|
|
|
|
if (!wizard) return this.transitionTo('adminWizard', 'new');
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
return wizard;
|
|
|
|
},
|
|
|
|
|
2017-10-05 02:36:46 +02:00
|
|
|
afterModel(model) {
|
2017-12-17 04:43:18 +01:00
|
|
|
return Ember.RSVP.all([
|
|
|
|
this._getFieldTypes(model),
|
|
|
|
this._getThemes(model)
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
_getFieldTypes(model) {
|
2017-10-05 02:36:46 +02:00
|
|
|
return ajax('/admin/wizards/field-types')
|
|
|
|
.then((result) => model.set('fieldTypes', result.types));
|
|
|
|
},
|
|
|
|
|
2017-12-17 04:43:18 +01:00
|
|
|
_getThemes(model) {
|
|
|
|
return this.store.findAll('theme').then((result) => {
|
|
|
|
model.set('themes', result.content);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
setupController(controller, model) {
|
2017-10-07 04:27:38 +02:00
|
|
|
const newWizard = this.get('newWizard');
|
|
|
|
const steps = model.get('steps') || [];
|
|
|
|
controller.setProperties({
|
|
|
|
newWizard,
|
|
|
|
model,
|
|
|
|
currentStep: steps[0]
|
|
|
|
});
|
2017-10-06 04:59:02 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2017-10-07 04:27:38 +02:00
|
|
|
refreshWizard() {
|
2017-10-06 04:59:02 +02:00
|
|
|
this.refresh();
|
|
|
|
}
|
2017-09-23 04:34:07 +02:00
|
|
|
}
|
|
|
|
});
|