0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00
discourse-custom-wizard/assets/javascripts/wizard/components/wizard-field-category.js.es6

29 Zeilen
885 B
Text

2020-03-21 18:30:11 +01:00
import { observes } from 'discourse-common/utils/decorators';
2019-07-27 08:10:26 +02:00
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 value = this.get('field.value');
if (value) {
const property = this.get('field.property') || 'id';
const categories = [...value].map(v => {
return property === 'id' ?
Category.findById(v) :
Category.findBySlug(v);
});
this.set('categories', categories);
}
},
2019-07-26 10:59:41 +02:00
@observes('categories')
setValue() {
const categories = this.get('categories');
if (categories.length) {
const property = this.get('field.property') || 'id';
2019-07-27 08:10:26 +02:00
let value = categories.length === 1 ?
categories[0][property] :
categories.map(c => c[property]);
this.set('field.value', value);
}
2019-07-26 10:59:41 +02:00
}
});