This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/static/js/main_inventory.js

104 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-01-11 10:21:17 +00:00
$(document).ready(function() {
var show_action_form = $("#allocateModal").data('show-action-form');
if (show_action_form != "None") {
$("#allocateModal .btn-primary").show();
newAllocate(show_action_form);
} else {
$(".deviceSelect").on("change", deviceSelect);
}
// $('#selectLot').selectpicker();
})
function deviceSelect() {
2022-02-04 10:30:29 +00:00
var devices_count = $(".deviceSelect").filter(':checked').length;
2022-02-03 12:58:54 +00:00
if (devices_count == 0) {
$("#addingLotModal .pol").show();
$("#addingLotModal .btn-primary").hide();
$("#removeLotModal .pol").show();
2022-01-03 10:32:12 +00:00
$("#removeLotModal .btn-primary").hide();
2022-02-03 12:58:54 +00:00
$("#addingTagModal .pol").show();
2022-01-25 11:53:36 +00:00
$("#addingTagModal .btn-primary").hide();
2022-02-03 12:58:54 +00:00
$("#actionModal .pol").show();
2022-02-03 12:58:54 +00:00
$("#actionModal .btn-primary").hide();
$("#allocateModal .pol").show();
2022-02-03 12:58:54 +00:00
$("#allocateModal .btn-primary").hide();
} else {
$("#addingLotModal .pol").hide();
$("#addingLotModal .btn-primary").show();
$("#removeLotModal .pol").hide();
2022-01-03 10:32:12 +00:00
$("#removeLotModal .btn-primary").show();
$("#actionModal .pol").hide();
$("#actionModal .btn-primary").show();
2022-01-10 14:53:11 +00:00
$("#allocateModal .pol").hide();
2022-01-10 14:53:11 +00:00
$("#allocateModal .btn-primary").show();
2022-02-02 12:05:55 +00:00
$("#addingTagModal .pol").hide();
}
}
2022-01-03 12:40:30 +00:00
2022-01-25 13:39:15 +00:00
function removeTag() {
var devices = $(".deviceSelect").filter(':checked');
var devices_id = $.map(devices, function(x) { return $(x).attr('data')});
console.log(devices_id);
if (devices_id.length > 0) {
var url = "/inventory/tag/devices/"+devices_id[0]+"/del/";
window.location.href = url;
}
}
2022-01-03 12:40:30 +00:00
function newAction(action) {
$("#actionModal #type").val(action);
$("#actionModal #title-action").html(action);
2022-02-04 10:30:29 +00:00
get_device_list();
deviceSelect();
$("#activeActionModal").click();
2022-01-03 12:40:30 +00:00
}
2022-01-10 14:53:11 +00:00
function newAllocate(action) {
$("#allocateModal #type").val(action);
$("#allocateModal #title-action").html(action);
2022-02-04 10:30:29 +00:00
get_device_list();
deviceSelect();
2022-01-10 14:53:11 +00:00
$("#activeAllocateModal").click();
}
2022-02-04 10:30:29 +00:00
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": "<i class='bi bi-building'></i>",
"Laptop": "<i class='bi bi-laptop'></i>",
};
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);
}