-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
291 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Sends a post request to the given endpoint. | ||
* | ||
* @author Marcel Werk | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.2 | ||
* @woltlabExcludeBundle tiny | ||
*/ | ||
|
||
import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; | ||
import { ApiResult, apiResultFromError, apiResultFromValue } from "./Result"; | ||
|
||
export async function postObject(endpoint: string): Promise<ApiResult<[]>> { | ||
try { | ||
await prepareRequest(endpoint).post().fetchAsJson(); | ||
} catch (e) { | ||
return apiResultFromError(e); | ||
} | ||
|
||
return apiResultFromValue([]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector"; | ||
import { postObject } from "WoltLabSuite/Core/Api/PostObject"; | ||
|
||
async function handleToggle(checked: boolean, enableEndpoint: string, disableEndpoint: string): Promise<void> { | ||
await postObject(checked ? enableEndpoint : disableEndpoint); | ||
} | ||
|
||
export function setup(tableId: string): void { | ||
wheneverFirstSeen(`#${tableId} .gridView__row woltlab-core-toggle-button`, (toggleButton) => { | ||
toggleButton.addEventListener("change", (event: CustomEvent) => { | ||
void handleToggle( | ||
event.detail.checked as boolean, | ||
toggleButton.dataset.enableEndpoint!, | ||
toggleButton.dataset.disableEndpoint!, | ||
); | ||
}); | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
wcfsetup/install/files/js/WoltLabSuite/Core/Api/PostObject.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
wcfsetup/install/files/js/WoltLabSuite/Core/Api/ToggleObject.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 7 additions & 2 deletions
9
wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Action/Toggle.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
wcfsetup/install/files/lib/system/view/grid/action/AbstractAction.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace wcf\system\view\grid\action; | ||
|
||
use Closure; | ||
|
||
abstract class AbstractAction implements IGridViewAction | ||
{ | ||
public function __construct( | ||
private readonly ?Closure $isAvailableCallback = null | ||
) {} | ||
|
||
#[\Override] | ||
public function isAvailable(mixed $row): bool | ||
{ | ||
if ($this->isAvailableCallback === null) { | ||
return true; | ||
} | ||
|
||
return ($this->isAvailableCallback)($row); | ||
} | ||
|
||
#[\Override] | ||
public function isQuickAction(): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.