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

78 Zeilen
2,2 KiB
Text

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