Stimulus controller to delete record
This commit is contained in:
36
assets/controllers/delete_record_controller.js
Normal file
36
assets/controllers/delete_record_controller.js
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user