mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-25 10:44:30 +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:
parent
a62c5a64ac
commit
5ddaa4c44f
@ -457,8 +457,15 @@ class LdapCherry(object):
|
|||||||
""" add user page """
|
""" add user page """
|
||||||
self._check_auth(must_admin=True)
|
self._check_auth(must_admin=True)
|
||||||
is_admin = self._check_admin()
|
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)
|
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)
|
return self.temp_adduser.render(form=form, roles=roles, is_admin=is_admin)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -468,18 +475,6 @@ class LdapCherry(object):
|
|||||||
is_admin = self._check_admin()
|
is_admin = self._check_admin()
|
||||||
pass
|
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
|
@cherrypy.expose
|
||||||
def modify(self, **params):
|
def modify(self, **params):
|
||||||
""" modify user page """
|
""" modify user page """
|
||||||
|
@ -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">
|
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -35,11 +54,21 @@
|
|||||||
${parents}
|
${parents}
|
||||||
</td>
|
</td>
|
||||||
<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">
|
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||||
<script>$("[name='${role}']").bootstrapSwitch();</script>
|
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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
% endfor
|
% endfor
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user