2017-11-21 18:53:09 +08:00
|
|
|
import ComboBoxComponent from "select-kit/components/combo-box";
|
|
|
|
import DatetimeMixin from "select-kit/components/future-date-input-selector/mixin";
|
2020-02-03 21:22:14 +08:00
|
|
|
import { computed } from "@ember/object";
|
2019-11-09 00:32:20 +08:00
|
|
|
import { equal } from "@ember/object/computed";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2021-08-23 16:44:19 +08:00
|
|
|
import buildTimeframes from "discourse/lib/timeframes-builder";
|
|
|
|
import I18n from "I18n";
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2017-11-29 03:16:13 +08:00
|
|
|
export const FORMAT = "YYYY-MM-DD HH:mmZ";
|
2017-10-20 03:51:08 +08:00
|
|
|
|
|
|
|
export default ComboBoxComponent.extend(DatetimeMixin, {
|
2017-11-21 18:53:09 +08:00
|
|
|
pluginApiIdentifiers: ["future-date-input-selector"],
|
2017-10-20 03:51:08 +08:00
|
|
|
classNames: ["future-date-input-selector"],
|
2019-11-09 00:32:20 +08:00
|
|
|
isCustom: equal("value", "pick_date_and_time"),
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
selectKitOptions: {
|
|
|
|
autoInsertNoneItem: false,
|
|
|
|
headerComponent:
|
|
|
|
"future-date-input-selector/future-date-input-selector-header",
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
modifyComponentForRow() {
|
|
|
|
return "future-date-input-selector/future-date-input-selector-row";
|
2017-11-21 18:53:09 +08:00
|
|
|
},
|
|
|
|
|
2020-03-19 23:36:31 +08:00
|
|
|
content: computed("statusType", function () {
|
2020-02-03 21:22:14 +08:00
|
|
|
const now = moment();
|
|
|
|
const opts = {
|
2017-10-27 01:50:31 +08:00
|
|
|
now,
|
|
|
|
day: now.day(),
|
2019-05-27 16:15:39 +08:00
|
|
|
includeWeekend: this.includeWeekend,
|
|
|
|
includeMidFuture: this.includeMidFuture || true,
|
|
|
|
includeFarFuture: this.includeFarFuture,
|
|
|
|
includeDateTime: this.includeDateTime,
|
2020-06-15 12:06:03 +08:00
|
|
|
canScheduleNow: this.includeNow || false,
|
2017-10-27 01:50:31 +08:00
|
|
|
canScheduleToday: 24 - now.hour() > 6,
|
|
|
|
};
|
|
|
|
|
2021-08-23 16:44:19 +08:00
|
|
|
return buildTimeframes(opts).map((tf) => {
|
2017-10-27 01:50:31 +08:00
|
|
|
return {
|
|
|
|
id: tf.id,
|
2020-02-03 21:22:14 +08:00
|
|
|
name: I18n.t(`topic.auto_update_input.${tf.id}`),
|
|
|
|
datetime: this._computeDatetimeForValue(tf.id),
|
|
|
|
icons: this._computeIconsForValue(tf.id),
|
2017-10-27 01:50:31 +08:00
|
|
|
};
|
2017-10-20 03:51:08 +08:00
|
|
|
});
|
2020-02-03 21:22:14 +08:00
|
|
|
}),
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
actions: {
|
|
|
|
onChange(value) {
|
2021-02-03 08:13:32 +08:00
|
|
|
if (value !== "pick_date_and_time") {
|
2020-02-03 21:22:14 +08:00
|
|
|
const { time } = this._updateAt(value);
|
|
|
|
if (time && !isEmpty(value)) {
|
|
|
|
this.attrs.onChangeInput &&
|
|
|
|
this.attrs.onChangeInput(time.locale("en").format(FORMAT));
|
|
|
|
}
|
2017-11-23 22:18:27 +08:00
|
|
|
}
|
2017-10-20 03:51:08 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
this.attrs.onChange && this.attrs.onChange(value);
|
2017-11-23 22:18:27 +08:00
|
|
|
},
|
2017-10-20 03:51:08 +08:00
|
|
|
},
|
|
|
|
});
|