2021-03-28 11:06:49 +02:00
|
|
|
import DiscourseURL from "discourse/lib/url";
|
2021-09-24 11:58:42 +02:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2021-11-11 12:50:10 +01:00
|
|
|
import getUrl from "discourse-common/lib/get-url";
|
2024-10-17 16:15:25 +02:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2024-11-22 15:04:06 +01:00
|
|
|
import CustomWizardTextareaEditor from "../components/custom-wizard-textarea-editor";
|
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) {
|
2022-08-15 13:53:31 +02:00
|
|
|
const siteSettings = container.lookup("service:site-settings");
|
2021-03-28 11:06:49 +02:00
|
|
|
|
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-09-24 11:58:42 +02:00
|
|
|
|
|
|
|
withPluginApi("0.8.36", (api) => {
|
2021-11-11 12:50:10 +01:00
|
|
|
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
|
|
|
},
|
2021-11-17 13:48:11 +01:00
|
|
|
},
|
2021-09-24 11:58:42 +02:00
|
|
|
});
|
2022-06-02 17:49:16 +02:00
|
|
|
|
2022-08-22 15:56:58 +02:00
|
|
|
api.modifyClass("component:d-editor", {
|
|
|
|
pluginId: "custom-wizard",
|
|
|
|
|
2024-11-22 15:04:06 +01:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.editorComponent = CustomWizardTextareaEditor;
|
|
|
|
},
|
|
|
|
|
2022-08-22 15:56:58 +02:00
|
|
|
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
|
|
|
|
) {
|
2024-10-28 09:52:04 +01:00
|
|
|
this.textManipulation.insertText(text, options);
|
2022-08-22 15:56:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_wizardReplaceText(oldVal, newVal, opts = {}) {
|
|
|
|
if (this.session.wizardEventFieldId === this.fieldId) {
|
2024-10-28 09:52:04 +01:00
|
|
|
this.textManipulation.replaceText(oldVal, newVal, opts);
|
2022-08-22 15:56:58 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2023-09-18 23:40:44 +02:00
|
|
|
|
|
|
|
api.modifyClass("component:category-chooser", {
|
2023-10-18 14:22:22 +02:00
|
|
|
pluginId: "custom-wizard",
|
|
|
|
|
2023-09-18 23:40:44 +02:00
|
|
|
categoriesByScope(options = {}) {
|
|
|
|
let categories = this._super(options);
|
2023-10-06 22:24:05 +02:00
|
|
|
const currentUser = this.currentUser;
|
2023-10-07 04:35:36 +02:00
|
|
|
if (!currentUser?.staff) {
|
2023-10-06 22:24:05 +02:00
|
|
|
categories = categories.filter((category) => {
|
|
|
|
return !category.custom_fields?.create_topic_wizard;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return categories;
|
2023-09-18 23:40:44 +02:00
|
|
|
},
|
|
|
|
});
|
2024-04-15 08:58:03 +02:00
|
|
|
|
|
|
|
api.addAdminSidebarSectionLink("plugins", {
|
|
|
|
name: "admin_wizards",
|
|
|
|
label: "admin.wizard.nav_label",
|
|
|
|
route: "adminWizardsWizard",
|
|
|
|
icon: "hat-wizard",
|
|
|
|
});
|
2024-10-17 16:15:25 +02:00
|
|
|
|
|
|
|
if (api.getCurrentUser()?.admin) {
|
|
|
|
api.modifyClass("model:admin-user", {
|
|
|
|
pluginId: "custom-wizard",
|
|
|
|
|
|
|
|
clearWizardRedirect(user) {
|
|
|
|
return ajax(`/admin/users/${user.id}/wizards/clear_redirect`, {
|
|
|
|
type: "PUT",
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
user.setProperties({
|
|
|
|
redirect_to_wizard: null,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-09-24 11:58:42 +02:00
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
},
|
2017-11-22 10:34:21 +01:00
|
|
|
};
|