Fix delete record JS mess

This commit is contained in:
2024-11-11 17:21:00 +01:00
parent 0a0f553510
commit adee0f6d0f
5 changed files with 49 additions and 19 deletions

View File

@@ -5,17 +5,22 @@ import { Controller } from '@hotwired/stimulus';
* [template: {entity}/index.html.twig]
*/
export default class extends Controller {
static targets = ['modal', 'path'];
static targets = ['modal', 'path', 'name', 'message'];
/**
* @todo Refactor with actions for modal
* @param {object} event
*/
show(event) {
warn(event) {
event.preventDefault();
const id = event.currentTarget.getAttribute('data-url').match(/\d+$/)[0];
const modal = this.modalTarget;
const name = this.nameTargets.find(a => a.href.includes(id)).textContent;
const message = `The record '<strong>${name.trim()}</strong>' will be permanently deleted. Proceed?`;
modal.classList.add('is-active');
this.messageTarget.innerHTML = message;
modal.querySelector('.delete').addEventListener('click', () => {
modal.classList.remove('is-active');
});
@@ -28,8 +33,8 @@ export default class extends Controller {
}
// Proceed with deletion...
delete(event) {
const delPath = this.pathTarget.href;
delete() {
const delPath = this.pathTarget.getAttribute('data-url');
location.href = delPath;
}
}

View File

@@ -0,0 +1,13 @@
import { Controller } from '@hotwired/stimulus';
/**
*/
export default class extends Controller {
static targets = [ 'map',];
static values = {
state: Number,
};
initialize() {
}
}