admin-wizard.js.es6 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Ember.RSVP.all([
  27. this._getFieldTypes(model),
  28. this._getThemes(model)
  29. ]);
  30. },
  31. _getFieldTypes(model) {
  32. return ajax('/admin/wizards/field-types')
  33. .then((result) => model.set('fieldTypes', result.types));
  34. },
  35. _getThemes(model) {
  36. return this.store.findAll('theme').then((result) => {
  37. model.set('themes', result.content);
  38. });
  39. },
  40. setupController(controller, model) {
  41. const newWizard = this.get('newWizard');
  42. const steps = model.get('steps') || [];
  43. controller.setProperties({
  44. newWizard,
  45. model,
  46. currentStep: steps[0]
  47. });
  48. },
  49. actions: {
  50. refreshWizard() {
  51. this.refresh();
  52. }
  53. }
  54. });