admin-wizard.js.es6 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { default as computed } from 'ember-addons/ember-computed-decorators';
  2. import showModal from 'discourse/lib/show-modal';
  3. export default Ember.Controller.extend({
  4. @computed('model.id', 'model.name')
  5. wizardUrl(wizardId) {
  6. return window.location.origin + '/w/' + Ember.String.dasherize(wizardId);
  7. },
  8. @computed('model.after_time_scheduled')
  9. nextSessionScheduledLabel(scheduled) {
  10. return scheduled ? moment(scheduled).format('MMMM Do, HH:mm') :
  11. I18n.t('admin.wizard.after_time_time_label');
  12. },
  13. actions: {
  14. save() {
  15. this.setProperties({
  16. saving: true,
  17. error: null
  18. });
  19. const wizard = this.get('model');
  20. wizard.save().then(() => {
  21. this.set('saving', false);
  22. if (this.get('newWizard')) {
  23. this.send("refreshAllWizards");
  24. } else {
  25. this.send("refreshWizard");
  26. }
  27. }).catch((result) => {
  28. this.set('saving', false);
  29. this.set('error', I18n.t(`admin.wizard.error.${result.error}`));
  30. Ember.run.later(() => this.set('error', null), 10000);
  31. });
  32. },
  33. remove() {
  34. const wizard = this.get('model');
  35. wizard.remove().then(() => {
  36. this.send("refreshAllWizards");
  37. });
  38. },
  39. setNextSessionScheduled() {
  40. let controller = showModal('next-session-scheduled', {
  41. model: {
  42. dateTime: this.get('model.after_time_scheduled'),
  43. update: (dateTime) => this.set('model.after_time_scheduled', dateTime)
  44. }
  45. });
  46. controller.setup();
  47. },
  48. }
  49. });