From f3d3538ff56d4895b0d2ffb960dcf8ca4757a63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Montero=20Lamas?= Date: Sat, 1 Jan 2022 16:56:22 +0100 Subject: [PATCH] Added lock/unlock all (#713) * Added lock/unlock all Lock All , Unlock All as separate buttons. Additionally to InvertLock. * Update burgs-overview.js Updated the syntax to the one suggested by Azgaar. * Lock/unlock in one button Unlock all burgs and lock all burgs in just one button. Additionally to invert lock. * lock unlock in burgs-overview.js Added a way to check if burgs are locked or unlocked with the lock all button, so it works in any situations about locking. * burgs-overview.js lock all Changed burgsonoff to setLockBurgs, also put setLockIcon. * index.html burgsonoff to burgsLockAll * Update burgs-overview.js spacing --- index.html | 1 + modules/ui/burgs-overview.js | 42 +++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index f4c9bda7..39e59bf3 100644 --- a/index.html +++ b/index.html @@ -3287,6 +3287,7 @@ + diff --git a/modules/ui/burgs-overview.js b/modules/ui/burgs-overview.js index 97093035..11006a03 100644 --- a/modules/ui/burgs-overview.js +++ b/modules/ui/burgs-overview.js @@ -8,6 +8,7 @@ function overviewBurgs() { const body = document.getElementById("burgsBody"); updateFilter(); burgsOverviewAddLines(); + setLockIcon(); $("#burgsOverview").dialog(); if (modules.overviewBurgs) return; @@ -33,6 +34,8 @@ function overviewBurgs() { document.getElementById("burgsListToLoad").addEventListener("change", function () { uploadFile(this, importBurgNames); }); + document.getElementById("burgsLockAll").addEventListener("click", setLockBurgs); + document.getElementById("burgsLockAll").addEventListener("click", setLockIcon); document.getElementById("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove); document.getElementById("burgsInvertLock").addEventListener("click", invertLock); @@ -87,7 +90,7 @@ function overviewBurgs() { - ${getCultureOptions( b.culture )} @@ -562,4 +565,41 @@ function overviewBurgs() { pack.burgs = pack.burgs.map(burg => ({...burg, lock: !burg.lock})); burgsOverviewAddLines(); } + + function lockAllBurgs() { + pack.burgs.forEach(burg => { + burg.lock = true; + }); + burgsOverviewAddLines(); + } + + function unlockAllBurgs() { + pack.burgs.forEach(burg => { + burg.lock = false; + }); + burgsOverviewAddLines(); + } + + function setLockBurgs() { + const allLocked = pack.burgs.every(({lock, i, removed}) => lock || !i || removed); + + if (allLocked) { + unlockAllBurgs(); + } else { + lockAllBurgs(); + } + setLockIcon(); + } + + function setLockIcon() { + const allLocked = pack.burgs.every(({lock, i, removed}) => lock || !i || removed); + + if (allLocked) { + burgsLockAll.classList.remove("icon-lock"); + burgsLockAll.classList.add("icon-lock-open"); + } else { + burgsLockAll.classList.add("icon-lock"); + burgsLockAll.classList.remove("icon-lock-open"); + } + } }