@using Common;
@model string

<form class="form-horizontal form ui-validForm" action="@Url.Action()" method="post">
    @if (ViewBag.FieldName.IndexOf("请设置采集字段!") != -1)
    {
        <script>
                $(function () {
                    Msg("@ViewBag.FieldName")
                })
        </script>
    }
    else
    {
        foreach (var fieldName in ViewBag.FieldName.Split(','))
        {
            <div class="main item" style="margin-bottom:15px;" id="box_@fieldName">
                <div class="control-group">
                    <label class="control-label">采集字段</label>
                    <div class="controls form-inline form-group-sm">
                        <input type="text" disabled value="@(fieldName)" class="form-control" id="@(fieldName)" name="@(fieldName)" data-validate="dataType:'*" nullMsg:'请填写采集正则@(fieldName)_field!" style="width:80%" />
                        <input type="hidden" value="@(fieldName)" class="form-control" id="@(fieldName)_field" name="@(fieldName)_field" data-validate="dataType:'*" nullMsg:'请填写采集正则@(fieldName)_field!" />
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="control-group @(fieldName)_regular">
                    <label class="control-label">采集正则</label>
                    <div class="controls form-inline form-group-sm">
                        <input type="text" value="" class="form-control" id="@(fieldName)_regular" name="@(fieldName)_regular" data-validate="dataType:'*" nullMsg:'请填写采集正则@(fieldName)_regular!" style="width:80%" />
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="control-group @(fieldName)_replace_regular">
                    <label class="control-label">过滤正则</label>
                    <div class="controls form-group-sm">
                        <input type="text" value="" class="form-control" id="@(fieldName)_replace_regular" name="@(fieldName)_replace_regular" style="width:80%" />
                        <span class="help-block"></span>
                    </div>
                </div>
            </div>
        }
    }

    <div class="control-group text-center">
        <label class="control-label"></label>
        <div class="controls form-inline" style="padding:0px;">
            <input type="hidden" id="collection_id" name="collection_id" value="@Request.QueryString["collection_id"]" />
            <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="{id}" />
            <button type="button" class="btn btn-primary btn-sm ui-dialog" params = "title: '测试', url:'@Url.Action("Test")?collection_id=@Request.QueryString["collection_id"]',beforeExecute:'BeforeExecute', width:'80%', height:'80%'">测试</button>
            <button type="button" class="btn btn-primary btn-sm ui-pagePost" data-custom-params="url:'@Url.Action()',callBack:'PostRefreshBack',beforeExecute:'BeforeExecuteAdd'" id="bt_submit">提交</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 getCollectionDetailRule = CallAjax("get", false, "@Url.Action("GetCollectionDetailRule")", "collection_id=@Request.QueryString["collection_id"]");
    if (getCollectionDetailRule != "") {
        json = eval(getCollectionDetailRule)
        for (var i in json) {
            var regular = json[i].field + "_regular";
            var replace_regular = json[i].field + "_replace_regular";
            $("#" + regular).val(json[i].regular);
            $("#" + replace_regular).val(json[i].replace_regular)
        }
    }
    function BeforeExecute()
    {
        var data = CallAjax("post", false,"@Url.Action("Test")",$(".form").serialize());
        return true;
    }
    function BeforeExecuteAdd()
    {
        var params = { title: "站点设置", url: "@Url.Action("Set")", width: "80%", height: "210px", target: '_self'};
        IDialog(params);
        return false;
    }
</script>