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