0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-24 10:20:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-custom-fields.js
2024-11-22 16:45:50 +01:00

58 Zeilen
1,5 KiB
JavaScript

import Controller from "@ember/controller";
import CustomWizardCustomField from "../models/custom-wizard-custom-field";
export default Controller.extend({
messageKey: "create",
fieldKeys: ["klass", "type", "name", "serializers"],
documentationUrl:
"https://pavilion.tech/products/discourse-custom-wizard-plugin/documentation/custom-fields",
actions: {
addField() {
this.get("customFields").unshiftObject(
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(
() => {
if (this.isDestroyed) {
return;
}
this.setProperties({
messageKey: "create",
messageType: null,
messageOpts: null,
});
},
10000
);
return result;
});
},
removeField(field) {
return CustomWizardCustomField.destroyField(field).then(() => {
this.get("customFields").removeObject(field);
});
},
},
});