2020-10-17 03:31:07 +02:00
|
|
|
import Controller from "@ember/controller";
|
2021-02-24 08:43:35 +01:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2020-11-08 04:24:20 +01:00
|
|
|
import CustomWizardCustomField from "../models/custom-wizard-custom-field";
|
2021-02-24 08:43:35 +01:00
|
|
|
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
2020-10-17 03:31:07 +02:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2021-02-24 08:43:35 +01:00
|
|
|
messageKey: "create",
|
|
|
|
fieldKeys: ["klass", "type", "serializers", "name"],
|
2020-11-08 04:24:20 +01:00
|
|
|
documentationUrl: "https://thepavilion.io/t/3572",
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-10-17 03:31:07 +02:00
|
|
|
actions: {
|
|
|
|
addField() {
|
2021-02-24 08:43:35 +01:00
|
|
|
this.get("customFields").pushObject(
|
2020-11-09 11:44:32 +01:00
|
|
|
CustomWizardCustomField.create({ edit: true })
|
2020-10-17 03:31:07 +02:00
|
|
|
);
|
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
saveField(field) {
|
2021-02-24 08:43:35 +01:00
|
|
|
return CustomWizardCustomField.saveField(field).then((result) => {
|
|
|
|
if (result.success) {
|
|
|
|
this.setProperties({
|
|
|
|
messageKey: "saved",
|
|
|
|
messageType: "success",
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (result.messages) {
|
2020-11-10 01:56:11 +01:00
|
|
|
this.setProperties({
|
2021-02-24 08:43:35 +01:00
|
|
|
messageKey: "error",
|
|
|
|
messageType: "error",
|
|
|
|
messageOpts: { messages: result.messages },
|
2020-11-10 01:56:11 +01:00
|
|
|
});
|
2020-11-08 04:24:20 +01:00
|
|
|
}
|
2021-02-24 08:43:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
this.setProperties({
|
|
|
|
messageKey: "create",
|
|
|
|
messageType: null,
|
|
|
|
messageOpts: null,
|
|
|
|
}),
|
|
|
|
10000
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
2020-11-09 11:44:32 +01:00
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-11-09 11:44:32 +01:00
|
|
|
removeField(field) {
|
2021-02-24 08:43:35 +01:00
|
|
|
return CustomWizardCustomField.destroyField(field).then((result) => {
|
|
|
|
this.get("customFields").removeObject(field);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|