226 lines
7.1 KiB
JavaScript
226 lines
7.1 KiB
JavaScript
$(function () {
|
|
common.checkboxInit("staff");
|
|
btnUpload($("input[name='upload_file_url']").val(), "", '.xls,.xlsx', 3500);
|
|
});
|
|
|
|
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()
|
|
},
|
|
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");
|
|
},
|
|
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) {
|
|
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) {
|
|
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();
|
|
}
|
|
});
|
|
}
|