2021-03-28 11:06:49 +02:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2021-11-11 12:50:10 +01:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import getUrl from "discourse-common/lib/get-url";
|
2022-06-02 17:49:16 +02:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2017-11-22 10:34:21 +01:00
|
|
|
|
|
|
|
export default {
|
2021-03-28 11:06:49 +02:00
|
|
|
name: "custom-wizard-edits",
|
2019-12-05 07:48:32 +01:00
|
|
|
initialize(container) {
|
2021-03-28 11:06:49 +02:00
|
|
|
const siteSettings = container.lookup("site-settings:main");
|
|
|
|
|
2021-04-12 08:12:20 +02:00
|
|
|
if (!siteSettings.custom_wizard_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-14 05:35:38 +01:00
|
|
|
|
|
|
|
const existing = DiscourseURL.routeTo;
|
2021-03-28 11:06:49 +02:00
|
|
|
DiscourseURL.routeTo = function (path, opts) {
|
|
|
|
if (path && path.indexOf("/w/") > -1) {
|
|
|
|
return (window.location = path);
|
2018-03-14 05:35:38 +01:00
|
|
|
}
|
|
|
|
return existing.apply(this, [path, opts]);
|
|
|
|
};
|
2021-11-11 12:50:10 +01:00
|
|
|
|
|
|
|
withPluginApi("0.8.7", (api) => {
|
|
|
|
api.modifyClass("component:d-navigation", {
|
2021-11-11 13:08:53 +01:00
|
|
|
pluginId: "custom-wizard",
|
2021-11-11 12:50:10 +01:00
|
|
|
actions: {
|
2021-11-11 13:08:53 +01:00
|
|
|
clickCreateTopicButton() {
|
|
|
|
let createTopicWizard = this.get(
|
|
|
|
"category.custom_fields.create_topic_wizard"
|
|
|
|
);
|
2021-11-11 12:50:10 +01:00
|
|
|
if (createTopicWizard) {
|
|
|
|
window.location.href = getUrl(`/w/${createTopicWizard}`);
|
|
|
|
} else {
|
|
|
|
this._super();
|
|
|
|
}
|
2021-11-11 13:08:53 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-06-02 17:49:16 +02:00
|
|
|
|
|
|
|
api.modifyClass("component:uppy-image-uploader", {
|
|
|
|
// Needed to ensure appEvents get registered when navigating between steps
|
|
|
|
@observes("id")
|
|
|
|
initOnStepChange() {
|
|
|
|
if (/wizard-field|wizard-step/.test(this.id)) {
|
|
|
|
this._initialize();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2021-11-11 12:50:10 +01:00
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2017-11-22 10:34:21 +01:00
|
|
|
};
|