discourse-adplugin/assets/javascripts/discourse/components/house-ads-chooser.js.es6

42 lines
1.1 KiB
Plaintext
Raw Normal View History

import MultiSelectComponent from "select-kit/components/multi-select";
const { makeArray } = Ember;
2020-02-07 04:34:58 -05:00
import { computed } from "@ember/object";
export default MultiSelectComponent.extend({
2020-02-07 04:34:58 -05:00
classNames: ["house-ads-chooser"],
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,
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);
}),
2020-02-07 04:34:58 -05:00
// TODO: kept for legacy, remove when Discourse is 2.5
mutateValues(values) {
2020-02-07 04:34:58 -05:00
this.set("settingValue", values.join(this.tokenSeparator));
},
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
},
},
});