update mở tất cả + đóng tất cả cửa

This commit is contained in:
2020-11-11 13:39:46 +07:00
parent 096be1a116
commit c4e631befe
4 changed files with 119 additions and 5 deletions

View File

@@ -672,4 +672,71 @@ function openAllDoorOfDevice(data) {
common.ajaxError();
}
});
}
var progressCloseDoor = 0;
var totalsDoorToClose = 0;
function closeAllDoors(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();
totalsDoorToClose = data.lists.length;
for (var i = 0; i < data.lists.length; i++) {
closeAllDoorOfDevice(data.lists[i]);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function closeAllDoorOfDevice(data) {
$.ajax({
url: $("input[name='URL_close_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> Đóng <b>" + data.totals + "</b> cửa từ thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").prepend(html);
progressCloseDoor++;
var percent = parseInt(progressCloseDoor / totalsDoorToClose * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progressCloseDoor = 0;
$("#close-modal").attr("disabled", false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}