2020-02-03 08:22:14 -05:00
|
|
|
import { MAIN_COLLECTION } from "select-kit/components/select-kit";
|
2017-11-21 05:53:09 -05:00
|
|
|
import MultiSelectComponent from "select-kit/components/multi-select";
|
2020-02-03 08:22:14 -05:00
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
|
|
|
import { readOnly } from "@ember/object/computed";
|
2017-11-21 05:53:09 -05:00
|
|
|
|
|
|
|
export default MultiSelectComponent.extend({
|
|
|
|
pluginApiIdentifiers: ["list-setting"],
|
2020-02-03 08:22:14 -05:00
|
|
|
classNames: ["list-setting"],
|
2017-11-21 05:53:09 -05:00
|
|
|
choices: null,
|
2020-02-03 08:22:14 -05:00
|
|
|
nameProperty: null,
|
|
|
|
valueProperty: null,
|
|
|
|
content: readOnly("choices"),
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
selectKitOptions: {
|
|
|
|
filterable: true,
|
2021-08-23 04:44:19 -04:00
|
|
|
selectedChoiceComponent: "selectedChoiceComponent",
|
2020-02-03 08:22:14 -05:00
|
|
|
},
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-08-23 04:44:19 -04:00
|
|
|
selectedChoiceComponent: computed("settingName", function () {
|
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
|
|
|
}
|
2020-02-03 08:22:14 -05: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
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
this._super(...arguments);
|
2017-11-21 05:53:09 -05:00
|
|
|
},
|
|
|
|
});
|