<@sys.dept id=id>
    <#assign a=object/>
    <#if (object.parentId)?has_content><#assign parentId=object.parentId/></#if>
    <#if (object.userId)?has_content><#assign userId=object.userId/></#if>
</@sys.dept>
<@sys.dept id=parentId!><#assign parentName=(object.name)!/></@sys.dept>
<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="<@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 'dept.parent'/>:</dt>
                <dd>
                    <input name="parentId" type="hidden" value="${parentId!}"/>
                    <input name="parentName" readonly="readonly" type="text" size="30" value="${(parentName)!}"/>
                    <a class="btnLook" href="sysDept/lookup.html?field=parentId&nameField=parentName" lookupGroup=""><@t.page 'dept.select'/></a>
                </dd>
            </dl>
            <dl>
                <dt><@t.page 'name'/>:</dt>
                <dd>
                    <input class="required" name="name" type="text" maxlength="50" size="30" value="${(a.name)!}"/>
                    <label><input name="hasChild" type="checkbox" class="form-check-input"${(a?has_content&&a.hasChild)?then(' checked="checked"','')?no_esc}/><@t.page 'dept.has_child'/></label>
                </dd>
            </dl>
            <dl>
                <dt><@t.page 'code'/>:</dt>
                <dd><input class="required" name="code" remote="sysDept/virify<#if id?has_content>?oldCode=${(a.code)!}</#if>" data-msg-remote="<@t.message 'verify.hasExist.code'/>" type="text" maxlength="50" size="20" value="${(a.code)!}"/></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="30" value="<@sys.user id=userId>${(object.nickname)!}</@sys.user>" 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" class="form-check-input"/></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" class="form-check-input"/></dd>
            </dl>
            <dl class="nowrap">
                <dt><@t.page 'dept.own_all_config'/>:</dt>
                <dd><input name="ownsAllConfig" type="checkbox" class="form-check-input"/></dd>
            </dl>
    <#macro categoryTree parentId=''>
        <@cms.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>
        </@cms.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=''>
        <@tools.fileList path=filepath>
            <#list list as a>
                <li>
                    <#local path=filepath+'/'+a.fileName>
                    <@tools.metadata path=path>
                        <a tname="pages" tvalue="${path}">${(object.alias)?has_content?then(object.alias+' '+a.fileName,a.fileName)}</a>
                    </@tools.metadata>
                    <#if a.directory>
                        <ul>
                            <@pageTree path/>
                        </ul>
                    </#if>
                </li>
            <#else>
                <li><a><@t.page 'empty_directory'/></a></li>
            </#list>
        </@tools.fileList>
    </#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>
                    <@sys.configList 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>
                    </@sys.configList>
                        </ul>
                    </li>
                </ul>
            </fieldset>
    <script>
        $('input[name=ownsAllCategory]',navTab.getCurrentPanel()).on("click", function(){
            if($(this).is(':checked')) {
                $('.ownsAllCategory',navTab.getCurrentPanel()).hide();
            } else {
                $('.ownsAllCategory',navTab.getCurrentPanel()).show();
            }
        });
        $('input[name=ownsAllPage]',navTab.getCurrentPanel()).on("click", function(){
            if($(this).is(':checked')) {
                $('.ownsAllPage',navTab.getCurrentPanel()).hide();
            } else {
                $('.ownsAllPage',navTab.getCurrentPanel()).show();
            }
        });
        $('input[name=ownsAllConfig]',navTab.getCurrentPanel()).on("click", function(){
            if($(this).is(':checked')) {
                $('.ownsAllConfig',navTab.getCurrentPanel()).hide();
            } else {
                $('.ownsAllConfig',navTab.getCurrentPanel()).show();
            }
        });
    <#if a?has_content>
        <#if a.ownsAllPage>
        $('input[name=ownsAllPage]',navTab.getCurrentPanel()).trigger("click");
        </#if>
        <@sys.deptItemList itemType='page' deptId=a.id>
            <#list page.list as a>
        $('.ownsAllPage .tree li a[tname=pages][tvalue="${a.id.itemId?js_string}"]',navTab.getCurrentPanel()).attr('checked','true');
            </#list>
        </@sys.deptItemList>
        <#if a.ownsAllCategory>
        $('input[name=ownsAllCategory]',navTab.getCurrentPanel()).trigger("click");
        </#if>
        <@sys.deptItemList itemType='category' deptId=a.id>
            <#list page.list as a>
        $('.ownsAllCategory .tree li a[tname=categoryIds][tvalue=${a.id.itemId}]',navTab.getCurrentPanel()).attr('checked','true');
            </#list>
        </@sys.deptItemList>
        <#if a.ownsAllConfig>
        $('input[name=ownsAllConfig]',navTab.getCurrentPanel()).trigger("click");
        </#if>
        <@sys.deptItemList itemType='config' deptId=a.id>
            <#list page.list as a>
        $('.ownsAllConfig .tree li a[tname=configs][tvalue=${a.id.itemId?js_string}]',navTab.getCurrentPanel()).attr('checked','true');
            </#list>
        </@sys.deptItemList>
    </#if>
    </script>
        </div>
    </div>
</form>