<@_sysDept id=id>
    <#assign a=object/>
    <#if (object.parentId)??><#assign parentId=object.parentId/></#if>
    <#if (object.userId)??><#assign userId=object.userId/></#if>
</@_sysDept>
<@_sysDept id=parentId!><#assign parentName=(object.name)!/></@_sysDept>
<form method="post" autocomplete="off" action="sysDept/save?callbackType=closeCurrent&navTabId=sysDept/list" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
    <input name="id" type="hidden" value="${id!}" />
    <input type="hidden" name="_csrf" value="<@_csrfToken admin=true/>"/>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive"><@t.page 'button.save'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
    <div class="pageFormContent" layoutH>
        <dl class="nowrap">
            <dt><@t.page 'dept.parent'/>:</dt>
            <dd>
                <input name="parentId" type="hidden" value="${parentId!}"/>
                <input name="parentName" readonly="readonly" type="text" size="10" value="${(parentName)!}"/>
                <a class="btnLook" href="sysDept/lookup.html" lookupGroup=""><@t.page 'dept.select'/></a>
            </dd>
        </dl>
        <dl class="nowrap">
            <dt><@t.page 'name'/>:</dt>
            <dd><input class="required" name="name" type="text" size="30" value="${(a.name)!}"/></dd>
        </dl>
        <dl class="nowrap">
            <dt><@t.page 'description'/>:</dt>
            <dd><textarea name="description" maxlength="150" cols="80" rows="3">${(a.description)!}</textarea></dd>
        </dl>
        <dl class="nowrap">
            <dt><@t.page 'dept.master'/>:</dt>
            <dd>
                <input name="userId" value="${userId!}" type="hidden"/>
                <input name="nickName" readonly="readonly" size="10" value="<@_sysUser id=userId>${(object.nickName)!}</@_sysUser>" type="text"/>
                <a class="btnLook" href="sysUser/lookup.html" width="920" lookupGroup=""><@t.page 'user.select'/></a>    
            </dd>
        </dl>
        <dl>
            <dt><@t.page 'dept.own_all_category'/>:</dt>
            <dd><input name="ownsAllCategory" type="checkbox" onclick="if($(this).is(':checked')){$('.ownsAllCategory',navTab.getCurrentPanel()).hide();}else{$('.ownsAllCategory',navTab.getCurrentPanel()).show();}"/></dd>
        </dl>
        <dl>
            <dt><@t.page 'content.max_top_level'/>:</dt>
            <dd><input class="required digits" type="number" name="maxSort" max="2100000000" value="${(a.maxSort)!100}"/></dd>
        </dl>
        <dl class="nowrap">
            <dt><@t.page 'dept.own_all_page'/>:</dt>
            <dd><input name="ownsAllPage" type="checkbox" onclick="if($(this).is(':checked')){$('.ownsAllPage',navTab.getCurrentPanel()).hide();}else{$('.ownsAllPage',navTab.getCurrentPanel()).show();}"/></dd>
        </dl>
        <dl class="nowrap">
            <dt><@t.page 'dept.own_all_config'/>:</dt>
            <dd><input name="ownsAllConfig" type="checkbox" onclick="if($(this).is(':checked')){$('.ownsAllConfig',navTab.getCurrentPanel()).hide();}else{$('.ownsAllConfig',navTab.getCurrentPanel()).show();}"/></dd>
        </dl>
<#macro categoryTree parentId=''>
    <@_categoryList parentId=parentId advanced=true pageSize=500>
        <#list page.list as a>
            <li>
                <a tname="categoryIds" tvalue="${a.id}">${a.name}</a>
            <#if a.childIds?has_content>
                <ul>
                    <@categoryTree a.id/>
                </ul>
            </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@_categoryList>
</#macro>
        <fieldset class="ownsAllCategory">
            <legend><i class="icon-folder-open icon-large"></i> <@t.page 'dept.category_authorize'/></legend>
            <ul class="tree treeFolder treeCheck expand">
                <li>
                    <a href="javascript:;" onclick="return false;"><@t.page 'category.all'/></a>
                    <ul><@categoryTree/></ul>
                </li>
            </ul>
        </fieldset>
<#macro pageTree filepath=''>
    <@_templateList path=filepath>
        <#list list as a>
            <li>
                <#local path=filepath+'/'+a.fileName>
                <@_metadata path=path>
                    <a tname="pages" tvalue="${path}">${(object.alias)?has_content?then(object.alias+' ('+a.fileName+')',a.fileName)}</a>
                </@_metadata>
                <#if a.directory>
                    <ul>
                        <@pageTree path/>
                    </ul>
                </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@_templateList>
</#macro>
        <fieldset class="ownsAllPage">
            <legend><@t.page 'dept.page_authorize'/></legend>
            <ul class="tree treeFolder treeCheck expand">
                <li>
                    <a href="javascript:;" onclick="return false;"><@t.page 'page.all'/></a>
                    <ul><@pageTree/></ul>
                </li>
                <li>
                    <a href="javascript:;" onclick="return false;"><@t.page 'place.all'/></a>
                    <ul><@pageTree '/include'/></ul>
                </li>
            </ul>
        </fieldset>
        <fieldset class="ownsAllConfig">
            <legend><@t.page 'dept.config_authorize'/></legend>
            <ul class="tree treeFolder treeCheck expand">
                <li>
                    <a href="javascript:;" onclick="return false;"><@t.page 'config.all'/></a>
                    <ul>
                <@_sysConfigList advanced=true>
                    <#list list as a>
                        <li>
                            <a tname="configs" tvalue="${a.code}">${(a.code)!} ${a.customed?then('','['+t.pageMessage('config.system_item')+']')}</a>
                        </li>
                    </#list>
                </@_sysConfigList>
                    </ul>
                </li>
            </ul>
        </fieldset>
<#if a??>
<script>
    <#if a.ownsAllPage>
    $('input[name=ownsAllPage]',navTab.getCurrentPanel()).click();
    </#if>
    <@_sysDeptPageList deptId=a.id>
        <#list page.list as a>
    $('.ownsAllPage .tree li a[tname=pages][tvalue="${a.id.page?js_string}"]',navTab.getCurrentPanel()).prop('checked',true);
        </#list>
    </@_sysDeptPageList>
    <#if a.ownsAllCategory>
    $('input[name=ownsAllCategory]',navTab.getCurrentPanel()).click();
    </#if>
    <@_sysDeptCategoryList deptId=a.id>
        <#list page.list as a>
    $('.ownsAllCategory .tree li a[tname=categoryIds][tvalue=${a.id.categoryId}]',navTab.getCurrentPanel()).prop('checked',true);
        </#list>
    </@_sysDeptCategoryList>
    <#if a.ownsAllConfig>
    $('input[name=ownsAllConfig]',navTab.getCurrentPanel()).click();
    </#if>
    <@_sysDeptConfigList deptId=a.id>
        <#list page.list as a>
    $('.ownsAllConfig .tree li a[tname=configs][tvalue=${a.id.config?js_string}]',navTab.getCurrentPanel()).prop('checked',true);
        </#list>
    </@_sysDeptConfigList>
</script>
</#if>
    </div>
</form>