304 lines
10 KiB
JavaScript
304 lines
10 KiB
JavaScript
$(function () {
|
|
common.checkboxInit("staff");
|
|
btnUpload($("input[name='upload_file_url']").val(), "", '.xls,.xlsx', 3500);
|
|
$("#staff-list").on('pjax:success', function () {
|
|
common.checkboxInit("staff");
|
|
});
|
|
});
|
|
|
|
function validate() {
|
|
var error = 0;
|
|
var Name = $("input[name='Name']").val();
|
|
if (Name === "") {
|
|
common.error("name", "Tên nhân viên không được để trống");
|
|
error++;
|
|
} else {
|
|
common.success("name");
|
|
}
|
|
|
|
var Code = $("input[name='Code']").val();
|
|
if (Code === "") {
|
|
common.error("code", "Mã nhân viên không được để trống");
|
|
error++;
|
|
} else {
|
|
common.success("code");
|
|
}
|
|
|
|
var Email = $("input[name='Email']").val();
|
|
if (Email !== "") {
|
|
if (common.validateEmail(Email) == false) {
|
|
common.error("email", "Định dạng email không đúng");
|
|
error++;
|
|
} else {
|
|
common.success("email");
|
|
}
|
|
}
|
|
var Phone = $("input[name='Phone']").val();
|
|
if (Phone !== "") {
|
|
if (common.validatePhone(Phone) == false) {
|
|
common.error("phone", "Định dạng số điện thoại không đúng");
|
|
error++;
|
|
} else {
|
|
common.success("phone");
|
|
}
|
|
}
|
|
return error == 0 ? true : false;
|
|
}
|
|
|
|
function save(e) {
|
|
if (validate()) {
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
Name: $("input[name='Name']").val(),
|
|
Code: $("input[name='Code']").val(),
|
|
Gender: $("select[name='Gender']").val(),
|
|
BirthDay: $("input[name='BirthDay']").val(),
|
|
Email: $("input[name='Email']").val(),
|
|
Phone: $("input[name='Phone']").val(),
|
|
CardNumber: $("input[name='CardNumber']").val(),
|
|
Department: $("select[name='Department']").val(),
|
|
DateIn: $("input[name='DateIn']").val(),
|
|
Address: $("textarea[name='Address']").val(),
|
|
Image: $("input[name='AnhNhanVienUrl']").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 === "code") {
|
|
common.error("code", "Mã nhân viên đã tồn tại");
|
|
} 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, true, data.title);
|
|
$('#Department').select2();
|
|
common.dateTimePickerByClass("DatePicker", "DD/MM/YYYY");
|
|
btnImage();
|
|
$("#staff-img").on("click", function () {
|
|
$("#AnhNhanVien").trigger("click");
|
|
});
|
|
},
|
|
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 btnUpload(mUrl, className, extension, fileSize) {
|
|
var fData = {
|
|
UploadFile: true,
|
|
Name: className
|
|
};
|
|
fData[common.csrfParam] = common.csrf;
|
|
new afuButton({
|
|
uploadURI: mUrl,
|
|
formData: fData,
|
|
wrap: {
|
|
tagName: 'div',
|
|
classes: ''
|
|
},
|
|
fileExtension: extension,
|
|
fileSizeLimit: fileSize,
|
|
classes: 'btn btn-default file-paperclip-' + className,
|
|
fakeInputContent: '<span class=\'fa fa-upload\'></span> Nhập dữ liệu',
|
|
onUploaded: function (data) {
|
|
window.location.reload(true);
|
|
// data = JSON.parse(data);
|
|
// common.modalOpenFullScreen(data.form, data.title);
|
|
// common.uploadBlock(false);
|
|
// common.checkboxInit("staff-import");
|
|
}
|
|
}).addInstance('file' + className);
|
|
$(".file-paperclip-" + className).closest("div").attr("style", "display:inline-block;");
|
|
}
|
|
|
|
function _import(e) {
|
|
var lists = [];
|
|
$.each($("input[name='checkbox-staff-import']:checked"), function () {
|
|
lists.push($(this).val());
|
|
});
|
|
if (lists.length == 0) {
|
|
alert("Vui lòng lựa chọn đối tượng để nhập!");
|
|
return;
|
|
}
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
lists: lists
|
|
},
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
window.location.reload(true);
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
console.log(errorThrown);
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
}
|
|
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
|
|
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',
|
|
fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh',
|
|
onUploaded: function (data) {
|
|
var res = JSON.parse(data);
|
|
$("#staff-img").attr("src", "/" + res.dataPath + res.url);
|
|
$("input[name='AnhNhanVienUrl']").val(res.url);
|
|
common.uploadBlock(false);
|
|
}
|
|
}).addInstance('AnhNhanVien');
|
|
}
|
|
|
|
function formGetRTLog(e) {
|
|
var stt = $(e).attr("data-stt");
|
|
if (stt === "true") {
|
|
$("#device-lists").removeClass("hidden");
|
|
$(e).attr("data-stt", false);
|
|
} else {
|
|
$("#device-lists").addClass("hidden");
|
|
$(e).attr("data-stt", true);
|
|
}
|
|
}
|
|
|
|
function getRTLog(e) {
|
|
// common.modalBlock(true);
|
|
common.warning("device-lists", "<i class='fa fa-info-circle'></i> Chờ tín hiệu thẻ (tối đa 60 giây)");
|
|
$("#spin-icon").removeClass("hidden");
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
data: {
|
|
device: $("select[name='Device']").val()
|
|
},
|
|
success: function (data) {
|
|
// common.modalBlock(false);
|
|
if (data.ErrorCode === "1") {
|
|
$("input[name='CardNumber']").val(data.CardNumber);
|
|
$("#device-lists").addClass("hidden");
|
|
$("#btn-get-rtlog").attr("data-stt", true);
|
|
$("#device-lists").removeClass("has-error").removeClass("has-warning");
|
|
$("#device-lists").find(".help-block").addClass("hidden");
|
|
$("#spin-icon").addClass("hidden");
|
|
} else {
|
|
common.error("device-lists", "<i class='fa fa-info-circle'></i> Không nhận được tín hiệu thẻ hoặc không có kết nối tới service");
|
|
$("#spin-icon").addClass("hidden");
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
// common.modalBlock(false);
|
|
common.error("device-lists", "<i class='fa fa-info-circle'></i> Không nhận được tín hiệu thẻ hoặc không có kết nối tới service");
|
|
$("#spin-icon").addClass("hidden");
|
|
}
|
|
});
|
|
}
|