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

<form id="cv-form" method="post" class="cv-mt-15">
    <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">
        <input class="easyui-textbox" name="cv[url]" label="友链地址" validType="url" style="width: 100%;"  />
    </div>
    <div class="cv-normal-input-box cv-input-box">
        <label style="text-align: left;margin-right: 2px;">友链图片</label>
        <div class="controls">
            <input style="width: 185px;" type="text" name="cv[cover]" id="cv_cover"  />
        </div>
        <div class="append">
            <button onclick="uploadFriendCover();" class="cv-button cv-button-primary" type="button">选取</button>
        </div>
    </div>
    <div class="cv-normal-input-box cv-clear">
        <input class="easyui-textbox" name="cv[remark]" 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.reloadFriendListData();
                    closeSelf();
                }
            }
        });
    }

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

    function uploadFriendCover() {
        parent.openDialog("媒体上传","<?= url('dash/media/new'); ?>?cl=returnImageUrlToParent('cv_cover',response.f_url);|closeSelf();",'750px','520px');
    }
</script>
