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