2022-01-11 10:21:17 +00:00
|
|
|
$(document).ready(function() {
|
2022-02-07 13:01:38 +00:00
|
|
|
var show_allocate_form = $("#allocateModal").data('show-action-form');
|
|
|
|
var show_datawipe_form = $("#datawipeModal").data('show-action-form');
|
2022-02-18 12:37:45 +00:00
|
|
|
var show_trade_form = $("#tradeLotModal").data('show-action-form');
|
2022-02-07 13:01:38 +00:00
|
|
|
if (show_allocate_form != "None") {
|
2022-02-01 12:40:06 +00:00
|
|
|
$("#allocateModal .btn-primary").show();
|
2022-02-07 13:01:38 +00:00
|
|
|
newAllocate(show_allocate_form);
|
|
|
|
} else if (show_datawipe_form != "None") {
|
|
|
|
$("#datawipeModal .btn-primary").show();
|
|
|
|
newDataWipe(show_datawipe_form);
|
2022-02-18 12:37:45 +00:00
|
|
|
} else if (show_trade_form != "None") {
|
|
|
|
$("#tradeLotModal .btn-primary").show();
|
|
|
|
newTrade(show_trade_form);
|
2022-02-01 12:40:06 +00:00
|
|
|
} else {
|
|
|
|
$(".deviceSelect").on("change", deviceSelect);
|
|
|
|
}
|
|
|
|
// $('#selectLot').selectpicker();
|
2021-12-30 11:41:37 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
function deviceSelect() {
|
2022-02-04 10:30:29 +00:00
|
|
|
var devices_count = $(".deviceSelect").filter(':checked').length;
|
2022-02-17 12:51:27 +00:00
|
|
|
get_device_list();
|
2022-02-03 12:58:54 +00:00
|
|
|
if (devices_count == 0) {
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#addingLotModal .pol").show();
|
2021-12-30 11:41:37 +00:00
|
|
|
$("#addingLotModal .btn-primary").hide();
|
2022-01-05 11:13:44 +00:00
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#removeLotModal .pol").show();
|
2022-01-03 10:32:12 +00:00
|
|
|
$("#removeLotModal .btn-primary").hide();
|
2022-02-03 12:58:54 +00:00
|
|
|
|
2022-02-04 12:22:47 +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
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#actionModal .pol").show();
|
2022-02-03 12:58:54 +00:00
|
|
|
$("#actionModal .btn-primary").hide();
|
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#allocateModal .pol").show();
|
2022-02-03 12:58:54 +00:00
|
|
|
$("#allocateModal .btn-primary").hide();
|
2022-02-07 13:01:38 +00:00
|
|
|
|
|
|
|
$("#datawipeModal .pol").show();
|
|
|
|
$("#datawipeModal .btn-primary").hide();
|
2021-12-30 11:41:37 +00:00
|
|
|
} else {
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#addingLotModal .pol").hide();
|
2021-12-30 11:41:37 +00:00
|
|
|
$("#addingLotModal .btn-primary").show();
|
2022-01-05 11:13:44 +00:00
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#removeLotModal .pol").hide();
|
2022-01-03 10:32:12 +00:00
|
|
|
$("#removeLotModal .btn-primary").show();
|
2022-01-05 11:13:44 +00:00
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#actionModal .pol").hide();
|
2022-01-05 11:13:44 +00:00
|
|
|
$("#actionModal .btn-primary").show();
|
2022-01-10 14:53:11 +00:00
|
|
|
|
2022-02-04 12:22:47 +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
|
|
|
|
2022-02-07 13:01:38 +00:00
|
|
|
$("#datawipeModal .pol").hide();
|
|
|
|
$("#datawipeModal .btn-primary").show();
|
|
|
|
|
2022-02-04 12:22:47 +00:00
|
|
|
$("#addingTagModal .pol").hide();
|
2022-02-18 10:18:54 +00:00
|
|
|
$("#addingTagModal .btn-primary").show();
|
2021-12-30 11:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
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')});
|
2022-03-02 12:08:23 +00:00
|
|
|
if (devices_id.length == 1) {
|
2022-01-25 13:39:15 +00:00
|
|
|
var url = "/inventory/tag/devices/"+devices_id[0]+"/del/";
|
|
|
|
window.location.href = url;
|
2022-03-02 12:08:23 +00:00
|
|
|
} else {
|
|
|
|
$("#unlinkTagAlertModal").click();
|
2022-01-25 13:39:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 10:18:54 +00:00
|
|
|
function addTag() {
|
2022-03-02 12:08:23 +00:00
|
|
|
var devices = $(".deviceSelect").filter(':checked');
|
|
|
|
var devices_id = $.map(devices, function(x) { return $(x).attr('data')});
|
|
|
|
if (devices_id.length == 1) {
|
|
|
|
$("#addingTagModal .pol").hide();
|
|
|
|
$("#addingTagModal .btn-primary").show();
|
|
|
|
} else {
|
|
|
|
$("#addingTagModal .pol").show();
|
|
|
|
$("#addingTagModal .btn-primary").hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#addTagAlertModal").click();
|
2022-02-18 10:18:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 12:22:47 +00:00
|
|
|
function newTrade(action) {
|
|
|
|
var title = "Trade "
|
2022-02-18 08:30:20 +00:00
|
|
|
var user_to = $("#user_to").data("email");
|
|
|
|
var user_from = $("#user_from").data("email");
|
|
|
|
if (action == 'user_from') {
|
2022-02-10 12:22:47 +00:00
|
|
|
title = 'Trade Incoming';
|
2022-02-18 08:30:20 +00:00
|
|
|
$("#user_to").attr('readonly', 'readonly');
|
|
|
|
$("#user_from").prop('readonly', false);
|
|
|
|
$("#user_from").val('');
|
|
|
|
$("#user_to").val(user_to);
|
|
|
|
} else if (action == 'user_to') {
|
2022-02-10 12:22:47 +00:00
|
|
|
title = 'Trade Outgoing';
|
2022-02-18 08:30:20 +00:00
|
|
|
$("#user_from").attr('readonly', 'readonly');
|
|
|
|
$("#user_to").prop('readonly', false);
|
|
|
|
$("#user_to").val('');
|
|
|
|
$("#user_from").val(user_from);
|
2022-02-10 12:22:47 +00:00
|
|
|
}
|
2022-02-18 12:37:45 +00:00
|
|
|
$("#tradeLotModal #title-action").html(title);
|
2022-02-10 12:22:47 +00:00
|
|
|
$("#activeTradeModal").click();
|
|
|
|
}
|
|
|
|
|
2022-01-03 12:40:30 +00:00
|
|
|
function newAction(action) {
|
2022-01-05 15:00:13 +00:00
|
|
|
$("#actionModal #type").val(action);
|
2022-02-03 10:44:51 +00:00
|
|
|
$("#actionModal #title-action").html(action);
|
2022-02-04 12:22:47 +00:00
|
|
|
deviceSelect();
|
2022-01-05 15:00:13 +00:00
|
|
|
$("#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);
|
2022-02-03 10:44:51 +00:00
|
|
|
$("#allocateModal #title-action").html(action);
|
2022-02-04 12:22:47 +00:00
|
|
|
deviceSelect();
|
2022-01-10 14:53:11 +00:00
|
|
|
$("#activeAllocateModal").click();
|
|
|
|
}
|
2022-02-04 10:30:29 +00:00
|
|
|
|
2022-02-07 13:01:38 +00:00
|
|
|
function newDataWipe(action) {
|
|
|
|
$("#datawipeModal #type").val(action);
|
|
|
|
$("#datawipeModal #title-action").html(action);
|
|
|
|
deviceSelect();
|
|
|
|
$("#activeDatawipeModal").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;
|
2022-02-07 13:01:38 +00:00
|
|
|
$("#datawipeModal .devices-count").html(devices_count);
|
2022-02-04 10:30:29 +00:00
|
|
|
$("#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);
|
|
|
|
}
|
2022-02-24 13:15:58 +00:00
|
|
|
|
|
|
|
function export_file(type_file) {
|
|
|
|
var devices = $(".deviceSelect").filter(':checked');
|
|
|
|
var devices_id = $.map(devices, function(x) { return $(x).attr('data-device-dhid')}).join(",");
|
|
|
|
if (devices_id){
|
|
|
|
var url = "/inventory/export/"+type_file+"/?ids="+devices_id;
|
|
|
|
window.location.href = url;
|
2022-02-28 10:19:22 +00:00
|
|
|
} else {
|
|
|
|
$("#exportAlertModal").click();
|
2022-02-24 13:15:58 +00:00
|
|
|
}
|
|
|
|
}
|