0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-25 10:40:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-custom-fields.js.es6

55 Zeilen
1,6 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';
import CustomWizardCustomField from "../models/custom-wizard-custom-field";
2020-11-10 01:56:11 +01:00
import { default as discourseComputed } from 'discourse-common/utils/decorators';
2020-10-17 03:31:07 +02:00
export default Controller.extend({
2020-11-10 01:56:11 +01:00
messageKey: 'create',
2020-10-20 07:40:23 +02:00
fieldKeys: ['klass', 'type', 'serializers', 'name'],
documentationUrl: "https://thepavilion.io/t/3572",
2020-10-17 03:31:07 +02:00
actions: {
addField() {
this.get('customFields').pushObject(
2020-11-09 11:44:32 +01:00
CustomWizardCustomField.create({ edit: true })
2020-10-17 03:31:07 +02:00
);
},
2020-11-10 01:56:11 +01:00
saveField(field) {
return CustomWizardCustomField.saveField(field)
.then(result => {
if (result.success) {
2020-11-10 01:56:11 +01:00
this.setProperties({
messageKey: 'saved',
messageType: 'success'
});
} else {
if (result.messages) {
this.setProperties({
messageKey: 'error',
messageType: 'error',
messageOpts: { messages: result.messages }
})
}
}
2020-11-10 01:56:11 +01:00
setTimeout(() => this.setProperties({
messageKey: 'create',
messageType: null,
messageOpts: null
}), 10000);
return result;
});
2020-11-09 11:44:32 +01:00
},
removeField(field) {
2020-11-10 01:56:11 +01:00
return CustomWizardCustomField.destroyField(field)
2020-11-09 11:44:32 +01:00
.then(result => {
this.get('customFields').removeObject(field);
});
2020-10-17 03:31:07 +02:00
}
}
});