0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 12:22:54 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-custom-field.js.es6

79 Zeilen
2,2 KiB
Text

2020-03-21 18:30:11 +01:00
import { default as computed, observes, on } from 'discourse-common/utils/decorators';
2020-03-24 10:35:46 +01:00
import { equal, not, or } from "@ember/object/computed";
2020-02-02 11:42:05 +01:00
import { generateSelectKitContent } from '../lib/custom-wizard';
2017-09-23 04:34:07 +02:00
export default Ember.Component.extend({
classNames: 'wizard-custom-field',
2020-03-23 06:41:04 +01:00
isDropdown: equal('field.type', 'dropdown'),
isUpload: equal('field.type', 'upload'),
isCategory: equal('field.type', 'category'),
isGroup: equal('field.type', 'group'),
isTag: equal('field.type', 'tag'),
disableId: not('field.isNew'),
2020-03-19 08:58:45 +01:00
choicesTypes: generateSelectKitContent(['translation', 'custom']),
2020-03-23 06:41:04 +01:00
choicesTranslation: equal('field.choices_type', 'translation'),
choicesCustom: equal('field.choices_type', 'custom'),
2020-02-02 11:42:05 +01:00
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
2017-09-23 04:34:07 +02:00
2017-10-13 15:02:34 +02:00
@computed('field.type')
2020-03-23 19:40:11 +01:00
isInput: (type) => type === 'text' || type === 'textarea' || type === 'url',
2017-10-13 15:02:34 +02:00
@computed('field.type')
isCategoryOrTag: (type) => type === 'tag' || type === 'category',
2019-07-19 05:47:17 +02:00
@on('didInsertElement')
@observes('isUpload')
setupFileType() {
if (this.get('isUpload') && !this.get('field.file_types')) {
this.set('field.file_types', '.jpg,.png');
}
2020-03-23 06:41:04 +01:00
},
@computed('isCategory', 'isGroup', 'isTag')
prefillOptions(isCategory, isGroup, isTag) {
let options = {
hasOutput: true,
enableConnectors: true,
2020-03-24 10:35:46 +01:00
wizardFieldSelection: true,
userFieldSelection: true
2020-03-23 06:41:04 +01:00
}
2020-03-24 10:35:46 +01:00
if (isCategory || isGroup || isTag) {
options.userFieldSelection = 'key,value';
options[`${this.field.type}Selection`] = 'output';
2020-03-23 06:41:04 +01:00
}
2020-03-24 10:35:46 +01:00
return options;
},
2020-03-30 08:16:03 +02:00
contentEnabled: or('isCategory', 'isTag', 'isGroup'),
2020-03-24 10:35:46 +01:00
@computed('field.type')
2020-03-30 08:16:03 +02:00
contentOptions(fieldType) {
if (!this.contentEnabled) return {};
2020-03-23 06:41:04 +01:00
2020-03-24 10:35:46 +01:00
let options = {
hasOutput: true,
enableConnectors: true,
wizardFieldSelection: 'key,value',
userFieldSelection: 'key,value',
textDisabled: 'output'
2020-03-23 06:41:04 +01:00
}
2020-03-24 10:35:46 +01:00
options[`${this.field.type}Selection`] = 'output';
options[`${this.field.type}AllowMultiple`] = true;
2020-03-23 06:41:04 +01:00
return options;
2020-03-24 10:35:46 +01:00
},
2020-03-30 01:53:28 +02:00
actions: {
imageUploadDone(upload) {
this.set("field.image", upload.url);
},
imageUploadDeleted() {
this.set("field.image", null);
}
}
2017-09-23 04:34:07 +02:00
});