{template "header.html"}
<div class="note note-danger">
    <p><a href="javascript:dr_update_cache_all();">{dr_lang('更改数据之后请更新下全站缓存')}</a></p>
</div>
<form action="" class="form-horizontal" method="post" name="myform" id="myform">
    {$form}
    <div class="portlet bordered light myfbody">
        <div class="portlet-title tabbable-line">
            <ul class="nav nav-tabs" style="float:left;">
                <li class="{if $page==0}active{/if}">
                    <a href="#tab_0" data-toggle="tab" onclick="$('#dr_page').val('0')"> <i class="fa fa-cog"></i> {dr_lang('基本设置')} </a>
                </li>
                <li class="{if $page==3}active{/if}">
                    <a href="#tab_3" data-toggle="tab" onclick="$('#dr_page').val('3')"> <i class="fa fa-code"></i> {dr_lang('字段样式')} </a>
                </li>
                <li class="{if $page==1}active{/if}">
                    <a href="#tab_1" data-toggle="tab" onclick="$('#dr_page').val('1')"> <i class="fa fa-crop"></i> {dr_lang('数据验证')} </a>
                </li>
                <li class="{if $page==2}active{/if}">
                    <a href="#tab_2" data-toggle="tab" onclick="$('#dr_page').val('2')"> <i class="fa fa-user"></i> {dr_lang('字段权限')} </a>
                </li>
            </ul>
        </div>
        <div class="portlet-body">
            <div class="tab-content">

                <div class="tab-pane active" id="tab_0">
                    <div class="form-body">

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('显示名称')}</label>
                            <div class="col-md-9">
                                <label><input class="form-control" type="text" name="data[name]" value="{htmlspecialchars($data.name)}" id="dr_name" onblur="d_topinyin('fieldname','name');" /></label>
                                <span class="help-block" id="dr_name_tips">{dr_lang('为字段取个名字')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('字段名称')}</label>
                            <div class="col-md-9">
                                <label><input class="form-control" type="text"  name="data[fieldname]" value="{$data.fieldname}" {if $data.id}disabled{/if} id="dr_fieldname" /></label>
                                <span class="help-block" id="dr_fieldname_tips">{dr_lang('只能由字母+数字组成')}</span>
                            </div>
                        </div>
                        {if $ismain}
                        <input name="data[ismain]" type="hidden" value="1" />
                        {else}
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('是否主表')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" id="iszb1" name="data[ismain]" value="0" {if $id} disabled{/if} {if !$data.ismain} checked{/if} /> {dr_lang('附表')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" id="iszb2" name="data[ismain]" value="1" {if $id} disabled{/if} {if $data.ismain} checked{/if} /> {dr_lang('主表')} <span></span></label>
                                </div>
                                <span class="help-block">{dr_lang('主表字段可用于列表循环或者搜索；附表只能用于内容页显示')}</span>
                            </div>
                        </div>
                        {/if}
                        {if $issearch}
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('是否搜索')}</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="data[issearch]" value="1" {if $data['issearch']}checked{/if} data-on-text="{dr_lang('开启')}" data-off-text="{dr_lang('关闭')}" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
                                <span class="help-block">{dr_lang('选择“是”时，栏目搜索时会用的到，无实际意义')}</span>
                            </div>
                        </div>
                        {/if}
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('字段类别')}</label>
                            <div class="col-md-9">
                                <label><select class="form-control" id="dr_fieldtype" name="data[fieldtype]" onChange="show_field_option(this.value)" {if $id}disabled{/if}>
                                    <option value=""> -- </option>
                                    {loop $ftype $t}
                                    <option value="{$t.id}" {if $t.id==$data.fieldtype} selected="selected"{/if}> {$t.name}（{$t.id}） </option>
                                    {/loop}
                                    </select>
                                </label>
                                <label id="dr_loading" style="display:none">
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                    <img width="16" src="{THEME_PATH}assets/images/loading-2.gif">
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-body" id="dr_option">

                    </div>
                </div>
                <div class="tab-pane" id="tab_1">
                    <div class="form-body">
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('是否必填')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][validate][required]" value="0" {if $data['setting']['validate']['required']==0}checked{/if} onclick="set_required(0)" /> {dr_lang('否')} <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][validate][required]" value="1" {if $data['setting']['validate']['required']==1}checked{/if} onclick="set_required(1)" /> {dr_lang('是')} <span></span></label>
                                </div>
                                <span class="help-block">{dr_lang('此选项部分字段不可用')}</span>
                            </div>
                        </div>
                        <div id="required" style="display:none">
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('正则验证')}</label>
                                <div class="col-md-9">
                                    <label><input class="form-control" type="text" name="data[setting][validate][pattern]" value="{$data['setting']['validate']['pattern']}" id="dr_pattern" size="30" /></label>
                                    <label><select class="form-control" onchange="javascript:$('#dr_pattern').val(this.value)" name="pattern_select">
                                        <option value="">{dr_lang('正则验证')}</option>
                                        <option value="/^[0-9.-]+$/">{dr_lang('数字')}</option>
                                        <option value="/^[0-9-]+$/">{dr_lang('整数')}</option>
                                        <option value="/^[a-z]+$/i">{dr_lang('字母')}</option>
                                        <option value="/^[0-9a-z]+$/i">{dr_lang('数字+字母')}</option>
                                        <option value="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">Email</option>
                                    </select></label>
                                    <span class="help-block">{dr_lang('此选项部分字段不可用')}</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-2 control-label">{dr_lang('验证提示')}</label>
                                <div class="col-md-9">
                                    <input class="form-control" type="text" name="data[setting][validate][errortips]" value="{$data['setting']['validate']['errortips']}" id="dr_errortips" />
                                    <span class="help-block">{dr_lang('当字段校验未通过时的提示信息，如“标题必须在80字以内”等等')}</span>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('禁止修改')}</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="data[setting][validate][isedit]" value="1" {if $data['setting']['validate']['isedit']}checked{/if} data-on-text="{dr_lang('是')}" data-off-text="{dr_lang('否')}" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
                                <span class="help-block">{dr_lang('前端用户提交之后将不能修改字段值，后台任然可以修改值')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('XSS过滤')}</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="data[setting][validate][xss]" value="1" {if $data['setting']['validate']['xss']}checked{/if} data-on-text="{dr_lang('关闭')}" data-off-text="{dr_lang('开启')}" data-off-color="success" data-on-color="danger" class="make-switch" data-size="small">
                                <span class="help-block">{dr_lang('开启之后相关字符会被替换掉')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('校验函数/方法')}</label>
                            <div class="col-md-9">
                                <label><input class="form-control input-large"type="text" name="data[setting][validate][check]" value="{$data['setting']['validate']['check']}" id="dr_check"> </label>
                                <label><a class="btn btn-sm blue" href="javascript:dr_test_call('dr_check');"> 检测 </a></label>
                                <span class="help-block"> <a href="javascript:dr_help('601');"> {dr_lang('此功能需要有PHP编程经验，了解函数的定义')}</a> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('过滤函数/方法')}</label>
                            <div class="col-md-9">

                                <label><input class="form-control input-large"type="text" name="data[setting][validate][filter]" value="{$data['setting']['validate']['filter']}" id="dr_filter"> </label>
                                <label><a class="btn btn-sm blue" href="javascript:dr_test_call('dr_filter');"> 检测 </a></label>
                                <span class="help-block"> <a href="javascript:dr_help('602');"> {dr_lang('此功能需要有PHP编程经验，了解函数的定义')}</a> </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="tab_3">
                    <div class="form-body">

                        <div class="form-body" id="dr_css">

                        </div>

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('Css样式表')}</label>
                            <div class="col-md-9">
                                <input class="form-control" type="text" name="data[setting][option][css]" value="{$data['setting']['option']['css']}" />
                                <span class="help-block">{dr_lang('对字段进行样式控制，使用开发者自定义的css样式')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('表单附加属性')}</label>
                            <div class="col-md-9">
                                <textarea class="form-control" style="height:120px" name="data[setting][validate][formattr]">{$data['setting']['validate']['formattr']}</textarea>
                                <span class="help-block">{dr_lang('可以通过此处加入js事件、ajax验证、css等')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('字段提示信息')}</label>
                            <div class="col-md-9">
                                <input class="form-control" type="text" name="data[setting][validate][tips]" value="{$data['setting']['validate']['tips']}" />
                                <span class="help-block">{dr_lang('对字段简短的提示，来说明这个字段是用来干什么的')}</span>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="tab-pane" id="tab_2">
                    <div class="form-body">

                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('禁止使用')}</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="data[disabled]" value="1" {if $data['disabled']}checked{/if} data-on-text="{dr_lang('是')}" data-off-text="{dr_lang('否')}" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
                             </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('显示位置')}</label>
                            <div class="col-md-9">
                                <div class="mt-radio-inline">
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][is_right]" value="0" {if !$data['setting']['is_right']}checked{/if}  /> {dr_lang('默认')}  <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][is_right]" value="1" {if 1==$data['setting']['is_right']}checked{/if} /> {dr_lang('右侧')}  <span></span></label>
                                    <label class="mt-radio mt-radio-outline"><input type="radio" name="data[setting][is_right]" value="2" {if 2==$data['setting']['is_right']}checked{/if} /> {dr_lang('手动')}  <span></span></label>
                                </div>
								<span class="help-block">{dr_lang('选择“右侧”时，发布模块内容时字段显示在右侧部分; 当选择"手动"时，需要开发者手动调用 ')}
                                    <?php echo '{';?>$diyfield}
								</span>
                            </div>
                        </div>
                        <div class="form-group hide">
                            <label class="col-md-2 control-label">{dr_lang('后台不显示该字段')}</label>
                            <div class="col-md-9">
                                <div class="mt-checkbox-list">
                                    {loop $role $t}
                                    {if $t.id>1}
                                    <label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" name="data[setting][show_admin][]" value="{$t.id}" {if @in_array($t.id, (array)$data.setting.show_admin)} checked{/if} /> {$t.name} <span></span></label>
                                    {/if}
                                    {/loop}
                                </div>
                                <span class="help-block">{dr_lang('勾选之后，发布内容时该角色将不会看到这个字段')}</span>
                            </div>
                        </div>
                        <div class="form-group ">
                            <label class="col-md-2 control-label">{dr_lang('前端不显示该字段')}</label>
                            <div class="col-md-9">
                                <div class="mt-checkbox-list">
                                    <label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" name="data[setting][show_member][]" value="0" {if @in_array(0, (array)$data.setting.show_member)} checked{/if} /> {dr_lang('游客')} <span></span></label>
                                    {list action=cache name=MEMBER.group}
                                    <label class="mt-checkbox mt-checkbox-outline"><input type="checkbox" name="data[setting][show_member][]" value="{$t.id}" {if @in_array($t.id, (array)$data.setting.show_member)} checked{/if} /> {$t.name} <span></span></label>
                                    {/list}
                                </div>
                                <span class="help-block">{dr_lang('勾选之后，发布内容时该会员组将不会看到这个字段，如果“前端显示”关闭了此功能就无效')}</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2 control-label">{dr_lang('前端显示')}</label>
                            <div class="col-md-9">
                                <input type="checkbox" name="data[ismember]" value="1" {if $data['ismember']}checked{/if} data-on-text="{dr_lang('是')}" data-off-text="{dr_lang('否')}" data-on-color="success" data-off-color="danger" class="make-switch" data-size="small">
                                <span class="help-block">{dr_lang('发布内容时，如果想前端表单或者会员中心不显示那么请选择“否”，否则选“是”')}</span>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>

    <div class="portlet-body form myfooter">
        <div class="form-actions text-center">
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}&page='+$('#dr_page').val(), 'myform', '2000', '')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存')}</button>
            <button type="button" onclick="dr_ajax_submit('{dr_now_url()}&page='+$('#dr_page').val(), 'myform', '2000', '{dr_url('field/index', ['rname' => $rname, 'rid' => $rid])}')" class="btn blue"> <i class="fa fa-mail-reply-all"></i> {dr_lang('保存并返回')}</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function() {
        set_required({intval($data['setting']['validate']['required'])});
        show_field_option("{$data['fieldtype']}");
    });
    function show_field_option(type) {
        $("#dr_loading").show();
        $.ajax({type: "GET",dataType:"json", url: '/index.php?s=api&c=api&m=field&rand='+Math.random(),
            data: {type:type, relatedid:'{$rid}', relatedname:'{$rname}', app:'{$namespace}', id:{intval($data.id)}},
            success: function(data) {
                $('#dr_css').html(data.style);
                $('#dr_option').html(data.option);
                $("#dr_loading").hide();
                App.init();
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
            }
        });

    }
    function set_required(id) {
        if (id == 0) {
            $('#required').hide();
        } else {
            $('#required').show();
        }
    }

    function dr_test_call(value) {
        $.ajax({type: "GET",dataType:"json", url: "{dr_url('api/field_call')}&name="+$('#'+value).val(),
            success: function(json) {
                dr_tips(json.code, json.msg);
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
            }
        });
    }
</script>
{template "footer.html"}