0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-30 04:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6

59 Zeilen
1,6 KiB
Text

2020-04-06 03:54:16 +02:00
import { default as discourseComputed } from 'discourse-common/utils/decorators';
2020-03-30 01:53:28 +02:00
import { scheduleOnce } from "@ember/runloop";
2020-04-05 03:37:09 +02:00
import Controller from "@ember/controller";
2017-11-01 05:21:14 +01:00
2020-04-05 03:37:09 +02:00
export default Controller.extend({
2017-11-01 05:21:14 +01:00
title: 'admin.wizard.after_time_modal.title',
setup() {
const dateTime = this.get('model.dateTime');
const ROUNDING = 30 * 60 * 1000;
const nextInterval = moment(Math.ceil((+moment()) / ROUNDING) * ROUNDING);
const mDateTime = dateTime ? moment(dateTime) : nextInterval;
const mDateTimeLocal = mDateTime.local();
const date = mDateTimeLocal.format('YYYY-MM-DD');
const time = mDateTimeLocal.format('HH:mm');
this.setProperties({ date, time });
2020-03-30 01:53:28 +02:00
scheduleOnce('afterRender', this, () => {
2017-11-01 05:21:14 +01:00
const $timePicker = $("#time-picker");
$timePicker.timepicker({ timeFormat: 'H:i' });
$timePicker.timepicker('setTime', time);
$timePicker.change(() => this.set('time', $timePicker.val()));
});
},
2020-04-06 03:54:16 +02:00
@discourseComputed('date', 'time')
2017-11-01 05:21:14 +01:00
dateTime: function(date, time) {
return moment(date + 'T' + time).format();
},
2020-04-06 03:54:16 +02:00
@discourseComputed('dateTime')
2017-11-01 05:21:14 +01:00
submitDisabled(dateTime) {
return moment().isAfter(dateTime);
},
resetProperties() {
this.setProperties({
date: null,
time: null
});
},
actions: {
clear() {
this.resetProperties();
this.get('model.update')(null);
},
submit() {
const dateTime = this.get('dateTime');
const formatted = moment(dateTime).utc().toISOString();
this.get('model.update')(formatted);
this.resetProperties();
this.send("closeModal");
}
}
});