From 4aa024b04191dc682ebf63f6751edf9d6abc4454 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Thu, 28 Apr 2022 16:58:44 +0200 Subject: [PATCH 1/5] checkpoint: add confirmation dialog --- ereuse_devicehub/static/js/main_inventory.js | 52 ++++++++++++++++--- .../inventory/alert_lots_changes.html | 19 +++++++ .../templates/inventory/device_list.html | 3 +- 3 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 ereuse_devicehub/templates/inventory/alert_lots_changes.html diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 6cb71534..69b09138 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -276,6 +276,7 @@ async function processSelectedDevices() { this.list = []; } }) + $("#confirmLotsModal").modal("hide"); // Hide dialog when click "Save changes" document.getElementById("dropDownLotsSelector").classList.remove("show"); } @@ -302,10 +303,9 @@ async function processSelectedDevices() { /** * Generates a list item with a correspondient checkbox state - * @param {String} lotID - * @param {String} lotName - * @param {Array} selectedDevicesIDs - * @param {HTMLElement} target + * @param {Object} lot Lot model server + * @param {HTMLElement} elementTarget + * @param {Array} actions */ function templateLot(lot, elementTarget, actions) { elementTarget.innerHTML = "" @@ -357,7 +357,48 @@ async function processSelectedDevices() { if (eventClickActions) { document.getElementById("ApplyDeviceLots").removeEventListener(eventClickActions); } - eventClickActions = document.getElementById("ApplyDeviceLots").addEventListener("click", () => actions.doActions()); + eventClickActions = document.getElementById("ApplyDeviceLots").addEventListener("click", () => { + const modal = $("#confirmLotsModal") + modal.modal({ keyboard: false }) + + let list_changes_html = ""; + // {type: ["Remove" | "Add"], "LotID": string, "devices": number[]} + actions.list.forEach(action => { + let type; + let devices; + if (action.type == "Add") { + type = "success"; + devices = action.devices.filter(dev => !action.lot.devices.includes(dev)) // Only show affected devices + } else { + type = "danger"; + devices = action.devices.filter(dev => action.lot.devices.includes(dev)) // Only show affected devices + } + list_changes_html += ` +
+
${action.lot.name}
+
+

+ ${devices.map(item => { + const dhid = $(".deviceSelect").filter(`[data=${item}]`)[0].attributes["data-device-dhid"].value; + const name = $(".deviceSelect").filter(`[data=${item}]`)[0].attributes["data-device-vname"].value; + return `${dhid}` + }).join(" ")} +

+
+
`; + }) + + modal.find(".modal-body").html(list_changes_html) + + const el = document.getElementById("SaveAllActions") + const elClone = el.cloneNode(true); + el.parentNode.replaceChild(elClone, el); + elClone.addEventListener("click", () => actions.doActions()) + + modal.modal("show") + + // actions.doActions(); + }); document.getElementById("ApplyDeviceLots").classList.add("disabled"); try { @@ -385,7 +426,6 @@ async function processSelectedDevices() { return lot; }) - let lotsList = []; lotsList.push(lots.filter(lot => lot.state == "true").sort((a,b) => a.name.localeCompare(b.name))); lotsList.push(lots.filter(lot => lot.state == "indetermined").sort((a,b) => a.name.localeCompare(b.name))); diff --git a/ereuse_devicehub/templates/inventory/alert_lots_changes.html b/ereuse_devicehub/templates/inventory/alert_lots_changes.html new file mode 100644 index 00000000..fa2613c9 --- /dev/null +++ b/ereuse_devicehub/templates/inventory/alert_lots_changes.html @@ -0,0 +1,19 @@ + + \ No newline at end of file diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 827c3b68..79a25330 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -329,7 +329,7 @@