0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-09-20 15:51:11 +02:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-custom-fields.js.es6

42 Zeilen
1,1 KiB
Text

2020-10-17 03:31:07 +02:00
import Controller from "@ember/controller";
import EmberObject from '@ember/object';
import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Controller.extend({
2020-10-20 07:40:23 +02:00
fieldKeys: ['klass', 'type', 'serializers', 'name'],
2020-10-17 03:31:07 +02:00
actions: {
addField() {
this.get('customFields').pushObject(
EmberObject.create({
new: true
})
);
},
2020-10-20 07:40:23 +02:00
removeField(field) {
this.get('customFields').removeObject(field);
},
saveFields() {
this.set('saving', true);
2020-10-17 03:31:07 +02:00
ajax(`/admin/wizards/custom-fields`, {
type: 'PUT',
2020-10-20 07:40:23 +02:00
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
2020-10-17 03:31:07 +02:00
custom_fields: this.customFields
2020-10-20 07:40:23 +02:00
})
}).then(result => {
if (result.success) {
this.set('saveIcon', 'check');
} else {
this.set('saveIcon', 'times');
2020-10-17 03:31:07 +02:00
}
2020-10-20 07:40:23 +02:00
setTimeout(() => this.set('saveIcon', ''), 5000);
}).finally(() => this.set('saving', false))
.catch(popupAjaxError);
2020-10-17 03:31:07 +02:00
}
}
});