ManagePanel/static/js/permissions.js

72 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2017-12-16 13:54:00 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2017-12-16 13:38:20 -07:00
function addPermission(permcode, permdesc) {
permcode = permcode.trim().toUpperCase();
if (permcode == "") {
2017-12-21 00:56:11 -07:00
return false;
2017-05-28 23:24:56 -06:00
}
2017-12-16 13:38:20 -07:00
if ($("#permslist div[data-permcode=" + permcode + "]").length) {
2017-12-21 00:56:11 -07:00
$("#permslist .list-group-item[data-permcode=" + permcode + "]").animate({
backgroundColor: "#ff0000",
}, 500, "linear", function () {
$("#permslist .list-group-item[data-permcode=" + permcode + "]").animate({
backgroundColor: "#ffffff",
}, 500);
});
return false;
2017-12-16 13:38:20 -07:00
}
if (typeof permdesc == "undefined") {
2017-12-21 00:56:11 -07:00
$.post("action.php", {
action: 'autocomplete_permission',
q: $("#perms-box").val()
}, function (resp) {
if (resp.length === 0) {
return;
}
if (resp.length === 1) {
permdesc = resp[0].info;
} else {
for (var i = 0; i < resp.length; i++) {
if (resp[i].name == permcode) {
permdesc = resp[i].info;
break;
}
}
if (typeof permdesc == "undefined") {
return;
}
}
$('#permslist').append("<div class=\"list-group-item\" data-permcode=\"" + permcode + "\">" + permcode + "<div class=\"btn btn-danger btn-sm float-right rmperm\"><i class=\"fas fa-trash\"></i></div><input type=\"hidden\" name=\"permissions[]\" value=\"" + permcode + "\" /> <p class=\"small\">" + permdesc + "</p></div>");
2017-12-21 00:56:11 -07:00
$("#perms-box").val("");
}, "json");
2017-12-16 13:38:20 -07:00
} else {
$('#permslist').append("<div class=\"list-group-item\" data-permcode=\"" + permcode + "\">" + permcode + "<div class=\"btn btn-danger btn-sm float-right rmperm\"><i class=\"fas fa-trash\"></i></div><input type=\"hidden\" name=\"permissions[]\" value=\"" + permcode + "\" /> <p class=\"small\">" + permdesc + "</p></div>");
2017-12-21 00:56:11 -07:00
$("#perms-box").val("");
2017-12-16 13:38:20 -07:00
}
}
function removePermission(permcode) {
$("#permslist div[data-permcode=" + permcode + "]").remove();
}
$("#user-box").on("change", function (e) {
$("#selectuserbtn").click();
2017-12-16 13:38:20 -07:00
});
$("#selectuserbtn").click(function () {
document.location.href = "app.php?page=permissions&user=" + $("#user-box").val();
});
$("#perms-box").on("click", function (event) {
$("#addpermbtn").click();
2017-12-16 13:38:20 -07:00
});
$("#addpermbtn").click(function () {
addPermission($("#perms-box").val());
});
$('#permslist').on("click", ".rmperm", function () {
removePermission($(this).parent().data("permcode"));
2017-05-28 23:24:56 -06:00
});