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