update data to device

This commit is contained in:
2020-10-14 17:21:26 +07:00
parent fd27169e00
commit 37ab48f055
7 changed files with 321 additions and 55 deletions

View File

@@ -243,4 +243,117 @@ function changeIP(e) {
}
});
}
}
}
var progress = 0;
var totals = 0;
function _sync(e) {
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
},
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, false, data.title);
$("#close-modal").attr("disabled", true);
$("#modalHeader").find("button").remove();
totals = data.lists.length * 2;
for (var i = 0; i < data.lists.length; i++) {
getDataSync(data.lists[i]);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function getDataSync(data) {
$.ajax({
url: $("input[name='get_data_sync_url']").val(),
type: 'POST',
data: {
data: data
},
success: function (data) {
var html = "";
html = "<span class='text-blue'><i class='fa fa-minus'></i> Bắt đầu đồng bộ dữ liệu tới thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").append(html);
syncSchedule(data.schedule, data.staffs, data.IP);
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}
function syncSchedule(schedule, staffs, ip) {
$.ajax({
url: $("input[name='sync_schedule_url']").val(),
type: 'POST',
data: {
data: schedule,
ip: ip
},
success: function (data) {
console.log("sync schedule: ", data.res);
var html = "";
html = "<span class='text-green'><i class='fa fa-check'></i> Đồng bộ lịch trình tới thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").append(html);
progress++;
var percent = parseInt(progress / totals * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progress = 0;
$("#close-modal").attr("disabled", false);
}
syncStaffs(staffs, ip);
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}
function syncStaffs(data, ip) {
$.ajax({
url: $("input[name='sync_staffs_url']").val(),
type: 'POST',
data: {
data: data,
ip: ip
},
success: function (data) {
console.log("sync user: ", data.resUser);
var html = "";
html = "<span class='text-green'><i class='fa fa-check'></i> Đồng bộ nhân viên tới thiết bị <b>" + data.IP + "</b>.</span><br>";
$("#logs-response").append(html);
progress++;
var percent = parseInt(progress / totals * 100);
$("#progress").attr("aria-valuenow", percent);
$("#progress").attr("style", "width: " + percent + "%");
$("#progress").html(percent + "%");
if (percent >= 100) {
progress = 0;
$("#close-modal").attr("disabled", false);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.ajaxError();
}
});
}

View File

@@ -222,4 +222,4 @@ function _logs(e) {
common.ajaxError();
}
});
}
}