next-session-scheduled.js.es6 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { default as computed } from 'ember-addons/ember-computed-decorators';
  2. export default Ember.Controller.extend({
  3. title: 'admin.wizard.after_time_modal.title',
  4. setup() {
  5. const dateTime = this.get('model.dateTime');
  6. const ROUNDING = 30 * 60 * 1000;
  7. const nextInterval = moment(Math.ceil((+moment()) / ROUNDING) * ROUNDING);
  8. const mDateTime = dateTime ? moment(dateTime) : nextInterval;
  9. const mDateTimeLocal = mDateTime.local();
  10. const date = mDateTimeLocal.format('YYYY-MM-DD');
  11. const time = mDateTimeLocal.format('HH:mm');
  12. this.setProperties({ date, time });
  13. Ember.run.scheduleOnce('afterRender', this, () => {
  14. const $timePicker = $("#time-picker");
  15. $timePicker.timepicker({ timeFormat: 'H:i' });
  16. $timePicker.timepicker('setTime', time);
  17. $timePicker.change(() => this.set('time', $timePicker.val()));
  18. });
  19. },
  20. @computed('date', 'time')
  21. dateTime: function(date, time) {
  22. return moment(date + 'T' + time).format();
  23. },
  24. @computed('dateTime')
  25. submitDisabled(dateTime) {
  26. return moment().isAfter(dateTime);
  27. },
  28. resetProperties() {
  29. this.setProperties({
  30. date: null,
  31. time: null
  32. });
  33. },
  34. actions: {
  35. clear() {
  36. this.resetProperties();
  37. this.get('model.update')(null);
  38. },
  39. submit() {
  40. const dateTime = this.get('dateTime');
  41. const formatted = moment(dateTime).utc().toISOString();
  42. this.get('model.update')(formatted);
  43. this.resetProperties();
  44. this.send("closeModal");
  45. }
  46. }
  47. });