feat: require data-modal-id for delete buttons (#8711)

All instances should have a `data-modal-id` now. Throw a user-friendly error if this is not the case (custom templates, or missed cases).

Checked via `rg -P -e '^(?=.*delete-button)' | grep -v "data-modal-id"`

Removed two instances of delete modals and one case of simplified logic.

## Rationale
I am currently surveying the existing modals in Forgejo in the context of eventually replacing the modals implementation with our own modal implementation. This refactor fixes one of the many inconsistencies that the current usage of modals has. It should explicitly specify which modal should be used to avoids any problems if new modals are introduced on the page (for example via https://codeberg.org/forgejo/forgejo/pulls/8662).

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8711
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-08-08 01:53:23 +02:00 committed by Gusted
commit 72bac98365
29 changed files with 50 additions and 76 deletions

View file

@ -369,12 +369,13 @@ export function initGlobalLinkActions() {
e.preventDefault();
const $this = $(this || e.target);
const dataArray = $this.data();
let filter = '';
if ($this[0].getAttribute('data-modal-id')) {
filter += `#${$this[0].getAttribute('data-modal-id')}`;
const modalID = $this[0].getAttribute('data-modal-id');
if (!modalID) {
throw new Error('This button does not specify which modal it wants to open.');
}
const $dialog = $(`.delete.modal${filter}`);
const $dialog = $(`#${modalID}`);
$dialog.find('.name').text($this.data('name'));
for (const [key, value] of Object.entries(dataArray)) {
if (key && key.startsWith('data')) {