admin-wizard.js.es6 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import CustomWizard from '../models/custom-wizard';
  2. import { ajax } from 'discourse/lib/ajax';
  3. export default Discourse.Route.extend({
  4. beforeModel() {
  5. const param = this.paramsFor('adminWizard').wizard_id;
  6. const wizards = this.modelFor('admin-wizards-custom');
  7. if (wizards.length && (param === 'first' || param === 'last')) {
  8. const wizard = wizards.get(`${param}Object`);
  9. if (wizard) {
  10. this.transitionTo('adminWizard', wizard.id.dasherize());
  11. }
  12. }
  13. },
  14. model(params) {
  15. const wizardId = params.wizard_id;
  16. if (wizardId === 'new') {
  17. this.set('newWizard', true);
  18. return CustomWizard.create();
  19. };
  20. this.set('newWizard', false);
  21. const wizard = this.modelFor('admin-wizards-custom').findBy('id', wizardId.underscore());
  22. if (!wizard) return this.transitionTo('adminWizard', 'new');
  23. return wizard;
  24. },
  25. afterModel(model) {
  26. return ajax('/admin/wizards/field-types')
  27. .then((result) => model.set('fieldTypes', result.types));
  28. },
  29. setupController(controller, model) {
  30. const newWizard = this.get('newWizard');
  31. const steps = model.get('steps') || [];
  32. controller.setProperties({
  33. newWizard,
  34. model,
  35. currentStep: steps[0]
  36. });
  37. },
  38. actions: {
  39. refreshWizard() {
  40. this.refresh();
  41. }
  42. }
  43. });