2019-04-18 17:52:59 -04:00
|
|
|
import MultiSelectComponent from "select-kit/components/multi-select";
|
2023-01-04 07:34:08 -05:00
|
|
|
import Ember from "ember";
|
2019-04-18 17:52:59 -04:00
|
|
|
const { makeArray } = Ember;
|
2020-02-07 04:34:58 -05:00
|
|
|
import { computed } from "@ember/object";
|
2019-04-18 17:52:59 -04:00
|
|
|
|
|
|
|
export default MultiSelectComponent.extend({
|
2020-02-07 04:34:58 -05:00
|
|
|
classNames: ["house-ads-chooser"],
|
2019-04-18 17:52:59 -04:00
|
|
|
filterable: true,
|
|
|
|
filterPlaceholder: "admin.adplugin.house_ads.filter_placeholder",
|
|
|
|
tokenSeparator: "|",
|
|
|
|
allowCreate: false,
|
|
|
|
allowAny: false,
|
|
|
|
settingValue: "",
|
2020-02-07 04:34:58 -05:00
|
|
|
valueAttribute: null,
|
|
|
|
nameProperty: null,
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-09-04 07:24:14 -04:00
|
|
|
value: computed("settingValue", function () {
|
2020-02-07 04:34:58 -05:00
|
|
|
return this.settingValue
|
|
|
|
.toString()
|
|
|
|
.split(this.tokenSeparator)
|
|
|
|
.filter(Boolean);
|
|
|
|
}),
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-02-07 04:34:58 -05:00
|
|
|
// TODO: kept for legacy, remove when Discourse is 2.5
|
2019-04-18 17:52:59 -04:00
|
|
|
mutateValues(values) {
|
2020-02-07 04:34:58 -05:00
|
|
|
this.set("settingValue", values.join(this.tokenSeparator));
|
2019-04-18 17:52:59 -04:00
|
|
|
},
|
|
|
|
computeValues() {
|
2020-02-07 04:34:58 -05:00
|
|
|
return this.settingValue.split(this.tokenSeparator).filter(Boolean);
|
|
|
|
},
|
|
|
|
|
2020-09-04 07:24:14 -04:00
|
|
|
content: computed("choices", function () {
|
2020-02-07 04:34:58 -05:00
|
|
|
return makeArray(this.choices);
|
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onChange(value) {
|
|
|
|
const settingValue = makeArray(value).join(this.tokenSeparator);
|
|
|
|
this.attrs.onChange && this.attrs.onChange(settingValue);
|
2020-09-04 07:24:14 -04:00
|
|
|
},
|
|
|
|
},
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|