Stimulus controller to delete record

This commit is contained in:
2024-11-06 22:02:56 +01:00
parent 4e52ea48f6
commit 36185d0539
4 changed files with 133 additions and 79 deletions

View File

@@ -0,0 +1,36 @@
import { Controller } from '@hotwired/stimulus';
/**
* Show warning before deleting record
* [template: {entity}/index.html.twig]
*/
export default class extends Controller {
static targets = ['modal', 'path'];
/**
* @todo Refactor with actions for modal
* @param {object} event
*/
show(event) {
event.preventDefault();
const modal = this.modalTarget;
modal.classList.add('is-active');
modal.querySelector('.delete').addEventListener('click', () => {
modal.classList.remove('is-active');
});
modal.querySelector('.modal-background').addEventListener('click', () => {
modal.classList.remove('is-active');
});
modal.querySelector('#cancel').addEventListener('click', () => {
modal.classList.remove('is-active');
});
}
// Proceed with deletion...
delete(event) {
const delPath = this.pathTarget.href;
location.href = delPath;
}
}