0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-14 05:52:52 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-text-editor.js.es6

73 Zeilen
1,8 KiB
Text

2021-04-12 07:44:47 +02:00
import discourseComputed from "discourse-common/utils/decorators";
2020-04-14 07:46:06 +02:00
import { notEmpty } from "@ember/object/computed";
import { userProperties } from "../lib/wizard";
2020-03-30 01:53:28 +02:00
import { scheduleOnce } from "@ember/runloop";
2020-04-05 03:37:09 +02:00
import Component from "@ember/component";
2020-05-28 05:06:06 +02:00
import I18n from "I18n";
2020-03-29 09:49:33 +02:00
const excludedUserProperties = [
"avatar",
"profile_background",
"card_background",
];
2020-04-05 03:37:09 +02:00
export default Component.extend({
classNames: "wizard-text-editor",
2020-03-30 01:53:28 +02:00
barEnabled: true,
previewEnabled: true,
fieldsEnabled: true,
hasWizardFields: notEmpty("wizardFieldList"),
hasWizardActions: notEmpty("wizardActionList"),
2020-03-30 01:53:28 +02:00
didReceiveAttrs() {
this._super(...arguments);
2020-03-30 01:53:28 +02:00
if (!this.barEnabled) {
scheduleOnce("afterRender", () => {
$(this.element).find(".d-editor-button-bar").addClass("hidden");
2020-03-30 01:53:28 +02:00
});
}
},
@discourseComputed("forcePreview")
2020-03-29 09:49:33 +02:00
previewLabel(forcePreview) {
return I18n.t("admin.wizard.editor.preview", {
action: I18n.t(`admin.wizard.editor.${forcePreview ? "hide" : "show"}`),
2020-03-29 09:49:33 +02:00
});
},
@discourseComputed("showPopover")
2020-03-29 09:49:33 +02:00
popoverLabel(showPopover) {
return I18n.t("admin.wizard.editor.popover", {
action: I18n.t(`admin.wizard.editor.${showPopover ? "hide" : "show"}`),
2020-03-29 09:49:33 +02:00
});
},
2020-03-29 09:49:33 +02:00
@discourseComputed()
userPropertyList() {
return userProperties
.filter((f) => !excludedUserProperties.includes(f))
.map((f) => ` u{${f}}`);
2020-03-29 09:49:33 +02:00
},
@discourseComputed("wizardFields")
2020-03-29 09:49:33 +02:00
wizardFieldList(wizardFields) {
return wizardFields.map((f) => ` w{${f.id}}`);
},
@discourseComputed("wizardActions")
wizardActionList(wizardActions) {
return wizardActions.map((a) => ` w{${a.id}}`);
},
2020-03-29 09:49:33 +02:00
actions: {
togglePreview() {
this.toggleProperty("forcePreview");
2020-03-29 09:49:33 +02:00
},
2020-03-29 09:49:33 +02:00
togglePopover() {
this.toggleProperty("showPopover");
},
},
});