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({
|
|
|
|
model(params) {
|
2017-09-29 13:27:03 +02:00
|
|
|
if (params.wizard_id === 'new') {
|
2017-09-23 04:34:07 +02:00
|
|
|
this.set('new', true);
|
2017-09-29 13:27:03 +02:00
|
|
|
return CustomWizard.create();
|
2017-09-23 04:34:07 +02:00
|
|
|
}
|
|
|
|
this.set('new', false);
|
|
|
|
|
2017-09-29 13:27:03 +02:00
|
|
|
const wizard = this.modelFor('admin-wizards-custom').findBy('id', params.wizard_id);
|
2017-09-24 05:01:18 +02:00
|
|
|
if (!wizard) return this.transitionTo('adminWizardsCustom.index');
|
2017-09-23 04:34:07 +02:00
|
|
|
|
|
|
|
return wizard;
|
|
|
|
},
|
|
|
|
|
2017-10-05 02:36:46 +02:00
|
|
|
afterModel(model) {
|
|
|
|
return ajax('/admin/wizards/field-types')
|
|
|
|
.then((result) => model.set('fieldTypes', result.types));
|
|
|
|
},
|
|
|
|
|
2017-09-23 04:34:07 +02:00
|
|
|
setupController(controller, model) {
|
2017-10-06 04:59:02 +02:00
|
|
|
let props = { new: this.get('new'), model };
|
|
|
|
const steps = model.get('steps');
|
|
|
|
if (steps[0]) props['currentStep'] = steps[0];
|
|
|
|
controller.setProperties(props);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
refreshRoute() {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2017-09-23 04:34:07 +02:00
|
|
|
}
|
|
|
|
});
|