1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/controllers/admin-wizards-custom-fields.js.es6
Angus McLeod cf50a7deb3
Apply prettier 💄 (#80)
* Apply prettier

* applied prettier for similar-topics-validator

Co-authored-by: Faizaan Gagan <fzngagan@gmail.com>
2021-03-28 14:36:49 +05:30

57 Zeilen
1,5 KiB
JavaScript

import Controller from "@ember/controller";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import CustomWizardCustomField from "../models/custom-wizard-custom-field";
import { default as discourseComputed } from "discourse-common/utils/decorators";
export default Controller.extend({
messageKey: "create",
fieldKeys: ["klass", "type", "serializers", "name"],
documentationUrl: "https://thepavilion.io/t/3572",
actions: {
addField() {
this.get("customFields").pushObject(
CustomWizardCustomField.create({ edit: true })
);
},
saveField(field) {
return CustomWizardCustomField.saveField(field).then((result) => {
if (result.success) {
this.setProperties({
messageKey: "saved",
messageType: "success",
});
} else {
if (result.messages) {
this.setProperties({
messageKey: "error",
messageType: "error",
messageOpts: { messages: result.messages },
});
}
}
setTimeout(
() =>
this.setProperties({
messageKey: "create",
messageType: null,
messageOpts: null,
}),
10000
);
return result;
});
},
removeField(field) {
return CustomWizardCustomField.destroyField(field).then((result) => {
this.get("customFields").removeObject(field);
});
},
},
});