<%@ Page Title="" Language="C#" MasterPageFile="~/whir_system/master/SystemMasterPage.master"
    AutoEventWireup="true" CodeFile="CollectStep3.aspx.cs" Inherits="Whir_System_Module_Extension_CollectStep3" %>

<%@ Import Namespace="Whir.Language" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
        h3 {
            text-align: center;
            font-size: 12px;
        }
        h3 span {
            margin: 0px 10px 0px 10px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="content-wrap">
        <div class="space15"></div>
        <div class="panel">
            <div class="panel-heading" align='center'>
                <span>第一步:基本设置</span>&nbsp;
                <i class="fa fa-lg fa-angle-right"></i>&nbsp;
                <span>第二步:列表页规则设置</span>&nbsp;
                <i class="fa fa-lg fa-angle-right"></i>&nbsp;
                <span class="text-danger"><b>第三步:内容页规则设置</b></span>&nbsp;
                <i class="fa fa-lg fa-angle-right"></i>&nbsp;
                <span>完成</span>
            </div>
            <div class="panel-body">
                <div class="form_center">
                    <form id="formEdit" class="form-horizontal" form-url="<%=SysPath%>Handler/Extension/Collect.aspx">
                        <div class="form-group">
                            <div class="col-md-2 text-right">所属采集栏目</div>
                            <div class="col-md-10 "><b><asp:Label ID="lblItemName" runat="server"></asp:Label></b></div>
                        </div>
                        <asp:Repeater ID="rptList" runat="server">
                            <ItemTemplate>
                                <div class="form-group">
                                    <div class="col-md-2 control-label" for="<%#Eval("FormId")%>">
                                        <%#Eval("FieldAlias")%>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="input-group">
                                            <span class="input-group-addon" style="width: 50%;">
                                                <input type="radio" class="defaultradio" id="radDefault<%#Eval("FormId")%>" name="<%#Eval("FormId")%>" checked="checked" value="1" />
                                                <label class="radio-label" for="radDefault<%#Eval("FormId")%>">指定默认值</label>
                                            </span>
                                            <input type="text" class="form-control" style="width: 50%;" value="<%#Eval("DefaultValue")%>" formid="<%#Eval("FormId")%>" />
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <input type="radio" class="ruleradio" id="radRule<%#Eval("FormId")%>" name="<%#Eval("FormId")%>" value="2" />
                                                <label class="radio-label" for="radRule<%#Eval("FormId")%>">使用采集规则</label>
                                            </span>
                                            <a class="btn btn-white input-group-addon" onclick="openSetRule(<%#Eval("FormId") %>,<%=CollectId %>)">设置采集规则</a>
                                        </div>
                                    </div>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                        <div class="button_submit_div text-center">
                            <input type="hidden" name="_action" value="Finished" />
                            <input type="hidden" name="hidValue" value="" />
                            <input type="hidden" name="CollectId" value="<%=CollectId %>" />
                            <div class="btn-group">
                                <a class="btn btn-info" href="CollectStep2.aspx?collectid=<%=CollectId %>">上一步</a>
                                <button form-action="submit" form-success="refresh" class="btn btn-info"><%="完成".ToLang()%></button>
                            </div>
                            <a class="btn text-danger border-danger" href="CollectList.aspx">返回采集管理</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var data = <%=GetEditInfo() %>;
        for (var i = 0; i < data.length; i++) {
            if (data[i].CollectType == 2) {//选择值类型
                $("#tableFields :radio[name='" + data[i].FormID + "'][value='2']").attr("checked", "checked");
            }
            //默认值
            $("#tableFields .defaultvalue[formid='" + data[i].FormID + "']").val(data[i].DefaultValue);
        }
        //指定默认值点击
        $(".defaultradio").click(function(){
            if($(this).attr("checked")){
                $(this).parents("tr:eq(0)").find(".defaultvalue").removeAttr("disabled");
            }
        });
        //设置规则点击
        $(".ruleradio").click(function(){
            if($(this).attr("checked")){
                $(this).parents("tr:eq(0)").find(".defaultvalue").attr("disabled","disabled");
                $(this).parents("tr:eq(0)").find(".defaultvalue").val("");
            }
        });

        $(".ruleradio:checked").click();
        
        ///获取保存数据
        function GetDataStr() {
            var str = "";
            $("#tableFields tr").each(function () {
                var type = $(this).find(":radio[checked]");
                str += type.attr("name") + "§" + type.val() + "§" + $(this).find(".defaultvalue").val() + "□";
            });
            $("[name=hidValue]").val(str);
        }

        function openSetRule(formid, collectid) {
            BootstrapDialog.show({
                title: "设置规则",
                message: $('<div></div>')
                    .load("CollectFieldSetRule.aspx?formid=" + formid + "&collectid=" + collectid),
                size: BootstrapDialog.SIZE_WIDE,
                buttons: [
                    {
                        label: '保存',
                        cssClass: 'btn-primary',
                        action: function(dialogItself) {
                            if ($("#TextStart").val() === "" || $("#TextEnd").val() === "") {
                                whir.dialog.alert("<%="字段代码不能为空！".ToLang()%>");
                            } else {
                                $.ajax({
                                    type: "POST",
                                    url: "<%=SysPath %>Handler/Extension/Collect.aspx",
                                    data: {_action:'Finish', formid:formid,collectid:collectid, TextStart: $("#TextStart").val(), TextEnd: $("#TextEnd").val() },
                                    success: function(response) {
                                        response = eval('(' + response + ')');
                                        if (response.Status == true) {
                                            dialogItself.close();
                                            whir.toastr.success(response.Message);
                                        } else {
                                            whir.dialog.alert(response.Message);
                                        }

                                    },
                                    error: function(msg) {
                                       
                                    }
                                });
                            }
                        }
                    }, {
                        label: '取消',
                        action: function(dialogItself) {
                            dialogItself.close();
                        }
                    }
                ]
            });
        }

        //提交内容
        $("[form-action='submit']").click(function() {
            GetDataStr();
                var actionSuccess = $(this).attr("form-success");
                var $form = $("#formEdit");
                $form.post({
                    success: function(response) {
                        if (response.Status == true) {
                            whir.toastr.success(response.Message);
                        } else {
                            whir.dialog.alert(response.Message);
                        }
                         whir.loading.remove();
                    },
                    error: function(response) {
                        whir.toastr.error(response.Message);
                        whir.loading.remove();
                    }
                });
                return false;
           
        });
         
    </script>
</asp:Content>
