custom-wizard.js.es6 872 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { ajax } from 'discourse/lib/ajax';
  2. const CustomWizard = Discourse.Model.extend({
  3. steps: Ember.A(),
  4. save() {
  5. const steps = JSON.stringify(this.get('steps').toArray());
  6. return ajax(`/admin/wizards/custom/${this.get('name')}`, {
  7. type: 'PUT',
  8. data: { steps }
  9. });
  10. },
  11. destroy() {
  12. return ajax(`/admin/wizards/custom/${this.get('name')}`, {
  13. type: 'DELETE'
  14. });
  15. }
  16. });
  17. CustomWizard.reopenClass({
  18. findAll() {
  19. return ajax("/admin/wizards/custom/all").then(result => {
  20. return result.wizards.map(w => CustomWizard.create(w));
  21. });
  22. },
  23. create() {
  24. const wizard = this._super.apply(this, arguments);
  25. const steps = wizard.get('steps');
  26. steps.forEach((s) => {
  27. s.fields = Ember.A(s.fields);
  28. s.actions = Ember.A(s.actions);
  29. });
  30. return wizard;
  31. }
  32. });
  33. export default CustomWizard;