Skip to content

Commit 1f84378

Browse files
committed
Autor bearbeiten Button verschoben nach Bearbeiten
1 parent dd2d109 commit 1f84378

File tree

7 files changed

+70
-36
lines changed

7 files changed

+70
-36
lines changed

files_wcf/js/Hanashi/Change/Author.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
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) {
22
"use strict";
33
Object.defineProperty(exports, "__esModule", { value: true });
44
exports.ChangeAuthor = void 0;
5+
EventHandler = tslib_1.__importStar(EventHandler);
56
UiNotification = tslib_1.__importStar(UiNotification);
67
Language = tslib_1.__importStar(Language);
78
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",
1216
});
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+
});
1426
}
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());
1731
if (ok) {
1832
UiNotification.show(Language.getPhrase("wcf.message.changeAuthor.success"), function () {
1933
window.location.reload();

package.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<packagename language="de">Beitrags-Autor bearbeiten</packagename>
77
<packagedescription>This plugin allows you to change the author of a post in the forum.</packagedescription>
88
<packagedescription language="de">Mit diesem Plugin lässt sich der Autor eines Beitrages im Forum ändern.</packagedescription>
9-
<version>1.0.1</version>
10-
<date>2025-07-08</date>
9+
<version>1.0.2</version>
10+
<date>2025-07-12</date>
1111
</packageinformation>
1212
<authorinformation>
1313
<author>Hanashi Development</author>
@@ -30,10 +30,10 @@
3030
<instruction type="userGroupOption"/>
3131
<instruction type="objectType"/>
3232
</instructions>
33-
<instructions type="update" fromversion="1.0.0">
34-
<instruction type="file" application="wbb">files_wbb.tar</instruction>
33+
<instructions type="update" fromversion="1.0.1">
34+
<instruction type="file" application="wcf">files_wcf.tar</instruction>
3535
<instruction type="template" application="wbb">templates_wbb.tar</instruction>
36-
<instruction type="language"/>
37-
<instruction type="objectType"/>
36+
<instruction type="templateListener"/>
37+
<instruction type="templateDelete"/>
3838
</instructions>
3939
</package>

templateDelete.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/6.0/templateDelete.xsd">
3+
<delete>
4+
<template application="wbb">__threadPostListChangeAuthor</template>
5+
</delete>
6+
</data>

templateListener.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/6.0/templateListener.xsd">
33
<import>
4-
<templatelistener name="threadPostListChangeAuthor">
5-
<environment>user</environment>
6-
<templatename>threadPostList</templatename>
7-
<eventname>messageFooterButtons</eventname>
8-
<templatecode><![CDATA[{include file='__threadPostListChangeAuthor' application='wbb'}]]></templatecode>
9-
</templatelistener>
104
<templatelistener name="threadPostListChangeAuthorJs">
115
<environment>user</environment>
126
<templatename>threadPostList</templatename>
137
<eventname>beforePosts</eventname>
148
<templatecode><![CDATA[{include file='__threadPostListChangeAuthorJs' application='wbb'}]]></templatecode>
159
</templatelistener>
1610
</import>
11+
<delete>
12+
<templatelistener name="threadPostListChangeAuthor">
13+
<environment>user</environment>
14+
<templatename>threadPostList</templatename>
15+
<eventname>messageFooterButtons</eventname>
16+
</templatelistener>
17+
</delete>
1718
</data>

templates_wbb/__threadPostListChangeAuthor.tpl

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<script data-relocate="true">
22
require(["Hanashi/Change/Author"], ({ ChangeAuthor }) => {
33
{jsphrase name='wcf.message.changeAuthor.success'}
4+
{jsphrase name='wcf.message.changeAuthor'}
5+
{capture assign='changeAuthorLink'}{link controller='ChangeAuthor' application='wbb'}{/link}{/capture}
46
5-
new ChangeAuthor();
7+
new ChangeAuthor('{unsafe:$changeAuthorLink|encodeJS}');
68
});
79
</script>

ts/Hanashi/Change/Author.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
import { dialogFactory } from "WoltLabSuite/Core/Component/Dialog";
2+
import * as EventHandler from "WoltLabSuite/Core/Event/Handler";
23
import * as UiNotification from "WoltLabSuite/Core/Ui/Notification";
34
import * as Language from "WoltLabSuite/Core/Language";
45

56
export class ChangeAuthor {
6-
constructor() {
7-
for (const button of document.querySelectorAll(".jsChangeAuthor")) {
8-
button.addEventListener("click", (event: MouseEvent) => {
9-
void this.#changeAuthorClicked(event.target as HTMLButtonElement);
7+
readonly #endpoint: string;
8+
9+
constructor(endpoint: string) {
10+
this.#endpoint = endpoint;
11+
12+
EventHandler.add("com.woltlab.wcf.inlineEditor", "dropdownInit_wbbPost", (data) => {
13+
(data.items as any[]).push({
14+
item: "changeAuthor",
15+
label: "wcf.message.changeAuthor",
1016
});
11-
}
17+
});
18+
19+
EventHandler.add("com.woltlab.wcf.inlineEditor", "dropdownItemClick_wbbPost", (data) => {
20+
if (data.item != "changeAuthor") {
21+
return;
22+
}
23+
data.cancel = true;
24+
const postID = parseInt((data.element as HTMLElement).dataset.objectId ?? "0");
25+
26+
void this.#changeAuthor(postID);
27+
});
1228
}
1329

14-
async #changeAuthorClicked(button: HTMLButtonElement) {
15-
const { ok } = await dialogFactory().usingFormBuilder().fromEndpoint(button.dataset.endpoint!);
30+
async #changeAuthor(postID: number) {
31+
const url = new URL(this.#endpoint);
32+
url.searchParams.set("id", postID.toString());
33+
34+
const { ok } = await dialogFactory().usingFormBuilder().fromEndpoint(url.toString());
1635
if (ok) {
1736
UiNotification.show(
1837
Language.getPhrase("wcf.message.changeAuthor.success"),

0 commit comments

Comments
 (0)