Last active
January 1, 2016 10:59
-
-
Save alanland/8134867 to your computer and use it in GitHub Desktop.
Grails Shiro-dui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="/app/static/dojo-release/dijit/themes/claro/claro.css"> | |
<script>dojoConfig = {parseOnLoad: true}</script> | |
<script src='/app/static/dojo-release/dojo/dojo.js'></script> | |
<script> | |
require(["dojo/parser", "dijit/form/Form", "dijit/form/CheckBox", "dijit/form/ValidationTextBox", "dijit/form/DateTextBox"]); | |
</script> | |
<tr class="prop"> | |
<td valign="top" class="name"> | |
<label for="permissions"><g:message code="shiroUser.permissions.label" default="Permissions" /></label> | |
</td> | |
<td valign="top" class="value ${hasErrors(bean: shiroRoleInstance, field: 'permissions', 'errors')}"> | |
<shirodui:permissionSelect name="permissions" size="10" value="${shiroRoleInstance?.permissions}"/> | |
</td> | |
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def permissionSelect = { attrs -> | |
def allPerms = ((attrs.value ?: []) + grailsApplication.controllerClasses.findAll { | |
it.propertyName != "authController" | |
}.collect { controller -> | |
def base = controller.propertyName - 'Controller'; | |
controller.getURIs().collect { | |
def action = it.split('\\/') | |
action = (action.size() == 2 ? "*" : action[2]) | |
"${base}:${action}" | |
} | |
} + "*:*").flatten().collect { it.toString() }.unique().sort() | |
if (allPerms) { | |
allPerms = allPerms.groupBy { it.split(":")[0] } | |
int i=0 | |
allPerms.each { k, perms -> | |
perms.each { String perm -> | |
def name = perm | |
if (perm.endsWith(":*")) { | |
out << "<br>" | |
out << """<input id="$name" name="permissions[$i]" data-dojo-type="dijit/form/CheckBox" value="$name" /> <label for="$name">$k</label><br>""" | |
out << '<hr>' | |
} else { | |
out << """<input id="$name" name="permissions[$i]" data-dojo-type="dijit/form/CheckBox" value="$name" /> <label for="$name">${perm - "$k:"}</label> """ | |
} | |
i++ | |
} | |
out << "<br>" | |
} | |
} else { | |
out << "<i>-</i>" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment