@using Common;
@model string

<form class="form-horizontal form ui-validForm" action="@Url.Action()" method="post">
    @*<div class="main item" style="margin-bottom:15px;">
        <div class="control-group bangding">
            <label class="control-label radio">是否下载图片</label>
            <div class="controls">
                <label class="radio-inline">
                    <input type="radio" name="is_download" id="is_download" value="1">是
                </label>
                <label class="radio-inline">
                    <input type="radio" name="is_download" id="is_download" checked value="0">否
                </label>
                <span class="help-block"></span>
            </div>
        </div>
    </div>*@
    @if (ViewBag.FieldName.Rows.Count <=0)
    {
        <script>
                $(function () {
                    Msg("请设置采集字段！")
                })
        </script>
    }
    else
    {
        foreach (var dr in ViewBag.FieldName.Rows)
        {
            <div class="main item" style="margin-bottom:15px;" id="box_@dr["name"].ToString()">
                @if (dr["value_type"].ToString() == "ntext")
                {
                    <div class="control-group bangding">
                        <label class="control-label radio">是否下载图片</label>
                        <div class="controls">
                            <label class="radio-inline">
                                <input type="radio" name="@(dr["name"].ToString())_is_download" id="@(dr["name"].ToString())_is_download" value="1">是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="@(dr["name"].ToString())_is_download" id="@(dr["name"].ToString())_is_download" checked value="0">否
                            </label>
                            <span class="help-block"></span>
                        </div>
                    </div>
                    <div class="control-group @(dr["name"].ToString())_image">
                        <label class="control-label">图片正则</label>
                        <div class="controls form-inline form-group-sm">
                            <input type="text" placeholder="不填写则为默认正则" value="" class="form-control" id="@(dr["name"].ToString())_image" name="@(dr["name"].ToString())_image" style="width:95%" />
                            <span class="help-block">默认正则：&lt;img\b[^&lt;&gt;]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?&lt;imgUrl&gt;[^\s\t\r\n""'&lt;>]*)[^&lt;&gt;]*?/?[\s\t\r\n]*&gt;</span>
                        </div>
                    </div>
                }
                <div class="control-group">
                    <label class="control-label">采集字段</label>
                    <div class="controls form-inline form-group-sm">
                        <input type="text" disabled value="@(dr["name"].ToString())" class="form-control" id="@(dr["name"].ToString())" name="@(dr["name"].ToString())" data-validate="dataType:'*" nullMsg:'请填写采集正则@(dr["name"].ToString())_field!" style="width:95%" />
                        <input type="hidden" value="@(dr["name"].ToString())" class="form-control field" id="@(dr["name"].ToString())_field" name="@(dr["name"].ToString())_field" data-validate="dataType:'*" nullMsg:'请填写采集正则@(dr["name"].ToString())_field!" />
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="control-group @(dr["name"].ToString())_regular">
                    <label class="control-label">采集正则</label>
                    <div class="controls form-inline form-group-sm">
                        <input type="text" value="" class="form-control" id="@(dr["name"].ToString())_regular" name="@(dr["name"].ToString())_regular" data-validate="dataType:'*" nullMsg:'请填写采集正则@(dr["name"].ToString())_regular!" style="width:95%" />
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="control-group @(dr["name"].ToString())_replace_regular">
                    <label class="control-label">过滤正则</label>
                    <div class="controls form-group-sm">
                        <textarea class="form-control" id="@(dr["name"].ToString())_replace_regular" name="@(dr["name"].ToString())_replace_regular" style="width:95%;height:80px"></textarea>
                        <span class="help-block">多条过滤正则用半圆逗号(,)隔开</span>
                    </div>
                </div>
            </div>
        }
    }
    <div class="control-group text-center">
        <label class="control-label"></label>
        <div class="controls form-inline bangding" style="padding:0px;">
            <textarea style="display:none;"  id="detail_rule" name="detail_rule"></textarea>
            <input type="hidden" id="site_id" name="site_id" value="" />
            <input type="hidden" id="column_id" name="column_id" value="" />
            <input type="hidden" id="id" name="id" value="@Request.QueryString["id"]" />
            <button type="button" class="btn btn-primary btn-sm ui-dialog" data-custom-params="title: '测试', url:'@Url.Action("Test")?id=@Request.QueryString["id"]',beforeExecute:'BeforeExecute', width:'70%', height:'80%'">测试</button>
            <button type="button" class="btn btn-primary btn-sm ui-pagePost" data-custom-params="url:'@Url.Action("Save")',beforeExecute:'DetailRule',callBack:'PostRefreshBack'">保存</button>
            <button type="button" class="btn btn-primary btn-sm ui-pagePost DetailRule" data-custom-params="url:'@Url.Action("DetailRule")',callBack:'PostRefreshBack',beforeExecute:'BeforeExecuteAdd'">保存并采集</button>
            <button type="button" class="btn btn-default btn-sm ui-closeDialog">关闭</button>
            <span class="help-block"></span>
        </div>
    </div>
</form>
<script type="text/javascript">
    //绑定数据
    var id =Request("id");
    if (id != "")
    {
        var data = @Html.Raw(Model??"null");
        $(".bangding").FormBind(data);
    }
    $(function () {
        var detail_rule = $("#detail_rule").val();
        var json = eval("(" + detail_rule + ")");
        $(".field").each(function (j) {
            var field = $(this).val();
            $("#" + field + "_regular").val(eval("json[0]." + field + ".regular"))
            $("#" + field + "_replace_regular").val(eval("json[0]." + field + ".replace_regular"))
            if ($("input[value='" + eval("json[0]." + field + ".is_download") + "']").length > 0) {
                $("input[value='" + eval("json[0]." + field + ".is_download") + "']").click();
            }
            if ($("#" + field + "_image").length > 0) {
                $("#" + field + "_image").val(eval("json[0]." + field + ".image"))
            }
        })
    })
    function DetailRule()
    {
        var data = CallAjax("post", false, "@Url.Action("Save")", $(".form").serialize());
        return true;
    }

    function BeforeExecute()
    {
        var data = CallAjax("post", false,"@Url.Action()",$(".form").serialize());
        return true;
    }
    function BeforeExecuteAdd()
    {
        var params = { title: "站点设置", url: "@Url.Action("Set")?id=@Request.QueryString["id"]'", width: "600px", height: "210px", target: '_self'};
        IDialog(params);
        return false;
    }
</script>