Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-30 04:30:29 +01:00
c45e51fcb6
* Code formatting * Both "type" and "name" are used to refer to the validation type. Changed all to "type". * Added proper abstraction of realtime validation classes on server * UI improvements in admin and wizard
44 Zeilen
1,3 KiB
JavaScript
44 Zeilen
1,3 KiB
JavaScript
import Component from "@ember/component";
|
|
import EmberObject from "@ember/object";
|
|
import { cloneJSON } from "discourse-common/lib/object";
|
|
import Category from "discourse/models/category";
|
|
|
|
export default Component.extend({
|
|
classNames: ["realtime-validations"],
|
|
|
|
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));
|
|
}
|
|
|
|
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(type, validation, categories) {
|
|
this.set(`validationBuffer.${type}.categories`, categories);
|
|
this.set(
|
|
`field.validations.${type}.categories`,
|
|
categories.map((category) => category.id)
|
|
);
|
|
},
|
|
},
|
|
});
|