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

160 Zeilen
4,3 KiB
Text

import { default as discourseComputed } from "discourse-common/utils/decorators";
2021-09-07 14:15:04 +02:00
import { equal, or } from "@ember/object/computed";
2020-04-20 11:41:13 +02:00
import { computed } from "@ember/object";
import { selectKitContent } from "../lib/wizard";
import UndoChanges from "../mixins/undo-changes";
2020-04-05 03:37:09 +02:00
import Component from "@ember/component";
import wizardSchema from "../lib/wizard-schema";
2017-09-23 04:34:07 +02:00
2020-04-20 11:41:13 +02:00
export default Component.extend(UndoChanges, {
componentType: "field",
classNameBindings: [":wizard-custom-field", "visible"],
visible: computed("currentFieldId", function () {
return this.field.id === this.currentFieldId;
}),
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"),
isText: equal("field.type", "text"),
isTextarea: equal("field.type", "textarea"),
isUrl: equal("field.type", "url"),
isComposer: equal("field.type", "composer"),
showPrefill: or("isText", "isCategory", "isTag", "isGroup", "isDropdown"),
showContent: or("isCategory", "isTag", "isGroup", "isDropdown"),
showLimit: or("isCategory", "isTag"),
isTextType: or("isText", "isTextarea", "isComposer"),
isComposerPreview: equal("field.type", "composer_preview"),
categoryPropertyTypes: selectKitContent(["id", "slug"]),
2022-09-20 11:16:43 +02:00
messageUrl: "https://discourse.pluginmanager.org/t/field-settings",
@discourseComputed("field.type")
2021-01-27 06:08:26 +01:00
validations(type) {
const applicableToField = [];
for (let validation in wizardSchema.field.validations) {
if (wizardSchema.field.validations[validation]["types"].includes(type)) {
applicableToField.push(validation);
2021-01-27 06:08:26 +01:00
}
}
return applicableToField;
},
@discourseComputed("field.type")
2020-07-16 05:26:56 +02:00
isDateTime(type) {
return ["date_time", "date", "time"].indexOf(type) > -1;
2020-07-16 05:26:56 +02:00
},
@discourseComputed("field.type")
2020-04-20 13:40:32 +02:00
messageKey(type) {
let key = "type";
2020-04-20 13:40:32 +02:00
if (type) {
key = "edit";
2020-04-20 13:40:32 +02:00
}
return key;
},
setupTypeOutput(fieldType, options) {
2020-04-07 13:06:35 +02:00
const selectionType = {
category: "category",
tag: "tag",
group: "group",
2020-04-07 13:06:35 +02:00
}[fieldType];
2020-04-07 13:06:35 +02:00
if (selectionType) {
options[`${selectionType}Selection`] = "output";
2020-04-07 13:06:35 +02:00
options.outputDefaultSelection = selectionType;
}
return options;
},
@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,
textSelection: "key,value",
userFieldSelection: "key,value",
context: "field",
};
2020-04-07 13:06:35 +02:00
options = this.setupTypeOutput(fieldType, options);
2020-04-05 03:37:09 +02:00
if (this.isDropdown) {
options.wizardFieldSelection = "key,value";
options.userFieldOptionsSelection = "output";
options.textSelection = "key,value";
options.inputTypes = "association,conditional,assignment";
options.pairConnector = "association";
options.keyPlaceholder = "admin.wizard.key";
options.valuePlaceholder = "admin.wizard.value";
2020-04-05 03:37:09 +02:00
}
2020-03-24 10:35:46 +01:00
return options;
},
@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,
userFieldSelection: "key,value",
context: "field",
};
2020-04-07 13:06:35 +02:00
return this.setupTypeOutput(fieldType, options);
2020-03-24 10:35:46 +01:00
},
@discourseComputed("step.index")
fieldConditionOptions(stepIndex) {
const options = {
inputTypes: "validation",
context: "field",
textSelection: "value",
userFieldSelection: true,
groupSelection: true,
};
if (stepIndex > 0) {
options.wizardFieldSelection = true;
options.wizardActionSelection = true;
}
return options;
},
@discourseComputed("step.index")
fieldIndexOptions(stepIndex) {
const options = {
context: "field",
userFieldSelection: true,
groupSelection: true,
};
if (stepIndex > 0) {
options.wizardFieldSelection = true;
options.wizardActionSelection = true;
}
return options;
},
actions: {
2020-03-30 01:53:28 +02:00
imageUploadDone(upload) {
2022-08-02 13:39:56 +02:00
this.setProperties({
"field.image": upload.url,
2022-08-02 14:57:19 +02:00
"field.image_upload_id": upload.id,
2022-08-02 13:39:56 +02:00
});
2020-03-30 01:53:28 +02:00
},
2020-03-30 01:53:28 +02:00
imageUploadDeleted() {
2022-08-02 13:39:56 +02:00
this.setProperties({
"field.image": null,
2022-08-02 14:57:19 +02:00
"field.image_upload_id": null,
2022-08-02 13:39:56 +02:00
});
},
},
2017-09-23 04:34:07 +02:00
});