<?php
use home\assets\MainAsset;
use yii\helpers\Url;
use home\modules\contract\models\Category;
use yii\widgets\ActiveForm;

$this->title = '合同类别';
$js = <<<JS
    $("#show-first").on('click',function(){
        var url = $(this).data('url');
        var showFirst = ($(this).is(":checked")) ? 1 : 0 ;
        window.location.href = url + showFirst;
    });
JS;
$this->registerJs($js, \yii\web\View::POS_END);
?>

<!--container-->
<div class="container manage-project fix">

    <!--manage-left -->
    <?= $this->render('@home/views/site/_left-menu') ?>
    <!--manage-left -->

    <div class="manage-right">
        <div class="tab-column tab-manage">
            <div class="tab-right">
                <button title="添加类型" type="button" data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-width='489' data-height='273' data-title='添加类型' class="btn btn-default btn-task open-dialog">
                   <i class="icon-plus"></i>
                </button>
                <input type="checkbox" <?= (isset($get['show_first']) && $get['show_first'] ==1) ? 'checked="checked"' : '' ?> id="show-first" data-url="<?= Url::to(['index', 'type' => (isset($get['type'])) ? $get['type'] : '' ,'show_first' => '']) ?>" style="position:relative; top:2px; left:-2px;">
                只看一级目录
            </div>
            <p class="caption">类型列表</p>
        </div>

        <?= \home\widgets\Alert::widget(); ?>
        <?php $mainForm = ActiveForm::begin(['id' => 'main-form', 'action' => '']); ?>

            <table class="table task-table">
                <tr>
                    <th width="60"><label style="font-weight:lighter" ><input type="checkbox" name="select_all" class="box-select-all" style="position:relative;top:2px;" /> 全选</label></th>
                    <th width="50">排序</th>
                    <th width="60%">名称</th>
                    <th width="50">状态</th>
                    <th width="150">操作</th>
                </tr>
                <?php if (empty($models)) : ?>
                <tr><td colspan="5" class="tac red">还没有任何数据...</td></tr>
                <?php else : ?>
                    <?php /* $search = isset($get['keywords']) ? array('like', $get['search_field'], $get['keywords']) : [] */ ?>
                    <?php echo Category::getIndexTree(0, [], Yii::$app->request->get('show_first')); ?>
                <?php endif; ?>
            </table>
            <div class="tab-column tab-manage">
                <button type="button" title="删除" class="btn btn-default btn-task batch-delete" data-url="<?= Url::to([$this->context->id . '/delete']) ?>" >
                    <i class="icon-trash"></i>
                </button>
            </div>
        <?php ActiveForm::end(); ?>
    </div>
    <!--manage-right-->
</div>

