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/initializers/custom-wizard-edits.js.es6

89 Zeilen
2,4 KiB
Text

import DiscourseURL from "discourse/lib/url";
2021-09-24 11:58:42 +02:00
import { withPluginApi } from "discourse/lib/plugin-api";
import getUrl from "discourse-common/lib/get-url";
import { observes } from "discourse-common/utils/decorators";
2017-11-22 10:34:21 +01:00
export default {
name: "custom-wizard-edits",
initialize(container) {
const siteSettings = container.lookup("service:site-settings");
2021-04-12 08:12:20 +02:00
if (!siteSettings.custom_wizard_enabled) {
return;
}
const existing = DiscourseURL.routeTo;
DiscourseURL.routeTo = function (path, opts) {
if (path && path.indexOf("/w/") > -1) {
return (window.location = path);
}
return existing.apply(this, [path, opts]);
};
2021-09-24 11:58:42 +02:00
withPluginApi("0.8.36", (api) => {
api.modifyClass("component:d-navigation", {
2021-11-11 13:08:53 +01:00
pluginId: "custom-wizard",
actions: {
2021-11-11 13:08:53 +01:00
clickCreateTopicButton() {
let createTopicWizard = this.get(
"category.custom_fields.create_topic_wizard"
);
if (createTopicWizard) {
window.location.href = getUrl(`/w/${createTopicWizard}`);
} else {
this._super();
}
2021-11-11 13:08:53 +01:00
},
2021-11-17 13:48:11 +01:00
},
2021-09-24 11:58:42 +02:00
});
api.modifyClass("component:uppy-image-uploader", {
2022-07-27 12:47:50 +02:00
pluginId: "custom-wizard",
// Needed to ensure appEvents get registered when navigating between steps
@observes("id")
initOnStepChange() {
if (/wizard-field|wizard-step/.test(this.id)) {
this._initialize();
}
},
});
api.modifyClass("component:d-editor", {
pluginId: "custom-wizard",
didInsertElement() {
this._super(...arguments);
if (this.wizardComposer) {
this.appEvents.on(
`wizard-editor:insert-text`,
this,
"_wizardInsertText"
);
this.appEvents.on(
"wizard-editor:replace-text",
this,
"_wizardReplaceText"
);
}
},
_wizardInsertText(text, options) {
2023-05-23 10:27:42 +02:00
if (
this.session.wizardEventFieldId === this.fieldId &&
this.element
) {
this.insertText(text, options);
}
},
_wizardReplaceText(oldVal, newVal, opts = {}) {
if (this.session.wizardEventFieldId === this.fieldId) {
this.replaceText(oldVal, newVal, opts);
}
},
});
2021-09-24 11:58:42 +02:00
});
},
2017-11-22 10:34:21 +01:00
};