1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/custom-field-input.js.es6

49 Zeilen
1,3 KiB
Text

2020-10-20 07:40:23 +02:00
import Component from "@ember/component";
import discourseComputed, { discourseObserve } from "discourse-common/utils/decorators";
import { or } from "@ember/object/computed";
const generateContent = function(array, type) {
return array.map(key => ({
id: key,
name: I18n.t(`admin.wizard.custom_field.${type}.${key}`)
}));
}
export default Component.extend({
tagName: 'tr',
topicSerializers: ['topic_view', 'topic_list_item'],
postSerializers: ['post'],
2020-11-09 11:44:32 +01:00
groupSerializers: ['basic_group'],
categorySerializers: ['basic_category'],
2020-10-20 07:40:23 +02:00
klassContent: generateContent(['topic', 'post', 'group', 'category'], 'klass'),
typeContent: generateContent(['string', 'boolean', 'integer', 'json'], 'type'),
2020-10-20 07:40:23 +02:00
showInputs: or('field.new', 'field.edit'),
@discourseComputed('field.klass')
serializerContent(klass) {
const serializers = this.get(`${klass}Serializers`);
if (serializers) {
return generateContent(serializers, 'serializers');
} else {
return [];
}
},
actions: {
edit() {
this.set('field.edit', true);
},
close() {
if (this.field.edit) {
this.set('field.edit', false);
}
2020-11-09 11:44:32 +01:00
},
destroy() {
this.set('removing', true);
this.removeField(this.field);
2020-10-20 07:40:23 +02:00
}
}
});