<@sys.role id=id>
    <#assign a=object/>
</@sys.role>
<form method="post" autocomplete="off" action="sysRole/save?callbackType=closeCurrent&navTabId=sysRole/list" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
    <input name="id" type="hidden" value="${id!}"/>
    <input type="hidden" name="_csrf" value="<@tools.csrfToken admin=true/>"/>
    <div class="formBar card">
        <ul>
            <li><button type="submit" class="buttonActive" title="ctrl+s"><@t.page 'button.save'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
    <div class="card">
        <div class="pageFormContent" layoutH>
            <dl class="nowrap">
                <dt><@t.page 'name'/>:</dt>
                <dd>
                    <input class="required" name="name" type="text" maxlength="20" size="20" value="${(a.name)!}"/>
                </dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'module.own_all_right'/>:</dt>
                <dd>
                    <input name="ownsAllRight" type="checkbox" class="form-check-input"/>
                </dd>
            </dl>
    <#macro moduleTree parentId=''>
        <@sys.moduleList parentId=parentId advanced=true>
                <#list page.list as a>
                    <li>
                        <a tname="moduleIds" tvalue="${a.id}"> <@t.menu a.id/></a>
                    <#if a.hasChild>
                        <ul>
                            <@moduleTree a.id/>
                        </ul>
                    </#if>
                    </li>
                </#list>
        </@sys.moduleList>
    </#macro>
            <fieldset class="ownsAllRight">
                <legend><@t.page 'module'/></legend>
                <dl class="nowrap">
                    <dt><@t.page 'module.show_all_module'/>:</dt>
                    <dd>
                        <input name="showAllModule" type="checkbox" class="form-check-input"/>
                    </dd>
                </dl>
                <ul class="tree treeFolder treeCheck">
                    <li>
                        <a href="javascript:;" onclick="return false;"><@t.page 'module.all'/></a>
                        <ul>
                            <@moduleTree/>
                        </ul>
                    </li>
                </ul>
    <script>
    $('input[name=ownsAllRight]',navTab.getCurrentPanel()).on("click", function(){
        if($(this).is(':checked')) {
            $('.ownsAllRight',navTab.getCurrentPanel()).hide();
        } else {
            $('.ownsAllRight').show();
        }
    });
<#if a?has_content>
        <#if a.ownsAllRight>
        $('input[name=ownsAllRight]',navTab.getCurrentPanel()).trigger("click");
        </#if>
        <#if a.showAllModule>
        $('input[name=showAllModule]',navTab.getCurrentPanel()).trigger("click");
        </#if>
        <@sys.roleModuleList roleId=a.id>
            <#list page.list as a>
        $('.tree li a[tname=moduleIds][tvalue=${a.id.moduleId?js_string}]',navTab.getCurrentPanel()).attr('checked','true');
            </#list>
        </@sys.roleModuleList>
</#if>
    </script>
            </fieldset>
        </div>
    </div>
</form>