mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 07:08:44 +08:00
39f3dbd945
* renames `select-box-kit` into `select-kit` * introduces `single-select` and `multi-select` as base components * introduces {{search-advanced-category-chooser}} as a better component for selecting category in advanced search * improves events handling in select-kit * recreates color selection inputs using {{multi-select}} and a custom {{selected-color}} component * replaces category-selector by a component using select-kit and based on multi-select * improves positioning of wrapper * removes the need for offscreen, and instead use `select-kit-header` as a base focus point for all select-kit based components * introduces a formal plugin api for select-kit based components * introduces a formal pattern for loading and updating select-kit based components: ``` computeValue() computeContent() mutateValue() ```
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import MultiSelectComponent from "select-kit/components/multi-select";
|
|
const { makeArray } = Ember;
|
|
|
|
export default MultiSelectComponent.extend({
|
|
pluginApiIdentifiers: ["admin-group-selector"],
|
|
classNames: "admin-group-selector",
|
|
selected: null,
|
|
available: null,
|
|
allowAny: false,
|
|
|
|
computeValues() {
|
|
return makeArray(this.get("selected"))
|
|
.map(s => this.valueForContentItem(s));
|
|
},
|
|
|
|
computeContent() {
|
|
return makeArray(this.get("available"));
|
|
},
|
|
|
|
computeContentItem(contentItem, name) {
|
|
let computedContent = this.baseComputedContentItem(contentItem, name);
|
|
computedContent.locked = contentItem.automatic;
|
|
return computedContent;
|
|
},
|
|
|
|
mutateValues(values) {
|
|
if (values.length > this.get("selected").length) {
|
|
const newValues = values
|
|
.filter(v => !this.get("selected")
|
|
.map(s => this.valueForContentItem(s))
|
|
.includes(v));
|
|
|
|
newValues.forEach(value => {
|
|
const actionContext = this.get("available")
|
|
.findBy(this.get("valueAttribute"), parseInt(value, 10));
|
|
|
|
this.triggerAction({ action: "groupAdded", actionContext });
|
|
});
|
|
} else if (values.length < this.get("selected").length) {
|
|
const selected = this.get("selected")
|
|
.filter(s => !values.includes(this.valueForContentItem(s)));
|
|
|
|
selected.forEach(s => {
|
|
this.triggerAction({
|
|
action: "groupRemoved",
|
|
actionContext: this.valueForContentItem(s)
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|