discourse/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.9 KiB
JavaScript
Raw Normal View History

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";
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, {
pluginApiIdentifiers: ["future-date-input-selector"],
2017-10-20 03:51:08 +08:00
classNames: ["future-date-input-selector"],
isCustom: equal("value", "pick_date_and_time"),
2017-10-20 03:51:08 +08:00
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,
includeMidFuture: this.includeMidFuture || true,
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),
};
2017-10-20 03:51:08 +08:00
});
}),
2017-10-20 03:51:08 +08:00
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));
}
}
2017-10-20 03:51:08 +08:00
this.attrs.onChange && this.attrs.onChange(value);
},
2017-10-20 03:51:08 +08:00
},
});