custom-wizard.js.es6 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { ajax } from 'discourse/lib/ajax';
  2. import { default as computed } from 'ember-addons/ember-computed-decorators';
  3. const CustomWizard = Discourse.Model.extend({
  4. steps: Ember.A(),
  5. @computed('name')
  6. dasherizedName(name) {
  7. return Ember.String.dasherize(name);
  8. },
  9. save() {
  10. const wizard = {
  11. id: this.get('id'),
  12. steps: this.get('steps').toArray(),
  13. name: this.get('name')
  14. };
  15. return ajax(`/admin/wizards/custom/save`, {
  16. type: 'PUT',
  17. data: {
  18. wizard: JSON.stringify(wizard)
  19. }
  20. });
  21. },
  22. remove() {
  23. return ajax(`/admin/wizards/custom/remove`, {
  24. type: 'DELETE',
  25. data: {
  26. id: this.get('id')
  27. }
  28. }).then(() => this.destroy());
  29. }
  30. });
  31. CustomWizard.reopenClass({
  32. findAll() {
  33. return ajax("/admin/wizards/custom/all").then(result => {
  34. return result.wizards.map(w => CustomWizard.create(w));
  35. });
  36. },
  37. create() {
  38. const wizard = this._super.apply(this, arguments);
  39. const steps = wizard.get('steps');
  40. steps.forEach((s) => {
  41. s.fields = Ember.A(s.fields);
  42. s.fields.forEach((f) => f.choices = Ember.A(f.choices));
  43. s.actions = Ember.A(s.actions);
  44. });
  45. return wizard;
  46. }
  47. });
  48. export default CustomWizard;