Skip to content

Instantly share code, notes, and snippets.

@alanland
Last active January 1, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanland/8134867 to your computer and use it in GitHub Desktop.
Save alanland/8134867 to your computer and use it in GitHub Desktop.
Grails Shiro-dui
<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>
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