From f011e29ce90d425463b89580a70b87ba4cec7be7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 4 Feb 2022 11:30:29 +0100 Subject: [PATCH] add description of device in actions --- ereuse_devicehub/static/js/main_inventory.js | 46 +++++++++++++++---- .../templates/inventory/device_list.html | 6 ++- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 48834647..f1bb44eb 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -10,9 +10,7 @@ $(document).ready(function() { }) function deviceSelect() { - var devices = $(".deviceSelect").filter(':checked'); - var devices_count = devices.length; - var devices_id = $.map(devices, function(x) { return $(x).attr('data')}).join(","); + var devices_count = $(".deviceSelect").filter(':checked').length; if (devices_count == 0) { $("#addingLotModal .text-danger").show(); $("#addingLotModal .btn-primary").hide(); @@ -43,9 +41,6 @@ function deviceSelect() { $("#addingTagModal .text-danger").hide(); } - $.map($(".devicesList"), function(x) { - $(x).val(devices_id); - }); } function removeTag() { @@ -61,15 +56,46 @@ function removeTag() { function newAction(action) { $("#actionModal #type").val(action); $("#actionModal #title-action").html(action); - var devices_count = $(".deviceSelect").filter(':checked').length; - $("#actionModal .devices-count").html(devices_count); + get_device_list(); $("#activeActionModal").click(); } function newAllocate(action) { $("#allocateModal #type").val(action); $("#allocateModal #title-action").html(action); - var devices_count = $(".deviceSelect").filter(':checked').length; - $("#allocateModal .devices-count").html(devices_count); + get_device_list(); $("#activeAllocateModal").click(); } + +function get_device_list() { + var devices = $(".deviceSelect").filter(':checked'); + + /* Insert the correct count of devices in actions form */ + var devices_count = devices.length; + $("#allocateModal .devices-count").html(devices_count); + $("#actionModal .devices-count").html(devices_count); + + /* Insert the correct value in the input devicesList */ + var devices_id = $.map(devices, function(x) { return $(x).attr('data')}).join(","); + $.map($(".devicesList"), function(x) { + $(x).val(devices_id); + }); + + /* Create a list of devices for human representation */ + var computer = { + "Desktop": "", + "Laptop": "", + }; + list_devices = devices.map(function (x) { + var typ = $(devices[x]).data("device-type"); + var manuf = $(devices[x]).data("device-manufacturer"); + var dhid = $(devices[x]).data("device-dhid"); + if (computer[typ]) { + typ = computer[typ]; + }; + return typ + " " + manuf + " " + dhid; + }); + + description = $.map(list_devices, function(x) { return x }).join(", "); + $(".enumeration-devices").html(description); +} diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index ead573bf..0c898246 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -234,7 +234,11 @@ {% for dev in devices %} - + + + {{ dev.type }} {{ dev.manufacturer }} {{ dev.model }}