diff options
5 files changed, 33 insertions, 20 deletions
diff --git a/modules-available/permissionmanager/inc/dbupdate.inc.php b/modules-available/permissionmanager/inc/dbupdate.inc.php index 417fd812..1101e4f7 100644 --- a/modules-available/permissionmanager/inc/dbupdate.inc.php +++ b/modules-available/permissionmanager/inc/dbupdate.inc.php @@ -34,13 +34,13 @@ class DbUpdate { Database::exec($query); } - public static function saveRole($roleName, $locType, $locations, $permissions, $role = NULL) { + public static function saveRole($roleName, $locations, $permissions, $role = NULL) { if ($role) { - Database::exec("UPDATE role SET name = '$roleName', locType = '$locType' WHERE id = $role"); + Database::exec("UPDATE role SET name = '$roleName' WHERE id = $role"); Database::exec("DELETE FROM roleXlocation WHERE roleid = $role"); Database::exec("DELETE FROM roleXpermission WHERE roleid = $role"); } else { - Database::exec("INSERT INTO role (name, locType) VALUES ('$roleName', '$locType')"); + Database::exec("INSERT INTO role (name) VALUES ('$roleName')"); $role = Database::lastInsertId(); } foreach ($locations as $locID) { diff --git a/modules-available/permissionmanager/inc/getdata.inc.php b/modules-available/permissionmanager/inc/getdata.inc.php index 67210246..7ca56754 100644 --- a/modules-available/permissionmanager/inc/getdata.inc.php +++ b/modules-available/permissionmanager/inc/getdata.inc.php @@ -40,7 +40,7 @@ class GetData { } public static function getRoleData($roleID) { - $query = "SELECT id, name, locType FROM role WHERE id = $roleID"; + $query = "SELECT id, name FROM role WHERE id = $roleID"; $data = Database::queryFirst($query); $query = "SELECT roleid, locid FROM roleXlocation WHERE roleid = $roleID"; $res = Database::simpleQuery($query); diff --git a/modules-available/permissionmanager/install.inc.php b/modules-available/permissionmanager/install.inc.php index e025299a..2d408f38 100644 --- a/modules-available/permissionmanager/install.inc.php +++ b/modules-available/permissionmanager/install.inc.php @@ -5,7 +5,6 @@ $res = array(); $res[] = tableCreate('role', " `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(200) NOT NULL, - `locType` varchar(200) NOT NULL DEFAULT 'include', PRIMARY KEY (`id`) "); diff --git a/modules-available/permissionmanager/page.inc.php b/modules-available/permissionmanager/page.inc.php index ef280c11..1d369ab3 100644 --- a/modules-available/permissionmanager/page.inc.php +++ b/modules-available/permissionmanager/page.inc.php @@ -30,10 +30,9 @@ class Page_PermissionManager extends Page } elseif ($action === 'saveRole') { $roleID = Request::post("roleid", false); $roleName = Request::post("roleName"); - $locType = Request::post("include", "off") == "on" ? "include" : "exclude"; - $locations = Request::post("locations"); + $locations = Request::post("allLocations", "off") == "on" ? array(0) : Request::post("locations"); $permissions = Request::post("permissions"); - DbUpdate::saveRole($roleName, $locType, $locations, $permissions, $roleID); + DbUpdate::saveRole($roleName, $locations, $permissions, $roleID); } } @@ -71,13 +70,20 @@ class Page_PermissionManager extends Page $selectedLocations = array(); if ($roleID) { $roleData = GetData::getRoleData($roleID); - $selectedLocations = $roleData["locations"]; $data["roleid"] = $roleID; $data["roleName"] = $roleData["name"]; - $data["includeChecked"] = $roleData["locType"] == "include" ? "checked" : ""; + if (count($roleData["locations"]) == 1 && $roleData["locations"][0] == 0) { + $data["allLocChecked"] = "checked"; + $data["selectizeClass"] = "disabled"; + } else { + $data["allLocChecked"] = ""; + $data["selectizeClass"] = ""; + $selectedLocations = $roleData["locations"]; + } $data["selectedPermissions"] = implode(" ", $roleData["permissions"]); } else { - $data["includeChecked"] = "checked"; + $data["allLocChecked"] = "checked"; + $data["selectizeClass"] = "disabled"; } $permissions = PermissionUtil::getPermissions(); diff --git a/modules-available/permissionmanager/templates/roleEditor.html b/modules-available/permissionmanager/templates/roleEditor.html index 99cf3053..98d87b70 100644 --- a/modules-available/permissionmanager/templates/roleEditor.html +++ b/modules-available/permissionmanager/templates/roleEditor.html @@ -13,9 +13,9 @@ <div class="row"> <div class="col-md-3"> <b style="line-height: 34px">Locations:</b> - <div class="pull-right"><input name="include" {{includeChecked}} type="checkbox" id="locSwitch"></div> + <div class="pull-right"><input name="allLocations" {{allLocChecked}} type="checkbox" id="allLocations"></div> </div> - <div class="col-md-9 text-left"> + <div id="selectize-container" class="col-md-9 text-left {{selectizeClass}}"> <select multiple name="locations[]" id="select-location"> <option value></option> {{#locations}} @@ -55,13 +55,21 @@ plugins: [ "remove_button" ] }); - var locSwitch = $("#locSwitch"); - locSwitch.bootstrapSwitch("size", "normal"); - locSwitch.bootstrapSwitch("labelWidth", 1); - locSwitch.bootstrapSwitch("onText", "include"); - locSwitch.bootstrapSwitch("offText", "exclude"); - locSwitch.bootstrapSwitch("onColor", "success"); - locSwitch.bootstrapSwitch("offColor", "danger"); + var allLocations = $("#allLocations"); + allLocations.bootstrapSwitch("size", "normal"); + allLocations.bootstrapSwitch("labelWidth", 1); + allLocations.bootstrapSwitch("onText", "all"); + allLocations.bootstrapSwitch("offText", "selected"); + allLocations.bootstrapSwitch("onColor", "default"); + allLocations.bootstrapSwitch("offColor", "primary"); + + allLocations.on('switchChange.bootstrapSwitch', function(event, state) { + if (state) { + $("#selectize-container").addClass("disabled"); + } else { + $("#selectize-container").removeClass("disabled"); + } + }); $("form input").keydown(function(e) { if (e.keyCode === 13) e.preventDefault(); |