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 { MAIN_COLLECTION } from "select-kit/components/select-kit";
|
|
|
|
import { computed } from "@ember/object";
|
|
|
|
import { readOnly } from "@ember/object/computed";
|
|
|
|
import { makeArray } from "discourse-common/lib/helpers";
|
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,
|
|
|
|
selectedNameComponent: "selectedNameComponent"
|
|
|
|
},
|
2017-11-21 05:53:09 -05:00
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
modifyComponentForRow(collection) {
|
|
|
|
if (
|
|
|
|
collection === MAIN_COLLECTION &&
|
|
|
|
this.settingName &&
|
|
|
|
this.settingName.indexOf("color") > -1
|
|
|
|
) {
|
|
|
|
return "create-color-row";
|
2017-11-21 05:53:09 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-03 08:22:14 -05:00
|
|
|
selectedNameComponent: computed("settingName", function() {
|
|
|
|
if (this.settingName && this.settingName.indexOf("color") > -1) {
|
|
|
|
return "selected-color";
|
2018-06-15 11:03:24 -04:00
|
|
|
} else {
|
2020-02-03 08:22:14 -05:00
|
|
|
return "selected-name";
|
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
|
|
|
}
|
|
|
|
});
|