aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Peugnet <33429034+vincent-peugnet@users.noreply.github.com>2019-11-05 18:31:05 +0100
committerGitHub <noreply@github.com>2019-11-05 18:31:05 +0100
commitf1f63f556c41c99d45cd610186b0982383eff375 (patch)
treec62c88864fa4bdc0d54e0bc90d174fae2d8adce3
parent9b43088415efee1f921feb9c858bcd924f1b6208 (diff)
parentd73bbbcf6c7bfe7291ac1593004581df6c96b3c8 (diff)
downloadwcms-f1f63f556c41c99d45cd610186b0982383eff375.tar.gz
wcms-f1f63f556c41c99d45cd610186b0982383eff375.zip
Merge pull request #25 from n-peugnet/add-checkall-checkbox
Add checkall checkbox in home page
-rw-r--r--app/view/templates/home.php3
-rw-r--r--src/edit.js4
-rw-r--r--src/home.js28
-rw-r--r--webpack.config.js1
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 6c2f328..062a0de 100644
--- a/src/edit.js
+++ b/src/edit.js
@@ -15,7 +15,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) {
@@ -86,7 +86,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 c0286df..b4a445a 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -11,6 +11,7 @@ module.exports = (env) => {
// Constant
entry: {
edit: './src/edit.js',
+ home: './src/home.js',
},
output: {
filename: 'assets/js/[name].bundle.js',