admin-wizard.js.es6 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { default as computed } from 'ember-addons/ember-computed-decorators';
  2. export default Ember.Controller.extend({
  3. @computed('model.steps.[]', 'currentStep')
  4. stepLinks(steps, currentStep) {
  5. return steps.map((s) => {
  6. if (s) {
  7. const id = s.get('id');
  8. const title = s.get('title');
  9. let link = { id, title: title || id };
  10. let classes = 'btn';
  11. if (currentStep && id === currentStep.get('id')) {
  12. classes += ' btn-primary';
  13. };
  14. link['classes'] = classes;
  15. return link;
  16. }
  17. });
  18. },
  19. @computed('model.id', 'model.name')
  20. wizardUrl(wizardId) {
  21. return window.location.origin + '/wizard/custom/' + Ember.String.dasherize(wizardId);
  22. },
  23. actions: {
  24. save() {
  25. this.get('model').save().then(() => {
  26. if (this.get('newWizard')) {
  27. this.send("refreshAllWizards");
  28. } else {
  29. this.send("refreshWizard");
  30. }
  31. });
  32. },
  33. remove() {
  34. this.get('model').remove().then(() => {
  35. this.send("refreshAllWizards");
  36. });
  37. },
  38. addStep() {
  39. const steps = this.get('model.steps');
  40. const newNum = steps.length + 1;
  41. const step = Ember.Object.create({
  42. fields: Ember.A(),
  43. actions: Ember.A(),
  44. id: `step-${newNum}`
  45. });
  46. steps.pushObject(step);
  47. this.set('currentStep', step);
  48. },
  49. removeStep(stepId) {
  50. const steps = this.get('model.steps');
  51. steps.removeObject(steps.findBy('id', stepId));
  52. this.set('currentStep', steps[steps.length - 1]);
  53. },
  54. changeStep(stepId) {
  55. const steps = this.get('model.steps');
  56. this.set('currentStep', steps.findBy('id', stepId));
  57. }
  58. }
  59. });