2020-02-03 08:22:14 -05:00
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { readOnly } from "@ember/object/computed";
|
2024-08-23 07:17:07 -04:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2023-10-10 14:38:59 -04:00
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
|
|
|
import MultiSelectComponent from "select-kit/components/multi-select";
|
2024-08-23 07:17:07 -04:00
|
|
|
import {
|
|
|
|
MAIN_COLLECTION,
|
|
|
|
pluginApiIdentifiers,
|
|
|
|
selectKitOptions,
|
|
|
|
} from "select-kit/components/select-kit";
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2024-08-23 07:17:07 -04:00
|
|
|
@classNames("list-setting")
|
|
|
|
@selectKitOptions({
|
|
|
|
filterable: true,
|
|
|
|
selectedChoiceComponent: "selectedChoiceComponent",
|
|
|
|
})
|
|
|
|
@pluginApiIdentifiers("list-setting")
|
|
|
|
export default class ListSetting extends MultiSelectComponent {
|
|
|
|
choices = null;
|
|
|
|
nameProperty = null;
|
|
|
|
valueProperty = null;
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2024-08-23 07:17:07 -04:00
|
|
|
@readOnly("choices") content;
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
modifyComponentForRow(collection) {
|
2022-07-17 14:48:36 -04:00
|
|
|
if (collection === MAIN_COLLECTION && this.settingName?.includes("color")) {
|
2020-02-03 08:22:14 -05:00
|
|
|
return "create-color-row";
|
2017-11-21 05:53:09 -05:00
|
|
|
}
|
2024-08-23 07:17:07 -04:00
|
|
|
}
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2024-08-23 07:17:07 -04:00
|
|
|
@computed("settingName")
|
|
|
|
get selectedChoiceComponent() {
|
2022-07-17 14:48:36 -04:00
|
|
|
if (this.settingName?.includes("color")) {
|
2021-08-23 04:44:19 -04:00
|
|
|
return "selected-choice-color";
|
2017-11-21 05:53:09 -05:00
|
|
|
} else {
|
2021-08-23 04:44:19 -04:00
|
|
|
return "selected-choice";
|
2017-11-21 05:53:09 -05:00
|
|
|
}
|
2024-08-23 07:17:07 -04:00
|
|
|
}
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
deselect(value) {
|
|
|
|
this.onChangeChoices &&
|
|
|
|
this.onChangeChoices([...new Set([value, ...makeArray(this.choices)])]);
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2024-08-23 07:17:07 -04:00
|
|
|
super.deselect(...arguments);
|
|
|
|
}
|
|
|
|
}
|