1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-25 02:34:31 +01:00

adding js to better handle parent/sub roles

now js functions automatically enables parent roles of a selected
roles, and disables sub roles unselected role
This commit is contained in:
kakwa 2015-06-11 23:36:50 +02:00
parent a62c5a64ac
commit 5ddaa4c44f
2 changed files with 40 additions and 16 deletions

View File

@ -457,8 +457,15 @@ class LdapCherry(object):
""" add user page """
self._check_auth(must_admin=True)
is_admin = self._check_admin()
graph={}
for r in self.roles.graph:
s = list(self.roles.graph[r]['sub_roles'])
p = list(self.roles.graph[r]['parent_roles'])
graph[r] = { 'sub_roles': s, 'parent_roles': p}
graph_js = json.dumps(graph, separators=(',',':'))
form = self.temp_form.render(attributes=self.attributes.attributes, values=None)
roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph)
roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js)
return self.temp_adduser.render(form=form, roles=roles, is_admin=is_admin)
@cherrypy.expose
@ -468,18 +475,6 @@ class LdapCherry(object):
is_admin = self._check_admin()
pass
@cherrypy.expose
def graph(self, **params):
""" remove user page """
self._check_auth(must_admin=True)
is_admin = self._check_admin()
graph={}
for r in self.roles.graph:
s = list(self.roles.graph[r]['sub_roles'])
p = list(self.roles.graph[r]['parent_roles'])
graph[r] = { 'sub_roles': s, 'parent_roles': p}
return json.dumps(graph, separators=(',',':'))
@cherrypy.expose
def modify(self, **params):
""" modify user page """

View File

@ -1,3 +1,22 @@
<script type="text/javascript">
var roles = ${graph_js};
function enableParentRoles(roleid){
var parentRoles = roles[roleid]['parent_roles'];
var len = parentRoles.length;
for (var i = 0; i < len; i++) {
var role = parentRoles[i];
$('input[name=' + role +']').bootstrapSwitch('state', true, true);
}
}
function disableSubRoles(roleid){
var parentRoles = roles[roleid]['sub_roles'];
var len = parentRoles.length;
for (var i = 0; i < len; i++) {
var role = parentRoles[i];
$('input[name=' + role +']').bootstrapSwitch('state', false, true);
}
}
</script>
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
<thead>
<tr>
@ -35,11 +54,21 @@
${parents}
</td>
<td>
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled" data-off-text="Disabled" data-handle-width="75" type="checkbox" name="${role}" data-size="mini">
<script>$("[name='${role}']").bootstrapSwitch();</script>
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
data-off-text="Disabled" data-handle-width="75" type="checkbox"
name="${role}" data-size="mini" id="${role}" >
<script>$("[name='${role}']").bootstrapSwitch();
$('input[name="${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
if (state) {
enableParentRoles('${role}');
}
else {
disableSubRoles('${role}');
}
});
</script>
</td>
</tr>
% endfor
</tbody>
</table>