|
1 | | -define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Dialog", "WoltLabSuite/Core/Ui/Notification", "WoltLabSuite/Core/Language"], function (require, exports, tslib_1, Dialog_1, UiNotification, Language) { |
| 1 | +define(["require", "exports", "tslib", "WoltLabSuite/Core/Component/Dialog", "WoltLabSuite/Core/Event/Handler", "WoltLabSuite/Core/Ui/Notification", "WoltLabSuite/Core/Language"], function (require, exports, tslib_1, Dialog_1, EventHandler, UiNotification, Language) { |
2 | 2 | "use strict"; |
3 | 3 | Object.defineProperty(exports, "__esModule", { value: true }); |
4 | 4 | exports.ChangeAuthor = void 0; |
| 5 | + EventHandler = tslib_1.__importStar(EventHandler); |
5 | 6 | UiNotification = tslib_1.__importStar(UiNotification); |
6 | 7 | Language = tslib_1.__importStar(Language); |
7 | 8 | class ChangeAuthor { |
8 | | - constructor() { |
9 | | - for (const button of document.querySelectorAll(".jsChangeAuthor")) { |
10 | | - button.addEventListener("click", (event) => { |
11 | | - void this.#changeAuthorClicked(event.target); |
| 9 | + #endpoint; |
| 10 | + constructor(endpoint) { |
| 11 | + this.#endpoint = endpoint; |
| 12 | + EventHandler.add("com.woltlab.wcf.inlineEditor", "dropdownInit_wbbPost", (data) => { |
| 13 | + data.items.push({ |
| 14 | + item: "changeAuthor", |
| 15 | + label: "wcf.message.changeAuthor", |
12 | 16 | }); |
13 | | - } |
| 17 | + }); |
| 18 | + EventHandler.add("com.woltlab.wcf.inlineEditor", "dropdownItemClick_wbbPost", (data) => { |
| 19 | + if (data.item != "changeAuthor") { |
| 20 | + return; |
| 21 | + } |
| 22 | + data.cancel = true; |
| 23 | + const postID = parseInt(data.element.dataset.objectId ?? "0"); |
| 24 | + void this.#changeAuthor(postID); |
| 25 | + }); |
14 | 26 | } |
15 | | - async #changeAuthorClicked(button) { |
16 | | - const { ok } = await (0, Dialog_1.dialogFactory)().usingFormBuilder().fromEndpoint(button.dataset.endpoint); |
| 27 | + async #changeAuthor(postID) { |
| 28 | + const url = new URL(this.#endpoint); |
| 29 | + url.searchParams.set("id", postID.toString()); |
| 30 | + const { ok } = await (0, Dialog_1.dialogFactory)().usingFormBuilder().fromEndpoint(url.toString()); |
17 | 31 | if (ok) { |
18 | 32 | UiNotification.show(Language.getPhrase("wcf.message.changeAuthor.success"), function () { |
19 | 33 | window.location.reload(); |
|
0 commit comments