2021-01-27 06:08:26 +01:00
|
|
|
import Component from "@ember/component";
|
2021-02-05 13:59:30 +01:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
import { cloneJSON } from "discourse-common/lib/object";
|
|
|
|
import Category from "discourse/models/category";
|
2021-01-27 06:08:26 +01:00
|
|
|
|
2021-01-30 18:46:04 +01:00
|
|
|
export default Component.extend({
|
|
|
|
init(){
|
|
|
|
this._super(...arguments);
|
|
|
|
if (!this.validations) return;
|
|
|
|
|
|
|
|
if (!this.field.validations) {
|
|
|
|
const validations = {};
|
|
|
|
this.validations.forEach((validation) => {
|
|
|
|
validations[validation] = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
this.set('field.validations', EmberObject.create(validations));
|
|
|
|
}
|
2021-02-05 13:59:30 +01:00
|
|
|
|
|
|
|
const validationBuffer = cloneJSON(this.get('field.validations'));
|
|
|
|
let bufferCategories;
|
|
|
|
if( validationBuffer.similar_topics && (bufferCategories = validationBuffer.similar_topics.categories)) {
|
|
|
|
const categories = Category.findByIds(bufferCategories);
|
|
|
|
validationBuffer.similar_topics.categories = categories;
|
|
|
|
}
|
|
|
|
this.set('validationBuffer', validationBuffer);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
updateValidationCategories(name, validation, categories) {
|
|
|
|
this.set(`validationBuffer.${name}.categories`, categories);
|
|
|
|
this.set(`field.validations.${name}.categories`, categories.map(category => category.id));
|
|
|
|
}
|
2021-01-30 18:46:04 +01:00
|
|
|
}
|
|
|
|
});
|