Server_AccessControl/web/js/area.js

149 lines
4.5 KiB
JavaScript

$(function () {
common.checkboxInit("area");
$("#area-list").on('pjax:success', function () {
common.checkboxInit("area");
});
});
function validate() {
var error = 0;
var Name = $("input[name='Name']").val();
if (Name === "") {
common.error("name", "Tên khu vực không được để trống");
error++;
} else {
common.success("name");
}
var Code = $("input[name='Code']").val();
if (Code === "") {
common.error("code", "Mã khu vực không được để trống");
error++;
} else {
common.success("code");
}
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(),
Pid: $("select[name='Pid']").val(),
Description: $("textarea[name='Description']").val()
},
success: function (data) {
common.modalBlock(false);
if (data.status) {
notification.success("Đã lưu thông tin", 1000);
$.pjax.reload({container: '#area-list'});
$("#area-list").on('pjax:success', function () {
common.checkboxInit("area");
});
$("#myModal").modal("hide");
} else {
if (data.type === "code") {
common.error("code", "Mã khu vực đã 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-area']: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);
$('#Pid').select2();
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function _delete(e) {
var lists = [];
$.each($("input[name='checkbox-area']: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 (lists.length == 1 && lists[0] === "1") {
alert("Danh mục gốc không thể 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: '#area-list'});
$("#area-list").on('pjax:success', function () {
common.checkboxInit("area");
});
},
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();
}
});
}