FIX: makes houses ads work with sk2

FIX: makes houses hads work with sk2

diff --git a/assets/javascripts/discourse/components/house-ads-chooser.js.es6 b/assets/javascripts/discourse/components/house-ads-chooser.js.es6
index 6b4d57a..d51ecc3 100644
--- a/assets/javascripts/discourse/components/house-ads-chooser.js.es6
+++ b/assets/javascripts/discourse/components/house-ads-chooser.js.es6
@@ -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));
   },
-
-  // called when first rendered
   computeValues() {
-    return this.get("settingValue")
-      .split(this.get("tokenSeparator"))
-      .filter(c => c);
+    return this.settingValue.split(this.tokenSeparator).filter(Boolean);
+  },
+
+  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);
+    }
   }
 });
diff --git a/assets/javascripts/discourse/templates/components/house-ads-list-setting.hbs b/assets/javascripts/discourse/templates/components/house-ads-list-setting.hbs
index 02bf05d..2457805 100644
--- a/assets/javascripts/discourse/templates/components/house-ads-list-setting.hbs
+++ b/assets/javascripts/discourse/templates/components/house-ads-list-setting.hbs
@@ -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"}}

GitHub sha: af346fc1

1 Like