2021-03-28 11:06:49 +02:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2020-11-08 04:24:20 +01:00
|
|
|
import EmberObject from "@ember/object";
|
|
|
|
import { isEmpty } from "@ember/utils";
|
|
|
|
|
|
|
|
const CustomWizardCustomField = EmberObject.extend({
|
2021-03-28 11:06:49 +02:00
|
|
|
isNew: isEmpty("id"),
|
2020-11-08 04:24:20 +01:00
|
|
|
});
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
const basePath = "/admin/wizards/custom-fields";
|
2020-11-08 04:24:20 +01:00
|
|
|
|
|
|
|
CustomWizardCustomField.reopenClass({
|
|
|
|
listFields() {
|
|
|
|
return ajax(basePath).catch(popupAjaxError);
|
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
saveField(customField) {
|
2020-11-08 04:24:20 +01:00
|
|
|
return ajax(basePath, {
|
2021-03-28 11:06:49 +02:00
|
|
|
type: "PUT",
|
2020-11-10 01:56:11 +01:00
|
|
|
data: {
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_field: customField,
|
|
|
|
},
|
2020-11-08 04:24:20 +01:00
|
|
|
}).catch(popupAjaxError);
|
2020-11-09 11:44:32 +01:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-11-10 01:56:11 +01:00
|
|
|
destroyField(field) {
|
2020-11-09 11:44:32 +01:00
|
|
|
return ajax(`${basePath}/${field.name}`, {
|
2021-03-28 11:06:49 +02:00
|
|
|
type: "DELETE",
|
2020-11-09 11:44:32 +01:00
|
|
|
}).catch(popupAjaxError);
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2020-11-08 04:24:20 +01:00
|
|
|
});
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default CustomWizardCustomField;
|