diff options
-rw-r--r-- | app/view/templates/home.php | 3 | ||||
-rw-r--r-- | src/edit.js | 4 | ||||
-rw-r--r-- | src/home.js | 28 | ||||
-rw-r--r-- | webpack.config.js | 1 |
4 files changed, 33 insertions, 3 deletions
diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 3c2db4d..2ee791a 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -36,7 +36,7 @@ <table id="home2table"> <thead> <tr> - <th class="hidephone">x</th> + <th id="checkall" class="hidephone">x</th> <th><a href="<?= $opt->getadress('id') ?>">id</a></th> <th>edit</th> <th>see</th> @@ -176,6 +176,7 @@ <?php } ?> + <script src="<?= Model::jspath() ?>home.bundle.js"></script> </body> diff --git a/src/edit.js b/src/edit.js index eaf2d1e..19f952f 100644 --- a/src/edit.js +++ b/src/edit.js @@ -16,7 +16,7 @@ let editors = []; let unsavedChanges = false; const inputEvent = new InputEvent('input'); -window.onload = () => { +window.addEventListener('load', () => { form = document.getElementById('update'); let inputs = form.elements; for (const input of inputs) { @@ -87,7 +87,7 @@ window.onload = () => { window.onkeydown = keyboardHandler; window.onbeforeunload = confirmExit; -}; +}); /** * Manage a keyboardEvent diff --git a/src/home.js b/src/home.js new file mode 100644 index 0000000..b10e7c3 --- /dev/null +++ b/src/home.js @@ -0,0 +1,28 @@ +/** @type {HTMLInputElement[]} */ +let checkboxes = []; + +window.addEventListener('load', () => { + checkboxes = document.getElementsByName('id[]'); + let checkall = document.getElementById('checkall'); + let checkbox = document.createElement('input'); + checkbox.type = 'checkbox'; + checkbox.addEventListener('input', checkallHandler); + checkall.innerHTML = ''; + checkall.appendChild(checkbox); +}); + +/** + * Manage input event on the checkall checkbox. + * @param {InputEvent} e the input event + */ +function checkallHandler(e) { + if (e.target.checked) { + for (const checkbox of checkboxes) { + checkbox.checked = true; + } + } else { + for (const checkbox of checkboxes) { + checkbox.checked = false; + } + } +} diff --git a/webpack.config.js b/webpack.config.js index 734b3cd..a761cbd 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,6 +10,7 @@ module.exports = (env) => { // Constant entry: { edit: './src/edit.js', + home: './src/home.js', }, output: { filename: 'assets/js/[name].bundle.js', |