2020-04-08 04:52:07 +02:00
|
|
|
import { default as discourseComputed, observes } from 'discourse-common/utils/decorators';
|
|
|
|
import { equal, or } from "@ember/object/computed";
|
2020-04-02 10:21:03 +02:00
|
|
|
import { selectKitContent } from '../lib/wizard';
|
2020-04-05 03:37:09 +02:00
|
|
|
import Component from "@ember/component";
|
2017-09-23 04:34:07 +02:00
|
|
|
|
2020-04-05 03:37:09 +02:00
|
|
|
export default Component.extend({
|
2017-09-23 04:34:07 +02:00
|
|
|
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'),
|
2020-04-08 04:52:07 +02:00
|
|
|
isText: equal('field.type', 'text'),
|
|
|
|
isTextarea: equal('field.type', 'textarea'),
|
|
|
|
isUrl: equal('field.type', 'url'),
|
|
|
|
showPrefill: or('isCategory', 'isTag', 'isGroup', 'isDropdown'),
|
|
|
|
showContent: or('isCategory', 'isTag', 'isGroup', 'isDropdown'),
|
|
|
|
showLimit: or('isCategory', 'isTag'),
|
|
|
|
showMinLength: or('isText', 'isTextarea', 'isUrl'),
|
2020-04-02 10:21:03 +02:00
|
|
|
categoryPropertyTypes: selectKitContent(['id', 'slug']),
|
2020-04-08 04:52:07 +02:00
|
|
|
|
|
|
|
@observes('isUpload', 'isCategory')
|
|
|
|
setupDefaults() {
|
2020-04-01 07:03:26 +02:00
|
|
|
if (this.isUpload && !this.field.file_types) {
|
2019-07-19 05:47:17 +02:00
|
|
|
this.set('field.file_types', '.jpg,.png');
|
|
|
|
}
|
2020-04-08 04:52:07 +02:00
|
|
|
|
|
|
|
if (this.isCategory && !this.field.property) {
|
|
|
|
this.set('field.property', 'id');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@observes('field.type')
|
|
|
|
clearMappedProperties() {
|
|
|
|
this.set('field.content', null);
|
|
|
|
this.set('field.prefill', null);
|
2020-03-23 06:41:04 +01:00
|
|
|
},
|
|
|
|
|
2020-04-07 13:06:35 +02:00
|
|
|
setupTypeOutput(fieldType, options) {
|
|
|
|
const selectionType = {
|
|
|
|
category: 'category',
|
|
|
|
tag: 'tag',
|
|
|
|
group: 'group'
|
|
|
|
}[fieldType];
|
|
|
|
|
|
|
|
if (selectionType) {
|
|
|
|
options[`${selectionType}Selection`] = 'output';
|
|
|
|
options.outputDefaultSelection = selectionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
2020-04-01 12:58:30 +02:00
|
|
|
@discourseComputed('field.type')
|
2020-04-05 03:37:09 +02:00
|
|
|
contentOptions(fieldType) {
|
2020-03-23 06:41:04 +01:00
|
|
|
let options = {
|
2020-04-05 03:37:09 +02:00
|
|
|
wizardFieldSelection: true,
|
2020-04-01 07:03:26 +02:00
|
|
|
textSelection: 'key,value',
|
2020-04-06 03:54:16 +02:00
|
|
|
userFieldSelection: 'key,value',
|
|
|
|
context: 'field'
|
2020-03-23 06:41:04 +01:00
|
|
|
}
|
2020-04-05 03:37:09 +02:00
|
|
|
|
2020-04-07 13:06:35 +02:00
|
|
|
options = this.setupTypeOutput(fieldType, options);
|
|
|
|
|
2020-04-05 03:37:09 +02:00
|
|
|
if (this.isDropdown) {
|
2020-04-06 03:54:16 +02:00
|
|
|
options.wizardFieldSelection = 'key,value';
|
2020-04-07 13:06:35 +02:00
|
|
|
options.listSelection += ',assignment';
|
2020-04-06 10:36:38 +02:00
|
|
|
options.inputTypes = 'association,assignment';
|
|
|
|
options.singular = true;
|
2020-04-06 03:54:16 +02:00
|
|
|
options.pairConnector = 'association';
|
2020-04-05 03:37:09 +02:00
|
|
|
options.keyPlaceholder = 'admin.wizard.key';
|
|
|
|
options.valuePlaceholder = 'admin.wizard.value';
|
|
|
|
}
|
2020-04-07 13:06:35 +02:00
|
|
|
|
2020-03-24 10:35:46 +01:00
|
|
|
return options;
|
|
|
|
},
|
|
|
|
|
2020-04-01 12:58:30 +02:00
|
|
|
@discourseComputed('field.type')
|
2020-04-05 03:37:09 +02:00
|
|
|
prefillOptions(fieldType) {
|
2020-03-24 10:35:46 +01:00
|
|
|
let options = {
|
2020-04-05 03:37:09 +02:00
|
|
|
wizardFieldSelection: true,
|
2020-04-07 09:54:30 +02:00
|
|
|
textSelection: true,
|
2020-04-06 03:54:16 +02:00
|
|
|
userFieldSelection: 'key,value',
|
|
|
|
context: 'field'
|
2020-04-05 03:37:09 +02:00
|
|
|
}
|
2020-04-07 13:06:35 +02:00
|
|
|
|
|
|
|
return this.setupTypeOutput(fieldType, 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
|
|
|
});
|