admin-wizard.js.es6 944 B

1234567891011121314151617181920212223242526272829303132333435363738
  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('newWizard', true);
  7. return CustomWizard.create();
  8. };
  9. this.set('newWizard', false);
  10. const wizard = this.modelFor('admin-wizards-custom').findBy('id', params.wizard_id.underscore());
  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. const newWizard = this.get('newWizard');
  20. const steps = model.get('steps') || [];
  21. controller.setProperties({
  22. newWizard,
  23. model,
  24. currentStep: steps[0]
  25. });
  26. },
  27. actions: {
  28. refreshWizard() {
  29. this.refresh();
  30. }
  31. }
  32. });