Skip to content

Commit 85cee10

Browse files
committed
Add restore action
1 parent da9e837 commit 85cee10

File tree

13 files changed

+173
-69
lines changed

13 files changed

+173
-69
lines changed

ts/WoltLabSuite/Core/Component/Inline/Actions/Disable.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,18 @@
77
* @since 6.2
88
*/
99

10-
import { Action, InlineEditor } from "WoltLabSuite/Core/Component/Inline/Editor";
11-
import { DropdownBuilderItemData } from "WoltLabSuite/Core/Ui/Dropdown/Builder";
12-
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
13-
import { apiResultFromError, apiResultFromValue, ApiResult } from "WoltLabSuite/Core/Api/Result";
14-
import { getPhrase } from "WoltLabSuite/Core/Language";
15-
16-
export class Disable implements Action {
17-
protected readonly inlineEditor: InlineEditor;
18-
protected readonly endpoint: string | URL;
10+
import { InlineEditor } from "WoltLabSuite/Core/Component/Inline/Editor";
11+
import { Simple } from "WoltLabSuite/Core/Component/Inline/Actions/Simple";
1912

13+
export class Disable extends Simple {
2014
constructor(inlineEditor: InlineEditor, endpoint: string | URL) {
21-
this.inlineEditor = inlineEditor;
22-
this.endpoint = endpoint;
15+
super(inlineEditor, "wcf.global.button.disable", endpoint);
2316
}
2417

25-
get item(): DropdownBuilderItemData {
26-
return {
27-
label: getPhrase("wcf.global.button.disable"),
28-
callback: async () => {
29-
const response = await disable(this.endpoint);
30-
31-
if (response.ok) {
32-
this.inlineEditor.update({
33-
isDisabled: true,
34-
});
35-
}
36-
},
37-
};
18+
responseOk(): void {
19+
this.inlineEditor.update({
20+
isDisabled: 1,
21+
});
3822
}
3923

4024
isVisible(): boolean {
@@ -45,13 +29,3 @@ export class Disable implements Action {
4529
);
4630
}
4731
}
48-
49-
async function disable(endpoint: string | URL): Promise<ApiResult<[]>> {
50-
try {
51-
await prepareRequest(endpoint).post().fetchAsJson();
52-
} catch (e) {
53-
return apiResultFromError(e);
54-
}
55-
56-
return apiResultFromValue([]);
57-
}

ts/WoltLabSuite/Core/Component/Inline/Actions/Enable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ export class Enable implements Action {
3636

3737
if (response.ok) {
3838
this.inlineEditor.update({
39-
isDisabled: response.result.isDisabled,
39+
isDisabled: response.result.isDisabled ? 1 : 0,
4040
});
4141
}
4242
} else {
4343
if ((await enable(this.endpoint)).ok) {
4444
this.inlineEditor.update({
45-
isDisabled: false,
45+
isDisabled: 0,
4646
});
4747
}
4848
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Inline editor action to restore an object.
3+
*
4+
* @author Olaf Braun
5+
* @copyright 2001-2025 WoltLab GmbH
6+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7+
* @since 6.2
8+
*/
9+
10+
import { InlineEditor } from "WoltLabSuite/Core/Component/Inline/Editor";
11+
import { Simple } from "WoltLabSuite/Core/Component/Inline/Actions/Simple";
12+
13+
export class Restore extends Simple {
14+
constructor(inlineEditor: InlineEditor, endpoint: string | URL) {
15+
super(inlineEditor, "wcf.global.button.restore", endpoint);
16+
}
17+
18+
responseOk(): void {
19+
this.inlineEditor.update({
20+
isDeleted: 0,
21+
});
22+
}
23+
24+
isVisible(): boolean {
25+
return this.inlineEditor.getPermissions()["canRestore"] && this.inlineEditor.getState("isDeleted");
26+
}
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Inline editor action to restore an object.
3+
*
4+
* @author Olaf Braun
5+
* @copyright 2001-2025 WoltLab GmbH
6+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7+
* @since 6.2
8+
*/
9+
10+
import { Action, InlineEditor } from "WoltLabSuite/Core/Component/Inline/Editor";
11+
import { DropdownBuilderItemData } from "WoltLabSuite/Core/Ui/Dropdown/Builder";
12+
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
13+
import { apiResultFromError, apiResultFromValue, ApiResult } from "WoltLabSuite/Core/Api/Result";
14+
import { getPhrase } from "WoltLabSuite/Core/Language";
15+
16+
export abstract class Simple implements Action {
17+
protected readonly inlineEditor: InlineEditor;
18+
protected readonly endpoint: string | URL;
19+
protected readonly label: string;
20+
21+
protected constructor(inlineEditor: InlineEditor, label: string, endpoint: string | URL) {
22+
this.inlineEditor = inlineEditor;
23+
this.endpoint = endpoint;
24+
this.label = label;
25+
}
26+
27+
get item(): DropdownBuilderItemData {
28+
return {
29+
label: getPhrase(this.label),
30+
callback: async () => {
31+
const response = await request(this.endpoint);
32+
if (response.ok) {
33+
this.responseOk();
34+
}
35+
},
36+
};
37+
}
38+
39+
abstract responseOk(): void;
40+
}
41+
42+
async function request(endpoint: string | URL): Promise<ApiResult<[]>> {
43+
try {
44+
await prepareRequest(endpoint).post().fetchAsJson();
45+
} catch (e) {
46+
return apiResultFromError(e);
47+
}
48+
49+
return apiResultFromValue([]);
50+
}

ts/WoltLabSuite/Core/Component/Inline/Actions/Trash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Trash implements Action {
3737
const response = await trash(this.endpoint, result.reason);
3838
if (response.ok) {
3939
this.inlineEditor.update({
40-
isDeleted: true,
40+
isDeleted: 1,
4141
deleteNote: response.value,
4242
});
4343
}

ts/WoltLabSuite/Core/Component/Inline/Editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class InlineEditor {
7373
showNotification();
7474

7575
Object.entries(data).forEach(([key, value]) => {
76-
this.element.dataset[key] = value.toString();
76+
this.element.dataset[key] = typeof value === "boolean" ? (value ? "1" : "0") : value.toString();
7777
});
7878
}
7979

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Inline/Actions/Disable.js

Lines changed: 7 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Inline/Actions/Enable.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Inline/Actions/Restore.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Inline/Actions/Simple.js

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)