FIX: makes houses hads work with sk2

This commit is contained in:
jjaffeux 2020-02-07 10:34:58 +01:00
parent 63ae1672ad
commit af346fc1c2
2 changed files with 29 additions and 12 deletions

View File

@ -1,28 +1,41 @@
import MultiSelectComponent from "select-kit/components/multi-select";
const { makeArray } = Ember;
import { computed } from "@ember/object";
export default MultiSelectComponent.extend({
classNames: "house-ads-chooser",
classNames: ["house-ads-chooser"],
filterable: true,
filterPlaceholder: "admin.adplugin.house_ads.filter_placeholder",
tokenSeparator: "|",
allowCreate: false,
allowAny: false,
settingValue: "",
valueAttribute: null,
nameProperty: null,
computeContent() {
return makeArray(this.get("choices"));
},
value: computed("settingValue", function() {
return this.settingValue
.toString()
.split(this.tokenSeparator)
.filter(Boolean);
}),
// called after a selection is made
// TODO: kept for legacy, remove when Discourse is 2.5
mutateValues(values) {
this.set("settingValue", values.join(this.get("tokenSeparator")));
this.set("settingValue", values.join(this.tokenSeparator));
},
computeValues() {
return this.settingValue.split(this.tokenSeparator).filter(Boolean);
},
// called when first rendered
computeValues() {
return this.get("settingValue")
.split(this.get("tokenSeparator"))
.filter(c => c);
content: computed("choices", function() {
return makeArray(this.choices);
}),
actions: {
onChange(value) {
const settingValue = makeArray(value).join(this.tokenSeparator);
this.attrs.onChange && this.attrs.onChange(settingValue);
}
}
});

View File

@ -1,5 +1,9 @@
<label for="{{name}}">{{title}}</label>
{{house-ads-chooser settingValue=adValue choices=adNames}}
{{house-ads-chooser
settingValue=adValue
choices=adNames
onChange=(action (mut adValue))
}}
<div class='setting-controls'>
{{#if changed}}
{{d-button class="ok" action=(action "save") icon="check"}}