update phân quyền chi tiết
This commit is contained in:
131
web/js/auth_item.js
Normal file
131
web/js/auth_item.js
Normal file
@@ -0,0 +1,131 @@
|
||||
$(function () {
|
||||
common.checkboxInit("role");
|
||||
$("#role-list").on('pjax:success', function () {
|
||||
common.checkboxInit("role");
|
||||
});
|
||||
});
|
||||
|
||||
function validate() {
|
||||
var error = 0;
|
||||
var Name = $("input[name='Name']").val();
|
||||
if (Name === "") {
|
||||
common.error("name", "Tên quyền không được để trống");
|
||||
error++;
|
||||
} else {
|
||||
common.success("name");
|
||||
}
|
||||
|
||||
var lists = [];
|
||||
$.each($("input[name='checkbox-permission']:checked"), function () {
|
||||
lists.push($(this).val());
|
||||
});
|
||||
if (lists.length == 0) {
|
||||
alert("Hãy chọn các quyền truy cập!");
|
||||
}
|
||||
return error == 0 ? true : false;
|
||||
}
|
||||
|
||||
function save(e) {
|
||||
if (validate()) {
|
||||
var lists = [];
|
||||
$.each($("input[name='checkbox-permission']:checked"), function () {
|
||||
lists.push($(this).val());
|
||||
});
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
url: $(e).attr('data-href'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
Name: $("input[name='Name']").val(),
|
||||
Description: $("input[name='Description']").val(),
|
||||
lists: lists
|
||||
},
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
if (data.status) {
|
||||
notification.success("Đã lưu thông tin", 1000);
|
||||
$.pjax.reload({container: '#role-list'});
|
||||
$("#role-list").on('pjax:success', function () {
|
||||
common.checkboxInit("role");
|
||||
});
|
||||
$("#myModal").modal("hide");
|
||||
} else {
|
||||
notification.danger("Tên quyền đã tồn tại!", 1000);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function _form(e) {
|
||||
var lists = [];
|
||||
$.each($("input[name='checkbox-role']: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') + "?name=" + lists[0],
|
||||
type: 'POST',
|
||||
success: function (data) {
|
||||
common.modalBlock(false);
|
||||
common.modalOpen(data.form, false, data.title);
|
||||
var roles = JSON.parse($("#roleArray").html());
|
||||
for (var k in roles) {
|
||||
common.checkboxInit("permission-" + k);
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _delete(e) {
|
||||
var lists = [];
|
||||
$.each($("input[name='checkbox-role']: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: '#role-list'});
|
||||
$("#role-list").on('pjax:success', function () {
|
||||
common.checkboxInit("role");
|
||||
});
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
common.ajaxError();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -263,6 +263,12 @@ common.form = function (e, obj, bigSize) {
|
||||
if (obj === 'statistics') {
|
||||
common.dateTimePickerById("month", "MM/YYYY");
|
||||
}
|
||||
if (obj === "auth") {
|
||||
var roles = JSON.parse($("#roleArray").html());
|
||||
for (var k in roles) {
|
||||
common.checkboxInit("permission-" + k);
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
common.modalBlock(false);
|
||||
|
||||
@@ -13,10 +13,10 @@ user.save = function (e) {
|
||||
if (!Role) {
|
||||
error++;
|
||||
}
|
||||
var Email = user.checkEmail();
|
||||
if (!Email) {
|
||||
error++;
|
||||
}
|
||||
// var Email = user.checkEmail();
|
||||
// if (!Email) {
|
||||
// error++;
|
||||
// }
|
||||
if (error == 0) {
|
||||
common.modalBlock(true);
|
||||
$.ajax({
|
||||
@@ -27,7 +27,7 @@ user.save = function (e) {
|
||||
Username: Username,
|
||||
Role: Role,
|
||||
PhoneNumber: $("input[name='PhoneNumber']").val(),
|
||||
Email: Email,
|
||||
Email:$("input[name='Email']").val(),
|
||||
Password: $("input[name='Password']").val()
|
||||
},
|
||||
success: function (data) {
|
||||
|
||||
Reference in New Issue
Block a user