<?= view('layout/header')->send(); ?>

<form id="cv-form" method="post" class="cv-mt-15">
    <div class="cv-normal-input-box">
        <?php if (intval($parent_id)===0):?>
        <select id="cv_category_ctype" class="easyui-combobox" name="cv[c_type]" label="栏目类型" limitToList="true" editable="false" style="width:100%">
            <option value="1">文章模型</option>
            <option value="2">产品模型</option>
            <option value="3">单页模型</option>
            <option value="4">案例模型</option>
        </select>
        <?php endif;?>
    </div>
    <?php if ($is_son):?>
        <input type="hidden" name="cv[parent_id]" value="<?= $parent_id; ?>" />
        <?php else:?>
        <div class="cv-normal-input-box">
            <select id="cv_category_parent" class="easyui-combobox" name="cv[parent_id]" label="栏目所属" limitToList="true" required style="width:100%">
                <option value="0">=顶级栏目=</option>
                <?php foreach ($categories as $category):?>
                    <?php if (intval($category['c_type'])!==0):?>
                    <option <?php if ($parent_id===intval($category['id'])):?>selected<?php endif;?> value="<?= $category['id']; ?>"><?= $category['title']; ?></option>
                    <?php endif;?>
                <?php endforeach;?>
            </select>
        </div>
    <?php endif;?>

    <div class="cv-normal-input-box">
        <input class="easyui-textbox" name="cv[title]" label="栏目名称" prompt="<?= lang('请输入栏目名称'); ?>" missingMessage="<?= lang('栏目名称为必填项'); ?>" required style="width: 100%;"  />
    </div>
    <div class="cv-normal-input-box">
        <label class="textbox-label textbox-label-before">是否显示</label>
        <span class="easyui-fluid">
            <input type="radio" name="cv[is_show]" value="1" checked />&nbsp;是&nbsp;&nbsp;
            <input type="radio" name="cv[is_show]" value="0" />&nbsp;否
        </span>
    </div>
    <div class="cv-normal-input-box">
        <input class="easyui-textbox" name="cv[mark]" label="标识" prompt="<?= lang('可为该栏目指定特殊标识'); ?>" style="width: 100%;"  />
    </div>
    <div class="cv-normal-input-box">
        <input class="easyui-textbox" name="cv[keywords]" label="关键词" prompt="<?= lang('请输入栏目关键词'); ?>" style="width: 100%;"  />
    </div>
    <div class="cv-normal-input-box">
        <input class="easyui-textbox" name="cv[view]" label="模板" prompt="<?= lang('仅需输入模板文件名，不含后缀'); ?>" style="width: 100%;"  />
    </div>
    <div class="cv-normal-input-box">
        <input buttonText="选取" id="cv_logo" class="easyui-textbox" name="cv[logo]" label="Logo" style="width: 100%;" />
    </div>
    <div class="cv-normal-input-box">
        <input class="easyui-textbox" name="cv[description]" label="栏目描述" prompt="<?= lang('请描述该栏目'); ?>" style="width: 100%;" multiline="true"  />
    </div>
</form>

<div class="cv-submit">
    <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="saveForm()" style="width:80px">确定</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeSelf()" style="width:80px">取消</a>
</div>
<?= view('layout/footer')->send(); ?>

<script type="text/javascript">
    function saveForm(){
        $("#cv-form").form('submit',{
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var response = JSON.parse(result);
                parent.message(response.message);
                if (response.success){
                    parent.reloadCategoryListData();
                    closeSelf();
                }
            }
        });
    }

    function closeSelf() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

    $(function () {
        $('#cv_logo').textbox({
            onClickButton: function () {
                parent.openDialog("媒体上传","<?= url('dash/media/new'); ?>?cl=toCategoryLogoReceiver(response.f_url);|closeSelf();",'750px','520px');
            }
        });

        $('#cv_category_parent').combobox({
            onChange: function (newValue,oldValue) {
                var cType = $('#cv_category_ctype');
                if (newValue==0){
                    cType.textbox('enable')
                }else {
                    cType.textbox('disable')
                }
            }
        })
    });

    function categoryLogoReceiver(response) {
        $('#cv_logo').textbox('setValue',response);
    }
</script>
