diff options
Diffstat (limited to 'modules-available/permissionmanager')
14 files changed, 287 insertions, 157 deletions
diff --git a/modules-available/permissionmanager/clientscript.js b/modules-available/permissionmanager/clientscript.js index 65065e6e..4770fa6a 100644 --- a/modules-available/permissionmanager/clientscript.js +++ b/modules-available/permissionmanager/clientscript.js @@ -1,5 +1,5 @@ document.addEventListener("DOMContentLoaded", function() { - var selectize = $('#select-role'); + var selectize = $("#select-role"); if (selectize.length) { selectize = selectize.selectize({ allowEmptyOption: false, @@ -13,10 +13,10 @@ document.addEventListener("DOMContentLoaded", function() { // If Site gets refreshed, all data-selectizeCounts will be reset to 0, so delete the filters from the selectize selectize.clear(); - selectize.on('item_add', function (value, $item) { + selectize.on("item_add", function (value, $item) { // When first item gets added the filter isn't empty anymore, so hide all rows if (selectize.items.length === 1) { - $('.dataTable tbody').find('tr').hide(); + $(".dataTable tbody").find("tr").hide(); } // Find all rows which shall be shown and increase their counter by 1 $(".roleid-" + value).closest("tr").each(function () { @@ -25,10 +25,10 @@ document.addEventListener("DOMContentLoaded", function() { }); }); - selectize.on('item_remove', function (value, $item) { + selectize.on("item_remove", function (value, $item) { // When no items in the filter, show all rows again if (selectize.items.length === 0) { - $('.dataTable tbody').find('tr').show(); + $(".dataTable tbody").find("tr").show(); } else { // Find all rows which have the delete role, decrease their counter by 1 $(".roleid-" + value).closest("tr").each(function () { @@ -42,9 +42,9 @@ document.addEventListener("DOMContentLoaded", function() { }); } - $("tr").on('click', function (e) { - if (e.target.type !== "checkbox") { - $(this).find("input:checkbox").trigger("click"); + $("tr").on("click", function(e) { + if (e.target.type !== "checkbox" && e.target.tagName !== "A") { + $(this).find("input[type=checkbox]").trigger("click"); } }); diff --git a/modules-available/permissionmanager/inc/getpermissiondata.inc.php b/modules-available/permissionmanager/inc/getpermissiondata.inc.php index 13c7ca89..982fa0b7 100644 --- a/modules-available/permissionmanager/inc/getpermissiondata.inc.php +++ b/modules-available/permissionmanager/inc/getpermissiondata.inc.php @@ -2,9 +2,17 @@ class GetPermissionData { - // get UserIDs, User Login Names, User Roles + /** + * Get data for all users. + * + * @return array array of users (each with userid, username and roles (each with roleid and rolename)) + */ public static function getUserData() { - $res = self::queryUserData(); + $res = Database::simpleQuery("SELECT user.userid AS userid, user.login AS login, role.rolename AS rolename, role.roleid AS roleid + FROM user + LEFT JOIN user_x_role ON user.userid = user_x_role.userid + LEFT JOIN role ON user_x_role.roleid = role.roleid + "); $userdata= array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { $userdata[$row['userid'].' '.$row['login']][] = array( @@ -24,7 +32,11 @@ class GetPermissionData { return $data; } - // get LocationIDs, Location Names, Roles of each Location + /** + * Get data for all locations. + * + * @return array array of locations (each including the roles that have permissions for them) + */ public static function getLocationData() { $res = Database::simpleQuery("SELECT role.roleid as roleid, rolename, GROUP_CONCAT(COALESCE(locationid, 0)) AS locationids FROM role INNER JOIN role_x_location ON role.roleid = role_x_location.roleid GROUP BY roleid ORDER BY rolename ASC"); @@ -46,7 +58,11 @@ class GetPermissionData { return array_values($locations); } - // get all roles from database (id and name) + /** + * Get all roles. + * + * @return array array roles (each with roleid and rolename) + */ public static function getRoles() { $res = Database::simpleQuery("SELECT roleid, rolename FROM role ORDER BY rolename ASC"); $data = array(); @@ -59,6 +75,12 @@ class GetPermissionData { return $data; } + /** + * Get permissions and locations for a given role. + * + * @param string $roleid id of the role + * @return array array containing an array of permissions and an array of locations + */ public static function getRoleData($roleid) { $query = "SELECT roleid, rolename FROM role WHERE roleid = :roleid"; $data = Database::queryFirst($query, array("roleid" => $roleid)); @@ -77,14 +99,4 @@ class GetPermissionData { return $data; } - // UserID, User Login Name, Roles of each User - private static function queryUserData() { - $res = Database::simpleQuery("SELECT user.userid AS userid, user.login AS login, role.rolename AS rolename, role.roleid AS roleid - FROM user - LEFT JOIN user_x_role ON user.userid = user_x_role.userid - LEFT JOIN role ON user_x_role.roleid = role.roleid - "); - return $res; - } - }
\ No newline at end of file diff --git a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php index f144b35e..ffe5fac0 100644 --- a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php +++ b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php @@ -2,7 +2,12 @@ class PermissionDbUpdate { - // insert new user_x_role to database. "ignore" to ignore duplicate entry try + /** + * Insert all user/role combinations into the user_x_role table. + * + * @param array $users userids + * @param array $roles roleids + */ public static function addRoleToUser($users, $roles) { $query = "INSERT IGNORE INTO user_x_role (userid, roleid) VALUES (:userid, :roleid)"; foreach($users AS $userid) { @@ -12,24 +17,34 @@ class PermissionDbUpdate { } } - // remove user_x_role entry from database + /** + * Remove all user/role combinations from the user_x_role table. + * + * @param array $users userids + * @param array $roles roleids + */ public static function removeRoleFromUser($users, $roles) { $query = "DELETE FROM user_x_role WHERE userid IN (:users) AND roleid IN (:roles)"; Database::exec($query, array("users" => $users, "roles" => $roles)); } - // delete role, delete user_x_role relationships, delete role_x_location relationships, delete role_x_permission relationships + /** + * Delete role from the role table. + * + * @param string $roleid roleid + */ public static function deleteRole($roleid) { - $query = "DELETE FROM role WHERE roleid = :roleid"; - Database::exec($query, array("roleid" => $roleid)); - $query = "DELETE FROM user_x_role WHERE roleid = :roleid"; - Database::exec($query, array("roleid" => $roleid)); - $query = "DELETE FROM role_x_location WHERE roleid = :roleid"; - Database::exec($query, array("roleid" => $roleid)); - $query = "DELETE FROM role_x_permission WHERE roleid = :roleid"; - Database::exec($query, array("roleid" => $roleid)); + Database::exec("DELETE FROM role WHERE roleid = :roleid", array("roleid" => $roleid)); } + /** + * Save changes to a role or create a new one. + * + * @param string $rolename rolename + * @param array $locations array of locations + * @param array $permissions array of permissions + * @param string|null $roleid roleid or null if the role does not exist yet + */ public static function saveRole($rolename, $locations, $permissions, $roleid = NULL) { if ($roleid) { Database::exec("UPDATE role SET rolename = :rolename WHERE roleid = :roleid", diff --git a/modules-available/permissionmanager/inc/permissionutil.inc.php b/modules-available/permissionmanager/inc/permissionutil.inc.php index 6fc33ad1..5ff41046 100644 --- a/modules-available/permissionmanager/inc/permissionutil.inc.php +++ b/modules-available/permissionmanager/inc/permissionutil.inc.php @@ -2,6 +2,14 @@ class PermissionUtil { + /** + * Check if the user has the given permission (for the given location). + * + * @param string $userid userid to check + * @param string $permissionid permissionid to check + * @param int|null $locationid locationid to check or null if the location should be disregarded + * @return bool true if user has permission, false if not + */ public static function userHasPermission($userid, $permissionid, $locationid) { $locations = array(); if (!is_null($locationid)) { @@ -10,23 +18,29 @@ class PermissionUtil else $locations[] = 0; } - $res = Database::simpleQuery("SELECT role_x_permission.permissionid as 'permissionid', - role_x_location.locationid as 'locationid' - FROM user_x_role + $res = Database::simpleQuery("SELECT permissionid, locationid FROM user_x_role INNER JOIN role_x_permission ON user_x_role.roleid = role_x_permission.roleid - LEFT JOIN role_x_location ON role_x_permission.roleid = role_x_location.roleid + LEFT JOIN (SELECT roleid, COALESCE(locationid, 0) AS locationid FROM role_x_location) t1 + ON role_x_permission.roleid = t1.roleid WHERE user_x_role.userid = :userid", array("userid" => $userid)); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $userPermission = trim($row["permissionid"], "*"); - if (substr($permissionid, 0, strlen($userPermission)) === $userPermission - && (is_null($locationid) || in_array($row["locationid"], $locations))) { + $userPermission = rtrim($row["permissionid"], ".*")."."; + if ((is_null($locationid) || (!is_null($row["locationid"]) && in_array($row["locationid"], $locations))) && + (substr($permissionid.".", 0, strlen($userPermission)) === $userPermission || $userPermission === ".")) { return true; } } return false; } + /** + * Get all locations where the user has the given permission. + * + * @param string $userid userid to check + * @param string $permissionid permissionid to check + * @return array array of locationids where the user has the given permission + */ public static function getAllowedLocations($userid, $permissionid) { $res = Database::simpleQuery("SELECT permissionid, COALESCE(locationid, 0) AS locationid FROM user_x_role @@ -36,8 +50,8 @@ class PermissionUtil $allowedLocations = array(); while ($row = $res->fetch(PDO::FETCH_ASSOC)) { - $userPermission = trim($row["permissionid"], "*"); - if (!is_null($row["locationid"]) && substr($permissionid, 0, strlen($userPermission)) === $userPermission) { + $userPermission = rtrim($row["permissionid"], ".*")."."; + if (substr($permissionid.".", 0, strlen($userPermission)) === $userPermission || $userPermission === ".") { $allowedLocations[$row["locationid"]] = 1; } } @@ -45,12 +59,20 @@ class PermissionUtil $locations = Location::getTree(); if (in_array("0", $allowedLocations)) { $allowedLocations = array_map("intval", Location::extractIds($locations)); + $allowedLocations[] = 0; } else { $allowedLocations = self::getSublocations($locations, $allowedLocations); } return $allowedLocations; } + /** + * Extend an array of locations by adding all sublocations. + * + * @param array $tree tree of all locations (structured like Location::getTree()) + * @param array $locations the array of locationids to extend + * @return array extended array of locationids + */ public static function getSublocations($tree, $locations) { $result = array_flip($locations); foreach ($tree as $location) { @@ -65,6 +87,11 @@ class PermissionUtil return array_keys($result); } + /** + * Get all permissions of all active modules that have permissions in their permissions/permissions.json file. + * + * @return array permission tree as a multidimensional array + */ public static function getPermissions() { $permissions = array(); @@ -75,7 +102,7 @@ class PermissionUtil preg_match('#^modules/([^/]+)/#', $file, $out); foreach( $data as $p ) { $description = Dictionary::translateFileModule($out[1], "permissions", $p); - $permissions = self::putInPermissionTree($out[1].".".$p, $description, $permissions); + self::putInPermissionTree($out[1].".".$p, $description, $permissions); } } ksort($permissions); @@ -89,10 +116,16 @@ class PermissionUtil return $permissions; } - private static function putInPermissionTree($permission, $description, $tree) + /** + * Place a permission into the given permission tree. + * + * @param string $permission the permission to place in the tree + * @param string $description the description of the permission + * @param array $tree the permission tree to modify + */ + private static function putInPermissionTree($permission, $description, &$tree) { $subPermissions = explode('.', $permission); - $original =& $tree; foreach ($subPermissions as $subPermission) { if ($subPermission) { if (!array_key_exists($subPermission, $tree)) { @@ -101,6 +134,6 @@ class PermissionUtil $tree =& $tree[$subPermission]; } } - return $original; + $tree = $description; } }
\ No newline at end of file diff --git a/modules-available/permissionmanager/lang/de/template-tags.json b/modules-available/permissionmanager/lang/de/template-tags.json index 23b2dc68..71bd4075 100644 --- a/modules-available/permissionmanager/lang/de/template-tags.json +++ b/modules-available/permissionmanager/lang/de/template-tags.json @@ -1,23 +1,22 @@ { - "lang_Roles": "Rollen", - "lang_Users": "Nutzer", - "lang_Locations": "Räume", - "lang_addRole": "Rolle zuweisen", - "lang_removeRole": "Rolle entfernen", + "lang_roles": "Rollen", + "lang_users": "Nutzer", + "lang_locations": "Räume", + "lang_addRole": "Rollen erteilen", + "lang_removeRole": "Rollen entziehen", "lang_newRole": "Rolle anlegen", - "lang_Selected": "Ausgewählt", - "lang_Edit": "Bearbeiten", - "lang_Remove": "Entfernen", - "lang_Delete": "Löschen", + "lang_selected": "Ausgewählt", + "lang_edit": "Bearbeiten", + "lang_delete": "Löschen", "lang_removeCheck": "Sind Sie sich sicher, dass Sie diese Rolle entfernen wollen?", "lang_deleteCheck": "Sind Sie sich sicher, dass Sie diese Rolle löschen wollen?", "lang_emptyNameWarning": "Der Name der Rolle darf nicht leer sein!", - "lang_Name": "Name", - "lang_Cancel": "Abbrechen", - "lang_Save": "Speichern", + "lang_name": "Name", + "lang_cancel": "Abbrechen", + "lang_save": "Speichern", "lang_all": "alle", "lang_selected": "ausgewählte", - "lang_Permissions": "Rechte", + "lang_permissions": "Rechte", "lang_selectizePlaceholder": "Nach Rollen filtern...", "lang_searchPlaceholder": "Nach Rollen suchen...", "lang_moduleName": "Rechtemanager", diff --git a/modules-available/permissionmanager/lang/en/template-tags.json b/modules-available/permissionmanager/lang/en/template-tags.json index 01056632..2d31b294 100644 --- a/modules-available/permissionmanager/lang/en/template-tags.json +++ b/modules-available/permissionmanager/lang/en/template-tags.json @@ -1,23 +1,22 @@ { - "lang_Roles": "Roles", - "lang_Users": "Users", - "lang_Locations": "Locations", - "lang_addRole": "Add Role", - "lang_removeRole": "Remove Role", + "lang_roles": "Roles", + "lang_users": "Users", + "lang_locations": "Locations", + "lang_addRole": "Grant Roles", + "lang_removeRole": "Revoke Roles", "lang_newRole": "New Role", - "lang_Selected": "Selected", - "lang_Edit": "Edit", - "lang_Remove": "Remove", - "lang_Delete": "Delete", + "lang_selected": "Selected", + "lang_edit": "Edit", + "lang_delete": "Delete", "lang_removeCheck": "Are you sure you want to remove this role?", "lang_deleteCheck": "Are you sure you want to delete this role?", "lang_emptyNameWarning": "Role name can not be empty!", - "lang_Name": "Name", - "lang_Cancel": "Cancel", - "lang_Save": "Save", + "lang_name": "Name", + "lang_cancel": "Cancel", + "lang_save": "Save", "lang_all": "all", "lang_selected": "selected", - "lang_Permissions": "Permissions", + "lang_permissions": "Permissions", "lang_selectizePlaceholder": "Filter for roles...", "lang_searchPlaceholder": "Search for roles...", "lang_moduleName": "Permission Manager", diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php index 9aba80b3..13d81c6a 100644 --- a/modules-available/permissionmanager/page.inc.php +++ b/modules-available/permissionmanager/page.inc.php @@ -64,14 +64,14 @@ class Page_PermissionManager extends Page Render::addTemplate('locationstable', $data); } } elseif ($show === "roleEditor") { - $data = array(); + $data = array("cancelShow" => Request::get("cancel", "roles")); $selectedPermissions = array(); $selectedLocations = array(); - $roleID = Request::get("roleid", false); - if ($roleID) { - $roleData = GetPermissionData::getRoleData($roleID); - $data["roleid"] = $roleID; + $roleid = Request::get("roleid", false); + if ($roleid) { + $roleData = GetPermissionData::getRoleData($roleid); + $data["roleid"] = $roleid; $data["rolename"] = $roleData["rolename"]; $selectedPermissions = $roleData["permissions"]; $selectedLocations = $roleData["locations"]; @@ -85,12 +85,21 @@ class Page_PermissionManager extends Page } } - private static function generatePermissionHTML($subPermissions, $selectedPermissions = array(), $selectAll = false, $permString = "") + /** + * Recursively generate HTML code for the permission selection tree. + * + * @param array $permissions the permission tree + * @param array $selectedPermissions permissions that should be preselected + * @param array $selectAll true if all pemrissions should be preselected, false if only those in $selectedPermissions + * @param array $permString the prefix permission string with which all permissions in the permission tree should start + * @return string generated html code + */ + private static function generatePermissionHTML($permissions, $selectedPermissions = array(), $selectAll = false, $permString = "") { $res = ""; $toplevel = $permString == ""; if ($toplevel && in_array("*", $selectedPermissions)) $selectAll = true; - foreach ($subPermissions as $k => $v) { + foreach ($permissions as $k => $v) { $leaf = !is_array($v); $nextPermString = $permString ? $permString.".".$k : $k; $id = $leaf ? $nextPermString : $nextPermString.".*"; @@ -107,7 +116,7 @@ class Page_PermissionManager extends Page if ($toplevel) { $res = Render::parse("treepanel", array("id" => "*", - "name" => Dictionary::translateFile("template-tags", "lang_Permissions"), + "name" => Dictionary::translateFile("template-tags", "lang_permissions"), "checkboxname" => "permissions", "selected" => $selectAll, "HTML" => $res)); @@ -115,6 +124,15 @@ class Page_PermissionManager extends Page return $res; } + /** + * Recursively generate HTML code for the location selection tree. + * + * @param array $locations the location tree + * @param array $selectedLocations locations that should be preselected + * @param array $selectAll true if all locations should be preselected, false if only those in $selectedLocations + * @param array $toplevel true if the location tree are the children of the root location, false if not + * @return string generated html code + */ private static function generateLocationHTML($locations, $selectedLocations = array(), $selectAll = false, $toplevel = true) { $res = ""; @@ -133,7 +151,7 @@ class Page_PermissionManager extends Page if ($toplevel) { $res = Render::parse("treepanel", array("id" => 0, - "name" => Dictionary::translateFile("template-tags", "lang_Locations"), + "name" => Dictionary::translateFile("template-tags", "lang_locations"), "checkboxname" => "locations", "selected" => $selectAll, "HTML" => $res)); @@ -141,6 +159,12 @@ class Page_PermissionManager extends Page return $res; } + /** + * Remove locations that are already covered by parent locations from the array. + * + * @param array $locations the locationid array + * @return array the locationid array without redundant locationids + */ private static function processLocations($locations) { if (in_array(0, $locations)) return array(NULL); @@ -158,6 +182,12 @@ class Page_PermissionManager extends Page return $result; } + /** + * Remove permissions that are already covered by parent permissions from the array. + * + * @param array $permissions the permissionid array + * @return array the permissionid array without redundant permissionids + */ private static function processPermissions($permissions) { if (in_array("*", $permissions)) return array("*"); @@ -171,6 +201,12 @@ class Page_PermissionManager extends Page return self::extractPermissions($result); } + /** + * Convert a multidimensional array of permissions to a flat array of permissions. + * + * @param array $permissions multidimensional array of permissionids + * @return array flat array of permissionids + */ private static function extractPermissions($permissions) { $result = array(); diff --git a/modules-available/permissionmanager/templates/_page.html b/modules-available/permissionmanager/templates/_page.html index 405462f7..4140ce78 100644 --- a/modules-available/permissionmanager/templates/_page.html +++ b/modules-available/permissionmanager/templates/_page.html @@ -8,17 +8,17 @@ <div class="btn-group"> <button class="btn btn-default {{rolesButtonClass}}" type="submit" name="show" value="roles"> <span class="glyphicon glyphicon-education"></span> - {{lang_Roles}} + {{lang_roles}} </button> <button class="btn btn-default {{usersButtonClass}}" type="submit" name="show" value="users"> <span class="glyphicon glyphicon-user"></span> - {{lang_Users}} + {{lang_users}} </button> <button class="btn btn-default {{locationsButtonClass}}" type="submit" name="show" value="locations"> <span class="glyphicon glyphicon-home"></span> - {{lang_Locations}} + {{lang_locations}} </button> </div> </form> diff --git a/modules-available/permissionmanager/templates/locationstable.html b/modules-available/permissionmanager/templates/locationstable.html index dcfefa94..153258fe 100644 --- a/modules-available/permissionmanager/templates/locationstable.html +++ b/modules-available/permissionmanager/templates/locationstable.html @@ -15,8 +15,8 @@ <table id="locationsTable" class="table table-condensed table-hover stupidtable dataTable"> <thead> <tr> - <th data-sort="string">{{lang_Locations}}</th> - <th>{{lang_Roles}}</th> + <th data-sort="string">{{lang_locations}}</th> + <th>{{lang_roles}}</th> </tr> </thead> @@ -26,7 +26,7 @@ <td>{{locationpad}} {{locationname}}</td> <td> {{#roles}} - <span class="label label-default customSpanMargin roleid-{{roleid}}">{{rolename}}</span> + <a href="?do=permissionmanager&show=roleEditor&cancel=locations&roleid={{roleid}}" class="label label-default customSpanMargin roleid-{{roleid}}">{{rolename}}</a> {{/roles}} </td> </tr> diff --git a/modules-available/permissionmanager/templates/roleeditor.html b/modules-available/permissionmanager/templates/roleeditor.html index b07e2112..871fd0cc 100644 --- a/modules-available/permissionmanager/templates/roleeditor.html +++ b/modules-available/permissionmanager/templates/roleeditor.html @@ -7,15 +7,15 @@ <div class="row"> <div class="col-md-12" style="margin-bottom: 20px;"> <ul class="nav nav-tabs text-center" role="tablist"> - <li role="presentation" class="active"><a href="#permissions" role="tab" data-toggle="tab">{{lang_Permissions}}</a></li> - <li role="presentation"><a href="#locations" role="tab" data-toggle="tab">{{lang_Locations}}</a></li> + <li role="presentation" class="active"><a href="#permissions" role="tab" data-toggle="tab">{{lang_permissions}}</a></li> + <li role="presentation"><a href="#locations" role="tab" data-toggle="tab">{{lang_locations}}</a></li> <li style="float: none; display: inline-block"> - <b>{{lang_Name}}:</b> - <input name="rolename" value="{{rolename}}" type="text" id="rolename" class="form-control"> + <label for="rolename">{{lang_name}}:</label> + <input id="rolename" name="rolename" value="{{rolename}}" type="text" class="form-control"> </li> <li style="float: right;"> - <button type="button" id="cancelButton" class="btn btn-default">{{lang_Cancel}}</button> - <button type="submit" id="saveButton" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> {{lang_Save}}</button> + <span><a href="?do=permissionmanager&show={{cancelShow}}" id="cancelButton" class="btn btn-default">{{lang_cancel}}</a></span> + <button type="submit" id="saveButton" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> {{lang_save}}</button> </li> </ul> </div> @@ -56,15 +56,12 @@ } } }); - - $("#cancelButton").click(function () { - window.location.replace("?do=permissionmanager&show=roles"); - }); $('form').submit(function () { - var name = $.trim($('#rolename').val()); - if (name === '') { - $("#rolename").addClass("missingInput"); + var input = $("#rolename"); + var name = $.trim(input.val()); + if (!name) { + input.addClass("missingInput"); return false; } }); diff --git a/modules-available/permissionmanager/templates/rolestable.html b/modules-available/permissionmanager/templates/rolestable.html index 992feca1..b121a9e0 100644 --- a/modules-available/permissionmanager/templates/rolestable.html +++ b/modules-available/permissionmanager/templates/rolestable.html @@ -8,27 +8,27 @@ <input type="text" class="form-control" id="roleNameSearchField" onkeyup="searchFieldFunction()" placeholder="{{lang_searchPlaceholder}}"> </div> <div class="col-md-4 text-right"> - <button class="btn btn-success" type="button" onclick="openRoleEditor()"><span class="glyphicon glyphicon-plus"></span> {{lang_newRole}}</button> + <a href="?do=permissionmanager&show=roleEditor" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span> {{lang_newRole}}</a> </div> </div> <div class="row"> <div class="col-md-12"> - <table id="rolesTable" class="table table-condensed table-hover stupidtable"> + <table class="table table-condensed table-hover stupidtable"> <thead> <tr> - <th data-sort="string">{{lang_Roles}}</th> - <th class="text-center">{{lang_Edit}}</th> - <th class="text-center">{{lang_Delete}}</th> + <th data-sort="string">{{lang_roles}}</th> + <th class="text-center">{{lang_edit}}</th> + <th class="text-center">{{lang_delete}}</th> </tr> </thead> <tbody> {{#roles}} - <tr class="rolesRow"> - <td class="rolesData">{{rolename}}</td> + <tr> + <td class="rolename">{{rolename}}</td> <td class="text-center"> - <a class="btn btn-xs btn-info" href="?do=permissionmanager&show=roleEditor&roleid={{roleid}}"><span class="glyphicon glyphicon-edit"></span></a> + <a class="btn btn-xs btn-primary" href="?do=permissionmanager&show=roleEditor&roleid={{roleid}}"><span class="glyphicon glyphicon-edit"></span></a> </td> <td class="text-center"> <a class="btn btn-xs btn-danger" href="#deleteModal" data-toggle="modal" data-target="#deleteModal" onclick="deleteRole('{{roleid}}')"><span class="glyphicon glyphicon-trash"></span></a> @@ -47,7 +47,7 @@ <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="myModalLabel">{{lang_Delete}}</h4> + <h4 class="modal-title" id="myModalLabel">{{lang_delete}}</h4> </div> <div class="modal-body"> {{lang_deleteCheck}} @@ -55,7 +55,7 @@ <div class="modal-footer"> <input type="hidden" id="deleteId" name="deleteId" value=""/> <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> - <button type="submit" name="action" value="deleteRole" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> {{lang_Delete}}</button> + <button type="submit" name="action" value="deleteRole" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> {{lang_delete}}</button> </div> </div> </div> @@ -64,30 +64,18 @@ </form> <script> - function openRoleEditor() { - window.location.href = "?do=permissionmanager&show=roleEditor" - } - function deleteRole($roleid) { $(".modal-footer #deleteId").val($roleid); } function searchFieldFunction() { - // Declare variables - var input, filter, table, trs, a, i; - input = document.getElementById('roleNameSearchField'); - filter = input.value.toUpperCase(); - table = document.getElementById("rolesTable"); - trs = table.getElementsByClassName('rolesRow'); - - // Loop through all list items, and hide those who don't match the search query - for (i = 0; i < trs.length; i++) { - a = trs[i].getElementsByClassName("rolesData")[0]; - if (a.innerHTML.toUpperCase().indexOf(filter) > -1) { - trs[i].style.display = ""; + var filter = $("#roleNameSearchField").val().toLowerCase(); + $(".rolename").each(function() { + if ($(this).text().toLowerCase().indexOf(filter) >= 0) { + $(this).closest("tr").show(); } else { - trs[i].style.display = "none"; + $(this).closest("tr").hide(); } - } + }); } </script>
\ No newline at end of file diff --git a/modules-available/permissionmanager/templates/treenode.html b/modules-available/permissionmanager/templates/treenode.html index 336ca13e..ced973ca 100644 --- a/modules-available/permissionmanager/templates/treenode.html +++ b/modules-available/permissionmanager/templates/treenode.html @@ -1,8 +1,8 @@ {{#toplevel}}<ul>{{/toplevel}} <li title="{{description}}" data-toggle="tooltip" data-placement="left"> <div class='checkbox'> - <input name='{{checkboxname}}[]' value='{{id}}' type='checkbox' class='form-control' {{#selected}}checked{{/selected}}> - <label>{{#toplevel}}<b>{{/toplevel}}{{name}}{{#toplevel}}</b>{{/toplevel}}</label> + <input id="{{id}}" name="{{checkboxname}}[]" value="{{id}}" type="checkbox" class="form-control" {{#selected}}checked{{/selected}}> + <label for="{{id}}">{{#toplevel}}<b>{{/toplevel}}{{name}}{{#toplevel}}</b>{{/toplevel}}</label> </div> <ul> {{{HTML}}} diff --git a/modules-available/permissionmanager/templates/treepanel.html b/modules-available/permissionmanager/templates/treepanel.html index 53e316c9..6f358825 100644 --- a/modules-available/permissionmanager/templates/treepanel.html +++ b/modules-available/permissionmanager/templates/treepanel.html @@ -1,11 +1,11 @@ -<div class='panel panel-primary tree-panel'> - <div class='panel-heading'> - <div class='checkbox'> - <input name='{{checkboxname}}[]' value='{{id}}' type='checkbox' class='form-control' {{#selected}}checked{{/selected}}> - <label>{{name}}</label> +<div class="panel panel-primary tree-panel"> + <div class="panel-heading"> + <div class="checkbox"> + <input id="{{id}}" name="{{checkboxname}}[]" value="{{id}}" type="checkbox" class="form-control" {{#selected}}checked{{/selected}}> + <label for="{{id}}">{{name}}</label> </div> </div> - <div class='panel-body'> + <div class="panel-body"> <div class="tree-container" style="padding-left: 20px; padding-right: 20px;"> {{{HTML}}} </div> diff --git a/modules-available/permissionmanager/templates/userstable.html b/modules-available/permissionmanager/templates/userstable.html index 9f684e99..bb0e228e 100644 --- a/modules-available/permissionmanager/templates/userstable.html +++ b/modules-available/permissionmanager/templates/userstable.html @@ -13,8 +13,8 @@ </select> </div> <div class="col-md-4 text-right"> - <button class="btn btn-success" type="button" data-toggle="modal" data-target="#addRoleToUserModal"><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> - <button class="btn btn-danger" type="button" data-toggle="modal" data-target="#removeRoleFromUserModal"><span class="glyphicon glyphicon-trash"></span> {{lang_removeRole}}</button> + <button class="roleButtons btn btn-success" type="button" data-toggle="modal" data-target="#addRoleToUserModal" disabled><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> + <button class="roleButtons btn btn-danger" type="button" data-toggle="modal" data-target="#removeRoleFromUserModal" disabled><span class="glyphicon glyphicon-remove-circle"></span> {{lang_removeRole}}</button> </div> </div> @@ -23,9 +23,9 @@ <table id="usersTable" class="table table-condensed table-hover stupidtable dataTable"> <thead> <tr> - <th data-sort="string">{{lang_Users}}</th> - <th>{{lang_Roles}}</th> - <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> + <th data-sort="string">{{lang_users}}</th> + <th>{{lang_roles}}</th> + <th data-sort="int" data-sort-default="desc">{{lang_selected}}</th> </tr> </thead> @@ -35,7 +35,7 @@ <td>{{username}}</td> <td> {{#roles}} - <span class="label label-default customSpanMargin roleid-{{roleid}}">{{rolename}}</span> + <a href="?do=permissionmanager&show=roleEditor&cancel=users&roleid={{roleid}}" class="label label-default customSpanMargin roleid-{{roleid}}">{{rolename}}</a> {{/roles}} </td> <td data-sort-value="0"> @@ -65,8 +65,8 @@ <table id="addRoleToUserTable" class="table table-condensed table-hover stupidtable"> <thead> <tr> - <th data-sort="string">{{lang_Roles}}</th> - <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> + <th data-sort="string">{{lang_roles}}</th> + <th data-sort="int" data-sort-default="desc">{{lang_selected}}</th> </tr> </thead> @@ -89,7 +89,7 @@ </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> - <button type="submit" name="action" value="addRoleToUser" class="btn btn-success" onclick="clearRemoveRoleModal()"><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> + <button id="confirmAddButton" type="submit" name="action" value="addRoleToUser" class="btn btn-success" onclick="clearRemoveRoleModal()" disabled><span class="glyphicon glyphicon-share-alt"></span> {{lang_addRole}}</button> </div> </div> </div> @@ -100,7 +100,7 @@ <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> - <h4 class="modal-title" id="myModalLabel2">{{lang_Remove}}</h4> + <h4 class="modal-title" id="myModalLabel2">{{lang_removeRole}}</h4> </div> <div class="modal-body"> <div class="row"> @@ -108,8 +108,8 @@ <table id="removeRoleFromUserTable" class="table table-condensed table-hover stupidtable"> <thead> <tr> - <th data-sort="string">{{lang_Roles}}</th> - <th data-sort="int" data-sort-default="desc">{{lang_Selected}}</th> + <th data-sort="string">{{lang_roles}}</th> + <th data-sort="int" data-sort-default="desc">{{lang_selected}}</th> </tr> </thead> @@ -132,7 +132,7 @@ </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_cancel}}</button> - <button type="submit" name="action" value="removeRoleFromUser" class="btn btn-danger" onclick="clearAddRoleModal()"><span class="glyphicon glyphicon-trash"></span> {{lang_Remove}}</button> + <button id="confirmRemoveButton" type="submit" name="action" value="removeRoleFromUser" class="btn btn-danger" onclick="clearAddRoleModal()" disabled><span class="glyphicon glyphicon-remove-circle"></span> {{lang_removeRole}}</button> </div> </div> </div> @@ -140,34 +140,85 @@ </form> <script> + selectedUsersCounter = 0; + selectedAddRolesCounter = 0; + selectedRemoveRolesCounter = 0; + document.addEventListener("DOMContentLoaded", function() { - // if checked,: mark green, else: unmark - $('input:checkbox').change(function() { + var checkboxes = $("input[type=checkbox]"); + checkboxes.prop("checked", false); + $(".roleButtons, #confirmAddButton, #confirmRemoveButton").prop("disabled", true); + + checkboxes.change(function() { if ($(this).is(':checked')) { + var color = "#eeeeff"; + if ($(this).closest("table").is("#addRoleToUserTable")) { + color = "#eeffee"; + } else if ($(this).closest("table").is("#removeRoleFromUserTable")) { + color = "#ffeeee"; + } $(this).closest("td").data("sort-value", 1); - $(this).closest("tr").css("background-color", "#f2ffe6"); + $(this).closest("tr").css("background-color", color); } else { $(this).closest("td").data("sort-value", 0); $(this).closest("tr").css("background-color", ""); } + }); + $("#usersTable").find("input[type=checkbox]").change(function() { + if ($(this).is(':checked')) { + selectedUsersCounter++; + if (selectedUsersCounter === 1) { + $(".roleButtons").prop("disabled", false); + } + } else { + selectedUsersCounter--; + if (selectedUsersCounter === 0) { + $(".roleButtons").prop("disabled", true); + } + } }); - }); + $("#addRoleToUserTable").find("input[type=checkbox]").change(function() { + if ($(this).is(':checked')) { + selectedAddRolesCounter++; + if (selectedAddRolesCounter === 1) { + $("#confirmAddButton").prop("disabled", false); + } + } else { + selectedAddRolesCounter--; + if (selectedAddRolesCounter === 0) { + $("#confirmAddButton").prop("disabled", true); + } + } + }); + + $("#removeRoleFromUserTable").find("input[type=checkbox]").change(function() { + if ($(this).is(':checked')) { + selectedRemoveRolesCounter++; + if (selectedRemoveRolesCounter === 1) { + $("#confirmRemoveButton").prop("disabled", false); + } + } else { + selectedRemoveRolesCounter--; + if (selectedRemoveRolesCounter === 0) { + $("#confirmRemoveButton").prop("disabled", true); + } + } + }); + }); // if remove-Role button is clicked, uncheck all checkboxes in add-role modal so they aren't submitted too function clearAddRoleModal () { $('#addRoleToUserModal') .find("input[type=checkbox]") - .prop("checked", "") - .end(); + .prop("checked", false); } // if add-Role button is clicked, uncheck all checkboxes in remove-role modal so they aren't submitted too function clearRemoveRoleModal() { $('#removeRoleFromUserModal') .find("input[type=checkbox]") - .prop("checked", "") - .end(); + .prop("checked", false); } </script>
\ No newline at end of file |