discourse/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
Andrei Prigorshnev 62029ec4eb
DEV: remove the includeMidFuture option on future-date-input (#15818)
This option was always on. Essentially, we set it only in two places and always use `|| true` with it.

Note that we're going to switch future-date-input-selector to another source of time shortcuts(https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/time-shortcut.js) and also change its API to make it more customizable. Removing the includeMidFuture option is a part of that change.
2022-02-04 21:33:11 +04:00

62 lines
1.8 KiB
JavaScript

import ComboBoxComponent from "select-kit/components/combo-box";
import DatetimeMixin from "select-kit/components/future-date-input-selector/mixin";
import { computed } from "@ember/object";
import { equal } from "@ember/object/computed";
import { isEmpty } from "@ember/utils";
import buildTimeframes from "discourse/lib/timeframes-builder";
import I18n from "I18n";
export const FORMAT = "YYYY-MM-DD HH:mmZ";
export default ComboBoxComponent.extend(DatetimeMixin, {
pluginApiIdentifiers: ["future-date-input-selector"],
classNames: ["future-date-input-selector"],
isCustom: equal("value", "pick_date_and_time"),
selectKitOptions: {
autoInsertNoneItem: false,
headerComponent:
"future-date-input-selector/future-date-input-selector-header",
},
modifyComponentForRow() {
return "future-date-input-selector/future-date-input-selector-row";
},
content: computed("statusType", function () {
const now = moment();
const opts = {
now,
day: now.day(),
includeWeekend: this.includeWeekend,
includeFarFuture: this.includeFarFuture,
includeDateTime: this.includeDateTime,
canScheduleNow: this.includeNow || false,
canScheduleToday: 24 - now.hour() > 6,
};
return buildTimeframes(opts).map((tf) => {
return {
id: tf.id,
name: I18n.t(`topic.auto_update_input.${tf.id}`),
datetime: this._computeDatetimeForValue(tf.id),
icons: this._computeIconsForValue(tf.id),
};
});
}),
actions: {
onChange(value) {
if (value !== "pick_date_and_time") {
const { time } = this._updateAt(value);
if (time && !isEmpty(value)) {
this.attrs.onChangeInput &&
this.attrs.onChangeInput(time.locale("en").format(FORMAT));
}
}
this.attrs.onChange && this.attrs.onChange(value);
},
},
});