{extend name="common/common2" /}
{block name="main"}

<style>
    .submit-btn{
        position: fixed;
        z-index: 10;
        top: 3px;
        right: 5px;
    }
    .submit-btn2{
        position: fixed;
        z-index: 10;
        top: 3px;
        right: 90px;
    }
    .panel-body{
        height: 90%;
        overflow: auto;
    }
    .tab-content{
        width: 60%;
        display: inline-block;
        float: left;
    }
    .org-box{
        width: 40%;
        height: auto;
        background: #fff;
        display: inline-block;
        float: right;
    }
</style>

<div class="tabs-container" >
    <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">后台权限</a>
        </li>
        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">APP权限</a>
        </li>
    </ul>
    <form method="post" action="{:url('orgBatchAuth')}" class="form-horizontal">

        <div class="tab-content">
            <div id="tab-1" class="tab-pane active">
                <div class="panel-body">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th style="width: 30px;"><input type="checkbox" class="check-all"></th>
                            <th>权限名称</th>
                        </tr>
                        </thead>
                        <tbody>
                        {if condition="$menus"}
                        {:widget_view('org/org_bach_authtree',['data'=>$menus,'select'=>[],'depth'=>0])}
                        {/if}
                        </tbody>
                    </table>
                </div>
            </div>
            <div id="tab-2" class="tab-pane">
                <div class="panel-body">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th style="width: 30px;"><input type="checkbox" class="app-check-all"></th>
                            <th>权限名称</th>
                        </tr>
                        </thead>
                        <tbody>
                        {if condition="$appauths"}
                        {:widget_view('org/org_bach_authtreeapp',['data'=>$appauths,'select'=>[],'depth'=>0])}
                        {/if}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <div class="org-box">
            <div class="panel-body">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th style="width: 30px;"><input type="checkbox" class="check-all-org"></th>
                        <th>组织名称</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $orgList as $k=>$v}
                    <tr>
                        <td>
                            <input type="checkbox"  class="orgs {$v.id}" name="orgs[]" value="{$v.id}" onclick="orgClick('{$v.id}',this)">
                        </td>
                        <td>
                            <i class="glyphicon glyphicon-list-alt"></i>
                            {$v.name}
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>

        </div>

        <button class="btn btn-primary ajax-post submit-btn" target-form="form-horizontal" type="submit">保存权限</button>
    </form>
</div>



<div class="ibox" style="display: none">
    <div class="ibox-content">

    </div>
</div>
{/block}
{block name="script"}
<script>
    $(document).on('click','.app-check-all',function(){
        $(".appids").prop("checked", $(this).prop('checked'));
    });

    function checkSubClick(id,_this){
        if($(_this).prop('checked') == true){
            $('.sub_'+id).prop("checked", $(_this).prop('checked'));
        }else {
            $('.sub_'+id).prop("checked", false);
        }
    }

    $(document).on('click','.check-all-org',function(){
        $(".orgs").prop("checked", $(this).prop('checked'));
    });

    function orgClick(id,_this){
        if($(_this).prop('checked') == true){
            $('.orgs'+id).prop("checked", $(_this).prop('checked'));
        }else {
            $('.orgs'+id).prop("checked", false);
        }
    }
</script>
{/block}