0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-15 22:32:54 +01:00
discourse-custom-wizard/assets/javascripts/wizard/components/wizard-field-category.js.es6

40 Zeilen
976 B
Text

import { observes } from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
2019-07-26 10:59:41 +02:00
export default Ember.Component.extend({
2019-07-27 08:10:26 +02:00
didInsertElement() {
const property = this.field.property || "id";
2020-04-15 05:21:40 +02:00
const value = this.field.value;
2019-07-27 08:10:26 +02:00
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;
}, [])
);
2019-07-27 08:10:26 +02:00
}
},
@observes("categories")
2019-07-26 10:59:41 +02:00
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;
}, [])
);
}
},
});