mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 12:53:45 +08:00
48193767bf
Automatically generated by `eslint --fix` to satisfy the updated configuration
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { computed } from "@ember/object";
|
|
import FormTemplate from "discourse/models/form-template";
|
|
import MultiSelectComponent from "select-kit/components/multi-select";
|
|
|
|
export default MultiSelectComponent.extend({
|
|
pluginApiIdentifiers: ["form-template-chooser"],
|
|
classNames: ["form-template-chooser"],
|
|
selectKitOptions: {
|
|
none: "form_template_chooser.select_template",
|
|
},
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
if (!this.templates) {
|
|
this._fetchTemplates();
|
|
}
|
|
},
|
|
|
|
didUpdateAttrs() {
|
|
this._super(...arguments);
|
|
this._fetchTemplates();
|
|
},
|
|
|
|
@computed("templates")
|
|
get content() {
|
|
if (!this.templates) {
|
|
return this._fetchTemplates();
|
|
}
|
|
|
|
return this.templates;
|
|
},
|
|
|
|
_fetchTemplates() {
|
|
FormTemplate.findAll().then((result) => {
|
|
let sortedTemplates = this._sortTemplatesByName(result);
|
|
|
|
if (this.filteredIds) {
|
|
sortedTemplates = sortedTemplates.filter((t) =>
|
|
this.filteredIds.includes(t.id)
|
|
);
|
|
}
|
|
|
|
if (sortedTemplates.length > 0) {
|
|
return this.set("templates", sortedTemplates);
|
|
} else {
|
|
this.set("templates", sortedTemplates);
|
|
this.set("selectKit.options.disabled", true);
|
|
}
|
|
});
|
|
},
|
|
|
|
_sortTemplatesByName(templates) {
|
|
return templates.sort((a, b) => a.name.localeCompare(b.name));
|
|
},
|
|
});
|