update Staff full CRUD
This commit is contained in:
BIN
web/data/excel/1602319719_staff_20201010154609.xlsx
Normal file
BIN
web/data/excel/1602319719_staff_20201010154609.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320488_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320488_staff_20201010155211.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320930_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320930_staff_20201010155211.xlsx
Normal file
Binary file not shown.
BIN
web/data/excel/1602320972_staff_20201010155211.xlsx
Normal file
BIN
web/data/excel/1602320972_staff_20201010155211.xlsx
Normal file
Binary file not shown.
@@ -224,16 +224,21 @@ common.success = function (id) {
|
||||
$("#" + id).addClass("has-success").removeClass("has-error");
|
||||
$("#" + id).find(".help-block").addClass("hidden");
|
||||
};
|
||||
common.form = function (e, obj) {
|
||||
common.form = function (e, obj, bigSize) {
|
||||
var size = bigSize | false;
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
common.modalOpen(data.form, false, data.title);
|
||||
common.modalOpen(data.form, size, data.title);
|
||||
if (obj === 'department')
|
||||
$('#Pid').select2();
|
||||
if (obj === 'staff') {
|
||||
$('#Department').select2();
|
||||
common.dateTimePickerByClass("DatePicker", "DD/MM/YYYY");
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
@@ -263,6 +268,22 @@ common.tree = function (e) {
|
||||
$("#sub-tree-" + $(e).attr("data")).removeClass("hidden");
|
||||
}
|
||||
};
|
||||
common.validatePhone = function (PhoneNumber) {
|
||||
var pattern = /^[0-9]{10,11}$/;
|
||||
if (pattern.test(PhoneNumber)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
common.validateEmail = function (Email) {
|
||||
var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
|
||||
if (pattern.test(Email)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* =========================
|
||||
|
||||
225
web/js/staff.js
Normal file
225
web/js/staff.js
Normal file
@@ -0,0 +1,225 @@
|
||||
$(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();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user