Server_AccessControl/web/js/card-register.js

142 lines
4.3 KiB
JavaScript

$(function () {
common.checkboxInit("staff");
$("#staff-list").on('pjax:success', function () {
common.checkboxInit("staff");
});
});
function validate() {
var error = 0;
var Staff = $("select[name='Staff']").val();
if (Staff === "0") {
common.error("staff", "Hãy chọn nhân viên");
error++;
} else {
common.success("staff");
}
var CardNumber = $("input[name='CardNumber']").val();
if (CardNumber === "") {
common.error("card_number", "Số thẻ không được để trống");
error++;
} else {
common.success("card_number");
}
return error == 0 ? true : false;
}
function save(e) {
if (validate()) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
Staff: $("select[name='Staff']").val(),
CardNumber: $("input[name='CardNumber']").val()
},
success: function (data) {
common.modalBlock(false);
if (data.status) {
notification.success("Đã lưu thông tin", 1000);
$.pjax.reload({container: '#staff-list'});
$("#staff-list").on('pjax:success', function () {
common.checkboxInit("staff");
});
$("#myModal").modal("hide");
} else {
if (data.type === "card") {
common.error("card_number", "Số thẻ đã tồn tại");
} else {
notification.danger("Có lỗi xảy ra, không lưu được dữ liệu!", 1000);
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
}
function _form(e) {
var lists = [];
$.each($("input[name='checkbox-staff']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng để thay đổi!");
return;
}
if (lists.length > 1) {
alert("Tác vụ này không thể lựa chọn nhiều hơn một đối tượng!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href') + "?id=" + lists[0],
type: 'POST',
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, false, data.title);
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function _delete(e) {
var lists = [];
$.each($("input[name='checkbox-staff']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng để xóa!");
return;
}
if (confirm("Bạn có chắc chắn muốn xóa các đối tượng đã lựa chọn không?")) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
lists: lists
},
success: function (data) {
common.modalBlock(false);
notification.danger("Đã xóa dữ liệu", 1000);
$.pjax.reload({container: '#staff-list'});
$("#staff-list").on('pjax:success', function () {
common.checkboxInit("staff");
});
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
}
function _export(e) {
window.location = $(e).attr("data-href");
}
function _logs(e) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, true, data.title);
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}