Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-30 04:30:29 +01:00
53 Zeilen
1,3 KiB
JavaScript
53 Zeilen
1,3 KiB
JavaScript
import CustomWizard from '../models/custom-wizard';
|
|
import { ajax } from 'discourse/lib/ajax';
|
|
|
|
export default Discourse.Route.extend({
|
|
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());
|
|
}
|
|
}
|
|
},
|
|
|
|
model(params) {
|
|
const wizardId = params.wizard_id;
|
|
|
|
if (wizardId === 'new') {
|
|
this.set('newWizard', true);
|
|
return CustomWizard.create();
|
|
};
|
|
this.set('newWizard', false);
|
|
|
|
const wizard = this.modelFor('admin-wizards-custom').findBy('id', wizardId.underscore());
|
|
|
|
if (!wizard) return this.transitionTo('adminWizard', 'new');
|
|
|
|
return wizard;
|
|
},
|
|
|
|
afterModel(model) {
|
|
return ajax('/admin/wizards/field-types')
|
|
.then((result) => model.set('fieldTypes', result.types));
|
|
},
|
|
|
|
setupController(controller, model) {
|
|
const newWizard = this.get('newWizard');
|
|
const steps = model.get('steps') || [];
|
|
controller.setProperties({
|
|
newWizard,
|
|
model,
|
|
currentStep: steps[0]
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
refreshWizard() {
|
|
this.refresh();
|
|
}
|
|
}
|
|
});
|