572 lines
18 KiB
JavaScript
572 lines
18 KiB
JavaScript
var x = 0, y = 0;
|
|
$(function () {
|
|
common.dateTimePickerByClass("datepicker", "HH:mm DD/MM/YYYY");
|
|
common.dateTimePickerDay("birthday");
|
|
$("tr").bind("click", function (event) {
|
|
x = event.pageX;
|
|
y = event.pageY;
|
|
});
|
|
$("input[name='BatchDelete']").change(function () {
|
|
if (this.checked) {
|
|
$("#delete-btn-group").removeClass("hidden");
|
|
} else {
|
|
$("tr").removeClass("delete-choose");
|
|
$("#delete-btn-group").addClass("hidden");
|
|
}
|
|
});
|
|
btnImage();
|
|
$("#Code").select2();
|
|
});
|
|
|
|
function _search(e) {
|
|
var location = $(e).attr("data-href");// + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
|
|
location = location + "?id=" + $("input[name='IDSearch']").val();
|
|
location = location + "&name=" + $("input[name='NameSearch']").val();
|
|
location = location + "&type=" + $("select[name='TypeSearch']").val();
|
|
location = location + "&gender=" + $("select[name='GenderSearch']").val();
|
|
window.location = location;
|
|
}
|
|
|
|
function _close() {
|
|
$("#form").addClass("hidden");
|
|
}
|
|
|
|
function _menu(e) {
|
|
var isDelete = $("input[name='BatchDelete']").is(':checked');
|
|
if (isDelete) {
|
|
if ($(e).hasClass("delete-choose"))
|
|
$(e).removeClass("delete-choose");
|
|
else
|
|
$(e).addClass("delete-choose");
|
|
$("#menu").addClass("hidden");
|
|
} else {
|
|
$("input[name='ListManagementID']").val($(e).attr("data-id"));
|
|
$("#menu").css({top: y, left: x}).removeClass("hidden");
|
|
}
|
|
}
|
|
|
|
function _closeMenu() {
|
|
$("#menu").addClass("hidden");
|
|
}
|
|
|
|
function _formModified(e) {
|
|
_closeMenu();
|
|
$("#form").removeClass("hidden");
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
id: $("input[name='ListManagementID']").val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
if (data.canUpload)
|
|
$("#upload-btn").removeClass("hidden");
|
|
else
|
|
$("#upload-btn").addClass("hidden");
|
|
$("select[name='Type']").val(data.type);
|
|
$("select[name='Code']").val(data.code);
|
|
$("input[name='Name']").val(data.name);
|
|
$("select[name='Gender']").val(data.gender);
|
|
$("input[name='Birthday']").val(data.birthday);
|
|
$("input[name='Telephone']").val(data.telephone);
|
|
$("input[name='Address']").val(data.address);
|
|
$("#FaceImage").attr("src", data.image);
|
|
$("#save-btn").attr("onclick", "_update(this);");
|
|
$("#save-btn").attr("data-href", $("input[name='update_url']").val());
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _update(e) {
|
|
var code = $("select[name='Code']").val();
|
|
if (code === "") {
|
|
alert("Hãy chọn đối tượng!");
|
|
return;
|
|
}
|
|
var name = $("input[name='Name']").val();
|
|
if (name === "") {
|
|
alert("Hãy nhập tên!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
code: code,
|
|
name: name,
|
|
type: $("select[name='Type']").val(),
|
|
gender: $("select[name='Gender']").val(),
|
|
birthday: $("input[name='Birthday']").val(),
|
|
telephone: $("input[name='Telephone']").val(),
|
|
address: $("input[name='Address']").val(),
|
|
id: $("input[name='ListManagementID']").val(),
|
|
image: $("input[name='AnhNhanVienUrl']").val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
if (data) {
|
|
alert("Cập nhật dữ liệu thành công!");
|
|
window.location.reload(true);
|
|
} else
|
|
alert("Mã đối tượng đã tồn tại!");
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _delete(e) {
|
|
if (confirm("Bạn có chắc chắn muốn xóa không?")) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
id: $("input[name='ListManagementID']").val()
|
|
},
|
|
success: function (data) {
|
|
window.location.reload(true);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function _deleteFeature(e) {
|
|
if (confirm("Bạn có chắc chắn muốn xóa ảnh này không?")) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
image: $(e).attr("data-img"),
|
|
id: $(e).attr("data-id")
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
$(e).closest("div").remove();
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function checkAll(status) {
|
|
if (status)
|
|
$("tr").addClass("delete-choose");
|
|
else
|
|
$("tr").removeClass("delete-choose");
|
|
}
|
|
|
|
function batchDelete(e) {
|
|
var check = $(".delete-choose");
|
|
if (check.length == 0) {
|
|
alert("Hãy chọn dữ liệu để xóa!");
|
|
return;
|
|
}
|
|
var lists = [];
|
|
$.each($(".delete-choose"), function () {
|
|
if ($(this).attr("data-id") !== "")
|
|
lists.push($(this).attr("data-id"));
|
|
});
|
|
if (confirm("Bạn có chắc chắn muốn xóa không?")) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
lists: lists
|
|
},
|
|
success: function (data) {
|
|
alert("Đã xóa dữ liệu!");
|
|
window.location.reload(true);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function _form() {
|
|
$("#form").removeClass("hidden");
|
|
$("#upload-btn").removeClass("hidden");
|
|
$("#FaceImage").attr("src", "/images/user2-160x160.jpg");
|
|
$("#save-btn").attr("onclick", "_create(this);");
|
|
$("#save-btn").attr("data-href", $("input[name='create_url']").val());
|
|
$("input[name='Code']").val($("input[name='isAuto']").val());
|
|
$("input[name='Name']").val("");
|
|
$("input[name='Birthday']").val("");
|
|
$("input[name='Telephone']").val("");
|
|
$("input[name='Address']").val("");
|
|
}
|
|
|
|
function btnImage() {
|
|
var fData = {
|
|
UploadImage: true
|
|
};
|
|
fData[common.csrfParam] = common.csrf;
|
|
new afuButton({
|
|
uploadURI: $("input[name='url_upload_staff_image']").val(),
|
|
formData: fData,
|
|
wrap: {
|
|
tagName: 'div',
|
|
classes: ''
|
|
},
|
|
fileExtension: '.png,.jpg,.jpeg,.gif',
|
|
fileSizeLimit: 1,
|
|
classes: 'btn btn-default btn-xs',
|
|
fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh',
|
|
onUploaded: function (data) {
|
|
var res = JSON.parse(data);
|
|
if (res.status) {
|
|
$("#FaceImage").attr("src", "/" + res.dataPath + res.url);
|
|
$("input[name='AnhNhanVienUrl']").val(res.url);
|
|
common.uploadBlock(false);
|
|
} else {
|
|
alert("Hình ảnh không nhận diện được khuôn mặt");
|
|
}
|
|
}
|
|
}).addInstance('AnhNhanVien');
|
|
}
|
|
|
|
function _create(e) {
|
|
var code = $("select[name='Code']").val();
|
|
if (code === "") {
|
|
alert("Hãy chọn đối tượng!");
|
|
return;
|
|
}
|
|
var name = $("input[name='Name']").val();
|
|
if (name === "") {
|
|
alert("Hãy nhập tên!");
|
|
return;
|
|
}
|
|
var image = $("input[name='AnhNhanVienUrl']").val();
|
|
if (image === "") {
|
|
alert("Hãy tải lên hình ảnh");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
code: code,
|
|
name: name,
|
|
type: $("select[name='Type']").val(),
|
|
gender: $("select[name='Gender']").val(),
|
|
birthday: $("input[name='Birthday']").val(),
|
|
telephone: $("input[name='Telephone']").val(),
|
|
address: $("input[name='Address']").val(),
|
|
image: image
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
if (data.status) {
|
|
alert("Cập nhật dữ liệu thành công!");
|
|
window.location.reload(true);
|
|
} else
|
|
alert("Mã đối tượng đã tồn tại!");
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _syncForm(e) {
|
|
var ip = $("input[name='SyncIP']").val();
|
|
if (ip === "") {
|
|
common.error("ip", "Hãy nhập địa chỉ ip thiết bị muốn đồng bộ");
|
|
return;
|
|
}
|
|
if (!common.validateIp(ip)) {
|
|
common.error("ip", "Sai định dạng ip");
|
|
return;
|
|
}
|
|
common.success("ip");
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
ip: ip
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpenFullScreen(data.form, data.title);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Không có kết nối tới thiết bị");
|
|
}
|
|
});
|
|
}
|
|
|
|
function choooseToSync(e) {
|
|
var stt = $(e).attr("data-stt");
|
|
if (stt === "false") {
|
|
$(e).addClass("success");
|
|
$(e).attr("data-stt", "true");
|
|
$("#totals-choose").html(parseInt($("#totals-choose").html()) + 1);
|
|
} else {
|
|
$(e).removeClass("success");
|
|
$(e).attr("data-stt", "false");
|
|
$("#totals-choose").html(parseInt($("#totals-choose").html()) - 1);
|
|
}
|
|
}
|
|
|
|
function checkAllSync(stt) {
|
|
if (stt) {
|
|
$("#sync-lists").find("tr").addClass("success").attr("data-stt", "true");
|
|
$("#totals-choose").html($("#sync-lists").find("tr").length);
|
|
} else {
|
|
$("#sync-lists").find("tr").removeClass("success").attr("data-stt", "false");
|
|
$("#totals-choose").html("0");
|
|
}
|
|
}
|
|
|
|
function checkAllNotInList() {
|
|
$("#sync-lists").find("tr").removeClass("success").attr("data-stt", "false");
|
|
$(".not-in-list").addClass("success").attr("data-stt", "true");
|
|
$("#totals-choose").html($(".not-in-list").length);
|
|
}
|
|
|
|
var progress = 0;
|
|
var totals = 0;
|
|
function _sync() {
|
|
var lists = [];
|
|
$.each($("#sync-lists").find(".success"), function () {
|
|
lists.push($(this).attr("data-id"));
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Không có dữ liệu đồng bộ!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$("#progress-totals").html(lists.length);
|
|
$("#progress-form").removeClass("hidden");
|
|
totals = lists.length;
|
|
syncFeatureFromDevice(lists[0], lists);
|
|
}
|
|
|
|
function syncFeatureFromDevice(id, fullData) {
|
|
$.ajax({
|
|
url: $("input[name='sync_feature_from_device_url']").val(),
|
|
type: 'POST',
|
|
data: {
|
|
id: id,
|
|
ip: $("input[name='SyncIP']").val(),
|
|
totals: totals
|
|
},
|
|
success: function (data) {
|
|
console.log(data, progress);
|
|
progress++;
|
|
$("#progress-current").html(parseInt($("#progress-current").html()) + 1);
|
|
var percent = parseInt(progress / totals * 100);
|
|
$("#progress").attr("aria-valuenow", percent);
|
|
$("#progress").attr("style", "width: " + percent + "%");
|
|
$("#progress").html(percent + "%");
|
|
if (percent >= 100) {
|
|
common.modalBlock(false);
|
|
if (totals > 10) {
|
|
updateFeature();
|
|
progress = 0;
|
|
} else {
|
|
window.location.reload(true);
|
|
}
|
|
} else {
|
|
syncFeatureFromDevice(fullData[progress], fullData);
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Mất kết nối tới thiết bị");
|
|
}
|
|
});
|
|
}
|
|
|
|
function _syncFromServerForm(e) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpenFullScreen(data.form, data.title);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _syncFromServer() {
|
|
var lists = [];
|
|
$.each($("#sync-lists").find(".success"), function () {
|
|
var id = $(this).attr("data-id");
|
|
lists.push(JSON.parse($("#full-data-" + id).html()));
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Không có dữ liệu đồng bộ!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$("#progress-totals").html(lists.length);
|
|
$("#progress-form").removeClass("hidden");
|
|
totals = lists.length;
|
|
syncFeature(lists[0], lists);
|
|
}
|
|
|
|
function syncFeature(id, fullData) {
|
|
$.ajax({
|
|
url: $("input[name='sync_feature_url']").val(),
|
|
type: 'POST',
|
|
data: {
|
|
id: id,
|
|
totals: totals
|
|
},
|
|
success: function (data) {
|
|
console.log(data, progress);
|
|
progress++;
|
|
$("#progress-current").html(parseInt($("#progress-current").html()) + 1);
|
|
var percent = parseInt(progress / totals * 100);
|
|
$("#progress").attr("aria-valuenow", percent);
|
|
$("#progress").attr("style", "width: " + percent + "%");
|
|
$("#progress").html(percent + "%");
|
|
if (percent >= 100) {
|
|
common.modalBlock(false);
|
|
if (totals > 10) {
|
|
updateFeature();
|
|
progress = 0;
|
|
} else {
|
|
window.location.reload(true);
|
|
}
|
|
} else {
|
|
syncFeature(fullData[progress], fullData);
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateFeature() {
|
|
$.ajax({
|
|
url: $("input[name='update_feature_url']").val(),
|
|
type: 'POST',
|
|
success: function (data) {
|
|
window.location.reload(true);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
}
|
|
});
|
|
}
|
|
|
|
function chooseStaff(e) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
code: $(e).val()
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
$("input[name='Name']").val(data.name);
|
|
$("select[name='Gender']").val(data.gender);
|
|
$("input[name='Birthday']").val(data.birthday);
|
|
$("input[name='Telephone']").val(data.telephone);
|
|
$("input[name='Address']").val(data.department);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
function _syncToServerForm(e) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpenFullScreen(data.form, data.title);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
var progressToServer = 0;
|
|
var totalsToServer = 0;
|
|
function _syncToServer() {
|
|
var lists = [];
|
|
$.each($("#sync-lists").find(".success"), function () {
|
|
lists.push($(this).attr("data-id"));
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Không có dữ liệu đồng bộ!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$("#progress-totals").html(lists.length);
|
|
$("#progress-form").removeClass("hidden");
|
|
totalsToServer = lists.length;
|
|
syncFeatureToServer(lists[0], lists);
|
|
}
|
|
var error = 0;
|
|
function syncFeatureToServer(id, fullData) {
|
|
$.ajax({
|
|
url: $("input[name='sync_feature_to_server_url']").val(),
|
|
type: 'POST',
|
|
data: {
|
|
id: id
|
|
},
|
|
success: function (data) {
|
|
if (data.status != 10000) {
|
|
error++;
|
|
console.log(error);
|
|
}
|
|
progressToServer++;
|
|
$("#progress-current").html(parseInt($("#progress-current").html()) + 1);
|
|
var percent = parseInt(progressToServer / totalsToServer * 100);
|
|
$("#progress").attr("aria-valuenow", percent);
|
|
$("#progress").attr("style", "width: " + percent + "%");
|
|
$("#progress").html(percent + "%");
|
|
if (percent >= 100) {
|
|
common.modalBlock(false);
|
|
setTimeout(function () {
|
|
alert("Đồng bộ dữ liệu hoàn thành");
|
|
window.location.reload(true);
|
|
}, 2000)
|
|
} else {
|
|
syncFeature(fullData[progressToServer], fullData);
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
}
|
|
});
|
|
} |