diff --git a/src/js/popup.js b/src/js/popup.js index 43bc529..499cfbc 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -263,6 +263,9 @@ const Logic = { } return identity; }); + + // reset selected container for deletion + this._currentSelectedIdentities = []; }, getPanelSelector(panel) { @@ -341,6 +344,21 @@ const Logic = { return this._currentSelectedIdentities; }, + addSelectedIdentiry(identity) { + const index = this._currentSelectedIdentities.indexOf(identity); + if (index === -1) { + this._currentSelectedIdentities.push(identity); + } + }, + + removeSelectedIdentity(identity) { + const index = this._currentSelectedIdentities.indexOf(identity); + + if (index !== -1) { + this._currentSelectedIdentities.splice(index, 1); + } + }, + currentUserContextId() { const identity = Logic.currentIdentity(); return Logic.userContextId(identity.cookieStoreId); @@ -970,6 +988,8 @@ Logic.registerPanel(P_CONTAINER_INFO, { Logic.registerPanel(P_CONTAINERS_EDIT, { panelSelector: "#edit-containers-panel", + selectedHistory: [], + switchOn: 0, // This method is called when the object is registered. initialize() { @@ -986,13 +1006,18 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { await Logic.showPanel(P_CONTAINER_DELETE, null, selectedIdentities); } }); - }, - // showing delete button if there is any selected containers - showDeleteSelectedButton(selectedContainers) { - const assignmentPanel = document.getElementById("edit-sites-assigned"); - const assignmentKeys = Object.keys(selectedContainers); - assignmentPanel.hidden = !(assignmentKeys.length > 0); + document.addEventListener("keydown", e => { + if (e.keyCode === 16) { + this.switchOn = 1; + } + }); + + document.addEventListener("keyup", e => { + if (e.keyCode === 16) { + this.switchOn = 0; + } + }); }, // This method is called when the panel is shown. @@ -1003,7 +1028,7 @@ Logic.registerPanel(P_CONTAINERS_EDIT, { fragment.appendChild(tr); tr.classList.add("container-panel-row"); tr.innerHTML = escaped` - +
end) { + const tmp = start; + end = start; + start = tmp; + } + + for (let i = start; i <= end; i++) { + Logic.addSelectedIdentiry(identities[i]); + } + + } else if (index === -1) { + this.selectedHistory.push(identity); + Logic.addSelectedIdentiry(identity); + } else if (this.switchOn === 0){ + this.selectedHistory.splice(index, 1); + Logic.removeSelectedIdentity(identity); + } + console.log(Logic.currentSelectedIdentities()); } }); }); diff --git a/src/popup.html b/src/popup.html index ce64fc3..4581cbe 100644 --- a/src/popup.html +++ b/src/popup.html @@ -179,7 +179,7 @@
-