admin-wizard.js.es6 906 B

1234567891011121314151617181920212223242526272829303132333435
  1. import CustomWizard from '../models/custom-wizard';
  2. import { ajax } from 'discourse/lib/ajax';
  3. export default Discourse.Route.extend({
  4. model(params) {
  5. if (params.wizard_id === 'new') {
  6. this.set('new', true);
  7. return CustomWizard.create();
  8. }
  9. this.set('new', false);
  10. const wizard = this.modelFor('admin-wizards-custom').findBy('id', params.wizard_id);
  11. if (!wizard) return this.transitionTo('adminWizardsCustom.index');
  12. return wizard;
  13. },
  14. afterModel(model) {
  15. return ajax('/admin/wizards/field-types')
  16. .then((result) => model.set('fieldTypes', result.types));
  17. },
  18. setupController(controller, model) {
  19. let props = { new: this.get('new'), model };
  20. const steps = model.get('steps');
  21. if (steps[0]) props['currentStep'] = steps[0];
  22. controller.setProperties(props);
  23. },
  24. actions: {
  25. refreshRoute() {
  26. this.refresh();
  27. }
  28. }
  29. });