336 lines
10 KiB
JavaScript
336 lines
10 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();
|
|
});
|
|
|
|
function _search(e) {
|
|
var location = $(e).attr("data-href") + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").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);
|
|
$("select[name='Type']").val(data.type);
|
|
$("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 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: {
|
|
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) {
|
|
alert("Cập nhật dữ liệu thành công!");
|
|
window.location.reload(true);
|
|
},
|
|
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());
|
|
}
|
|
|
|
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 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: {
|
|
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) {
|
|
alert("Cập nhật dữ liệu thành công!");
|
|
window.location.reload(true);
|
|
},
|
|
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 _sync(e) {
|
|
var lists = [];
|
|
$.each($("#sync-lists").find(".success"), function () {
|
|
lists.push($(this).attr("data-id"));
|
|
});
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr("data-href"),
|
|
type: 'POST',
|
|
data: {
|
|
lists: lists
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
alert("Đồng bộ dữ liệu thành công!");
|
|
window.location.reload(true);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
alert("Mất kết nối tới thiết bị");
|
|
}
|
|
});
|
|
} |