Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-10 12:22:54 +01:00
43 Zeilen
1 KiB
JavaScript
43 Zeilen
1 KiB
JavaScript
import { observes } from "discourse-common/utils/decorators";
|
|
import Category from "discourse/models/category";
|
|
|
|
export default Ember.Component.extend({
|
|
layoutName: 'wizard/templates/components/wizard-field-category',
|
|
|
|
didInsertElement() {
|
|
const property = this.field.property || "id";
|
|
const value = this.field.value;
|
|
|
|
if (value) {
|
|
this.set(
|
|
"categories",
|
|
[...value].reduce((result, v) => {
|
|
let val =
|
|
property === "id" ? Category.findById(v) : Category.findBySlug(v);
|
|
if (val) {
|
|
result.push(val);
|
|
}
|
|
return result;
|
|
}, [])
|
|
);
|
|
}
|
|
},
|
|
|
|
@observes("categories")
|
|
setValue() {
|
|
const categories = (this.categories || []).filter((c) => !!c);
|
|
const property = this.field.property || "id";
|
|
|
|
if (categories.length) {
|
|
this.set(
|
|
"field.value",
|
|
categories.reduce((result, c) => {
|
|
if (c && c[property]) {
|
|
result.push(c[property]);
|
|
}
|
|
return result;
|
|
}, [])
|
|
);
|
|
}
|
|
},
|
|
});
|