discourse/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
Joffrey JAFFEUX cb59681d86
DEV: select-kit third major update with focus on accessibility (#13303)
Major changes included:
- better support for screen readers
- trapping focus in modals
- better tabbing order in composer
- alerts on no content found/number of items found
- better autofocus in modals
- mini-tag-chooser is now a multi-select component
- each multi-select-component will now display selection on one row
2021-08-23 10:44:19 +02:00

63 lines
1.9 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,
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),
};
});
}),
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);
},
},
});