update mở tất cả cửa các thiết bị được chọn

This commit is contained in:
2020-11-05 13:57:18 +07:00
parent d420323d4b
commit 05545bafc9
4 changed files with 129 additions and 1 deletions

View File

@@ -605,4 +605,71 @@ function changeDuration(e) {
common.ajaxError();
}
});
}
var progressOpenDoor = 0;
var totalsDoor = 0;
function openAllDoors(e) {
var all = false;
if ($("#checkbox-device-all:checked").length > 0)
all = true;
var lists = [];
$.each($("input[name='checkbox-device']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
lists: lists,
all: all
},
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, false, data.title);
$("#close-modal").attr("disabled", true);
$("#modalHeader").find("button").remove();
totalsDoor = data.lists.length;
for (var i = 0; i < data.lists.length; i++) {
openAllDoorOfDevice(data.lists[i]);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function openAllDoorOfDevice(data) {
$.ajax({
url: $("input[name='URL_open_door']").val(),
type: 'POST',
data: {
data: data
},
success: function (data) {
console.log(data.response);
var html = "";
html = "<span class='text-green'><i class='fa fa-check'></i> Mở <b>" + data.totals + "</b> cửa từ thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").prepend(html);
progressOpenDoor++;
var percent = parseInt(progressOpenDoor / totalsDoor * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progressOpenDoor = 0;
$("#close-modal").attr("disabled", false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}