Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-14 05:52:52 +01:00
af3e61fe75
* Add custom field improvements This PR does a few things to improve our support of custom fields 1. Adds custom fields added by other plugins to the list in admin/wizards/custom-fields and the custom field list in the mapper selector 2. Adds support for json custom fields in the wizard actions * Make eslint happy * Make prettier happy * Make rubocop happy * Make ember template lint happy * Don't assume we have the context in the selector * Ensure custom fields don't require optional attributes (with tests)
53 Zeilen
1,3 KiB
JavaScript
53 Zeilen
1,3 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://thepavilion.io/t/3572",
|
|
|
|
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(
|
|
() =>
|
|
this.setProperties({
|
|
messageKey: "create",
|
|
messageType: null,
|
|
messageOpts: null,
|
|
}),
|
|
10000
|
|
);
|
|
|
|
return result;
|
|
});
|
|
},
|
|
|
|
removeField(field) {
|
|
return CustomWizardCustomField.destroyField(field).then(() => {
|
|
this.get("customFields").removeObject(field);
|
|
});
|
|
},
|
|
},
|
|
});
|