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

<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="Whir.Language" %>
<%@ Import Namespace="Whir.Framework" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="Server">
    <div class="content-wrap">
        <div class="space15"></div>
        <div class="panel">

            <div class="panel-body">

                <section class="panel">
                         <% if (CurrentColumn.ColumnId == 0)
                             { %>
                            <ul class="nav nav-tabs">
                                <li><a href="ColumnList.aspx" aria-expanded="true"><%="栏目管理".ToLang() %></a></li>
                                <li class="active"><a data-toggle="tab" href="#single" aria-expanded="true">单条添加</a></li>
                                  <li class=""><a data-toggle="tab" href="#multi" aria-expanded="false">批量添加</a></li>
                            </ul>
                        <% } %>
                        <% else if (CurrentColumn.ColumnId != 0)
                            { %>
                            <ul class="nav nav-tabs">
                                <li><a href="ColumnList.aspx" aria-expanded="true"><%="栏目管理".ToLang() %></a></li>
                                 <li class="<%=Type=="base"?"active":"" %>"><a data-toggle="tab" href="#baseTab" aria-expanded="true">基本信息</a></li>
                              <%if (IsDevUser)
                                  {%>
                                   <li class="<%=Type=="advanced"?"active":"" %>"><a data-toggle="tab" href="#advancedTab" aria-expanded="false">高级设置</a></li>
                                <%} %>
                                 <li class="<%=Type=="seo"?"active":"" %>"><a data-toggle="tab" href="#seoTab" aria-expanded="false">SEO设置</a></li>
                            </ul>
                        <% } %>
                        <div class="panel-body">
                            <div class="tab-content">
                              <div id="single" class="tab-pane active">
                                <form id="formSingle" class="form-horizontal" form-url="<%=SysPath%>Handler/Developer/Column.aspx">
                                         <div class="tab-content">
                                          <div id="baseTab" class="tab-pane <%=Type=="base"?"active":"" %> <%=CurrentColumn.ColumnId ==0?"active":"" %>">
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ParentId"><%="上级栏目：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <select id="ParentId" name="ParentId" class="form-control">
                                                    <option value="0">请选择</option>
                                                    <% foreach (var column in ColumnTreeList)
                                                        {
                                                            %>
                                                    <option value="<%=column.ColumnId%>"><%=column.ColumnName%></option>
                                                    <%  }   %>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ModelId"><%="功能模块：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <select id="ModelId" name="ModelId" class="form-control">
                                                    <option value="0">请选择</option>
                                                    <% foreach (var model in AllModel.Where(p => p.ParentId == 0 && !p.IsDel))
                                                        {
                                                            %>
                                                    <option value="<%=model.ModelId%>"><%=model.ModelName%></option>
                                                    <%  }   %>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ColumnName"><%="栏目名称：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="ColumnName" name="ColumnName" class="form-control" value="<%=CurrentColumn.ColumnName%>"
                                                       required="true"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ColumnNameStage"><%="栏目别名：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="ColumnNameStage" name="ColumnNameStage" class="form-control" value="<%=CurrentColumn.ColumnNameStage%>"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="Path"><%="英文目录：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="Path" name="Path" class="form-control" value="<%=CurrentColumn.Path%>"/>
                                            </div>
                                        </div>
                                            </div>
                                          <div id="advancedTab" class="tab-pane  <%=Type=="advanced"?"active":"" %>">
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="DefaultTemp"><%="栏目首页模板：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <div class="input-group ">
                                                    <input id="DefaultTemp" name="DefaultTemp" class="form-control" readonly="readonly" value="<%=CurrentColumn.DefaultTemp%>" />
                                                    <span class="input-group-addon pointer" for="DefaultTemp" dialog-url="TemplateSelector.aspx">选择</span>
                                                    <span class="input-group-addon pointer" onclick="$('#DefaultTemp').val('');">清空</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ListTemp"><%="列表页模板：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <div class="input-group ">
                                                    <input id="ListTemp" name="ListTemp" class="form-control" readonly="readonly" value="<%=CurrentColumn.ListTemp%>" />
                                                    <span class="input-group-addon pointer" for="ListTemp" dialog-url="TemplateSelector.aspx">选择</span>
                                                    <span class="input-group-addon pointer" onclick="$('#ListTemp').val('');">清空</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ContentTemp"><%="详细页模板：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <div class="input-group ">
                                                    <input id="ContentTemp" name="ContentTemp" class="form-control" readonly="readonly" value="<%=CurrentColumn.ContentTemp%>" />
                                                    <span class="input-group-addon pointer" for="ContentTemp" dialog-url="TemplateSelector.aspx">选择</span>
                                                    <span class="input-group-addon pointer" onclick="$('#ContentTemp').val('');">清空</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="PreviewTemp"><%="预览页模板：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <div class="input-group ">
                                                    <input id="PreviewTemp" name="PreviewTemp" class="form-control" readonly="readonly" value="<%=CurrentColumn.PreviewTemp%>" />
                                                    <span class="input-group-addon pointer" for="PreviewTemp" dialog-url="TemplateSelector.aspx">选择</span>
                                                    <span class="input-group-addon pointer" onclick="$('#PreviewTemp').val('');">清空</span>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 text-right" for="PreviewTemp"><%="生成模式：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <ul class="list">
                                                    <li>
                                                        <input type="radio" id="CreateMode_No" name="CreateMode" value="0" />
                                                        <label for="CreateMode_No">不生成</label>
                                                    </li>
                                                    <li>
                                                        <input type="radio" id="CreateMode_Static" name="CreateMode" value="1" />
                                                        <label for="CreateMode_Static">生成静态</label>
                                                    </li>
                                                    <li>
                                                        <input type="radio" id="CreateMode_Dynamic" name="CreateMode" value="2" />
                                                        <label for="CreateMode_Dynamic">生成动态</label>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="PreviewTemp"><%="导航链接地址：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="LocationUrl" name="LocationUrl" class="form-control" value="<%=CurrentColumn.LocationUrl%>"
                                                        ValidationExpression="http[s]?:\/\/([\w-]+\.)+[\w-]+([\w-./?%&=]*)|([\w-./?%&=]*)"
                                                     />
                                                <span class="note_gray"><%="以“http://”开始代表外网地址，以“/”开始代表本站根目录，最多可输入1024个字符".ToLang()%></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="WorkFlow"><%="工作流定义：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <select id="WorkFlow" name="WorkFlow" class="form-control">
                                                    <option value="0">请选择</option>
                                                    <% foreach (var flow in AllWorkFlow)
                                                        {
                                                        %>
                                                    <option value="<%=flow.WorkFlowId%>"><%=flow.WorkFlowName%></option>
                                                    <%  }   %>
                                                </select>
                                                <span class="note_gray"><%="修改工作流会导致该栏目信息所有审核状态重置".ToLang()%></span>
                                            </div>
                                        </div>
                                       <div class="form-group" >
                                            <div class="col-md-2 control-label" for="CategoryLevel"><%="单独类别级数：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="CategoryLevel" name="CategoryLevel" class="form-control" value="<%=CurrentColumn.CategoryLevel%>"
                                                        ValidationExpression="[0-9]*[1-9][0-9]*"   <%=CurrentColumn.ColumnId !=0&&CurrentColumn.IsCategory?" min='1'":"" %>  />
                                                <span class="note_gray"><%="必须输入大于等于1的正整数".ToLang()%></span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 text-right" ><%="其它设置：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <ul class="list">
                                                    <%if (CurrentColumn.ModuleMark != null && (CurrentColumn.ModuleMark.ToLower() == "content_v0.0.01" ||
                                                                 CurrentColumn.ModuleMark.ToLower() == "subsitecontent_v0.0.01"))
                                                        { %>
                                                    <li>
                                                        <input type="checkbox" id="IsRelated" value="1" />
                                                        <label for="IsRelated">启用相关文章</label>
                                                           <input type="hidden"  name="IsRelated"  />
                                                    </li>

                                                    <li>
                                                        <input type="checkbox" id="IsRedirect" value="1" />
                                                        <label for="IsRedirect">启用转向链接</label>
                                                           <input type="hidden"  name="IsRedirect"  />
                                                    </li>
                                                    <%} %>
                                                    <%if (Whir.Service.ServiceFactory.ColumnService.IsCategoryParent(ColumnId))
                                                        { %>
                                                    <li>
                                                        <input type="checkbox" id="IsCategory" value="1" />
                                                        <label for="IsCategory">启用单独类别</label>
                                                        <input type="hidden"  name="IsCategory"  />
                                                    </li>
                                                    <%} %>
                                                </ul>
                                            </div>
                                        </div>
                                            <div class="form-group" id="divIsCategoryPower">
                                                <div class="col-md-2 text-right" for="IsCategoryPower"><%="启用类别权限：".ToLang()%></div>
                                                <div class="col-md-10 ">
                                                    <ul class="list">
                                                        <li>
                                                            <input type="radio" id="IsCategoryPower_True" name="IsCategoryPower" value="1" />
                                                            <label for="IsCategoryPower_True">启用</label>
                                                        </li>
                                                        <li>
                                                            <input type="radio" id="IsCategoryPower_False" name="IsCategoryPower" value="0" />
                                                            <label for="IsCategoryPower_False">不启用</label>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </div>
                                          </div>
                                          <div id="seoTab" class="tab-pane <%=Type=="seo"?"active":"" %>">
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="MetaTitle"><%="SEO标题：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <input id="MetaTitle" name="MetaTitle" class="form-control" maxlength="200" value="<%=CurrentColumn.MetaTitle%>"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="MetaKeyword"><%="SEO关键字：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                               <textarea id="MetaKeyword" name="MetaKeyword" class="form-control" maxlength="200"><%=CurrentColumn.MetaKeyword%></textarea>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="MetaDesc"><%="SEO描述：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <textarea id="MetaDesc" name="MetaDesc" class="form-control" maxlength="200"><%=CurrentColumn.MetaDesc%></textarea>
                                            </div>
                                        </div>
                                              </div>
                                          <div class="form-group">
                                                <div class="col-md-offset-2 col-md-10 ">
                                                    <input type="hidden" name="ColumnId" Value="<%=CurrentColumn.ColumnId%>" />
                                                    <input type="hidden" name="SiteId" value="<%=CurrentSiteID%>" />
                                                    <input type="hidden" name="CreateDate" value="<%=CurrentColumn.CreateDate.Value(DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss")%>"/> 
                                                    <input type="hidden" name="CreateUser" value="<%=CurrentColumn.CreateUser??CurrentUserName%>"/> 
                                                    <input type="hidden" name="UpdateDate" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")%>"/> 
                                                    <input type="hidden" name="UpdateUser" value="<%=CurrentUserName%>"/> 
                                                    <input type="hidden" name="_action" value="Save"/>
                                                    <div class="btn-group">
                                                        <button form-action="submitSingle" form-success="back" class="btn btn-info"><%="提交并返回".ToLang()%></button>
                                                        <% if (ColumnId == 0)
                                                            { %>
                                                        <button form-action="submitSingle" form-success="refresh" class="btn btn-info"><%= "提交并继续".ToLang() %></button>
                                                        <% } %>
                                                    </div>
                                                    <a class="btn btn-white" href="ColumnList.aspx"><%="返回".ToLang()%></a>
                                                </div>
                                            </div>
                                         </div>
                                    </form>
                                </div>
                                <div id="multi" class="tab-pane">
                                    <form id="formMulti" class="form-horizontal" form-url="<%=SysPath%>Handler/Developer/Column.aspx">
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="ParentId"><%="上级栏目：".ToLang()%></div>
                                            <div class="col-md-10 ">
                                                <select   name="ParentId" class="form-control">
                                                    <option value="0">请选择</option>
                                                    <% foreach (var column in ColumnTreeList)
                                                        {
                                                            %>
                                                    <option value="<%=column.ColumnId%>"><%=column.ColumnName%></option>
                                                    <%  }   %>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-2 control-label" for="BatchColumnName"><%="栏目名称：".ToLang()%></div>
                                            <div class="col-md-5">
                                                <textarea name="BatchColumnName" class="form-control" rows="10" required="true" ></textarea>
                                            </div>
                                            <div class="col-md-5 alert alert-info">
                                                <strong><%="注意：".ToLang()%></strong><br />
                                                <%="1．每行填写一个栏目".ToLang()%><br />
                                                <%="2．子栏目相对父栏目使用“-”缩进".ToLang()%><br />
                                                <strong><%="示例：".ToLang()%></strong><br />
                                                <%="栏目一".ToLang()%><br />
                                                <%="-下级栏目一".ToLang()%><br />
                                                <%="--下下级栏一".ToLang()%><br />
                                                <%="-下级栏目二".ToLang()%><br />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <div class="col-md-offset-2 col-md-10 ">
                                                <input type="hidden" name="ColumnId" value="<%=CurrentColumn.ColumnId%>" />
                                                <input type="hidden" name="SiteId" value="<%=CurrentSiteID%>" />
                                                <input type="hidden" name="CreateDate" value="<%=CurrentColumn.CreateDate.Value(DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss")%>"/> 
                                                <input type="hidden" name="CreateUser" value="<%=CurrentColumn.CreateUser??CurrentUserName%>"/> 
                                                <input type="hidden" name="UpdateDate" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")%>"/> 
                                                <input type="hidden" name="UpdateUser" value="<%=CurrentUserName%>"/> 
                                                <input type="hidden" name="_action" value="SaveMulti"/>
                                                <div class="btn-group">
                                                    <button form-action="submitMulti" form-success="back" class="btn btn-info"><%="提交并返回".ToLang()%></button>
                                                    <% if (ColumnId == 0)
                                                        { %>
                                                    <button form-action="submitMulti" form-success="refresh" class="btn btn-info"><%= "提交并继续".ToLang() %></button>
                                                    <% } %>
                                                </div>
                                                <a class="btn btn-white" href="ColumnList.aspx"><%="返回".ToLang()%></a>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>

            </div>

        </div>
    </div>
    <script type="text/javascript">

        //弹出层
        $("[dialog-url]").click(function () {
            var dialogUrl = $(this).attr("dialog-url");
            var targetControl = $(this).attr("for");

            var dialog = whir.dialog.frame("选择模板", dialogUrl, function () {
                var frameDocument = dialog.find("iframe").contents();
                var checked = frameDocument.find("input[type='radio'][name='template']:checked");
                if (checked.length != 1) {
                    whir.toastr.warning("请选择一个模板");
                    return;
                }
                $(document.getElementById(targetControl)).val(checked.val());
                dialog.remove();
            }, 800);
        });

        //选择事件
        $(document).ready(function () {
           
            $("#IsCategory")
                .next()
                .click(function () {
                    Change();
                });
            $("#IsCategory")
                .parent()
                .next()
                .click(function () {
                    Change();
                });
        });

        function checkCheckbox() {
            
            if ($("#IsRedirect").prop("checked")) {
                $("[name='IsRedirect']").val(1);
            }
            else
                $("[name='IsRedirect']").val(0);

            if ($("#IsRelated").prop("checked")) {
                $("[name='IsRelated']").val(1);
            }
            else
                $("[name='IsRelated']").val(0);
        }

        function Change() {
           
            if ($("#IsCategory").prop("checked")) {
                $("input[name='IsCategory']").val(1);
                $("#divIsCategoryPower").show();
            } else {
                $("input[name='IsCategory']").val(0);
                $("#divIsCategoryPower").hide();
                $("#IsCategoryPower_False").iCheck("check");
            }
        }
        //绑定值
        $("[name='ParentId']").val("<%=CurrentColumn.ParentId%>");
        $("[name='ModelId']").val("<%=CurrentColumn.ModelId%>");
        $("[name='WorkFlow']").val("<%=CurrentColumn.WorkFlow%>");
        $("[name='CreateMode'][value='<%=CurrentColumn.CreateMode%>']").prop("checked", "checked");
        $("#IsRelated[value='<%=CurrentColumn.IsRelated.ToInt()%>']").prop("checked", "checked");
        $("#IsRedirect[value='<%=CurrentColumn.IsRedirect.ToInt()%>']").prop("checked", "checked");
        $("#IsCategory[value='<%=CurrentColumn.IsCategory.ToInt()%>']").prop("checked", "checked");
        $("[name='IsCategoryPower'][value='<%=CurrentColumn.IsCategoryPower.ToInt()%>']").prop("checked", "checked");
        Change();
        //提交内容
        var options = {
            fields: {
                ColumnName: {
                    validators: {
                        notEmpty: {
                            message: '<%="栏目名称为必填项".ToLang() %>'
                        }
                    }
                }, CategoryLevel: {
                    validators: {
                        integer: {
                            message: '<%="单独类别级数只能是数字".ToLang() %>'
                        },
                      
                    }
                },
                Path: {
                    validators: {
                        regexp: {
                            regexp: /^[a-zA-Z0-9]{1,12}$/i,
                            message: '<%="英文目录只能是1-12个英文或数字".ToLang() %>'
                        }
                    }
                },
                LocationUrl: {
                    validators: {
                        regexp: {
                            regexp: /(^\/.*)|(^(http|https):\/\/.*)/,   //还要修改
                            message: '<%="请输入正确网址".ToLang() %>'
                        }
                    }
                }
            },
            submitButtons: '[form-action="submitSingle"]'
        };
        $('#formSingle').Validator(options,
             function (el) {
                 var actionSuccess = el.attr("form-success");
                 var $form = $("#formSingle");
                 checkCheckbox();
                 $form.post({
                     success: function (response) {
                         if (response.Status == true) {
                             actionSuccess == "refresh" ? whir.toastr.success(response.Message, true, false) : whir.toastr.success(response.Message, true, false, "ColumnList.aspx");
                         } else {
                             whir.toastr.error(response.Message);
                         }
                         whir.loading.remove();
                     },
                     error: function (response) {
                         whir.toastr.error(response.Message);
                         whir.loading.remove();
                     }
                 });
                 return false;
             });

        //提交内容
        var options = {
            submitButtons: '[form-action="submitMulti"]'
        };
        $('#formMulti').Validator(options,
        function (el) {
            var actionSuccess = el.attr("form-success");

            var $form = $("#formMulti");
            $form.post({
                success: function (response) {
                    if (response.Status == true) {
                        actionSuccess == "refresh" ? whir.toastr.success(response.Message, true, false) : whir.toastr.success(response.Message, true, false, "ColumnList.aspx");

                    } else {
                        whir.toastr.error(response.Message);
                    }
                    whir.loading.remove();
                },
                error: function (response) {
                    whir.toastr.error(response.Message);
                    whir.loading.remove();
                }
            });
            return false;
        });

    </script>
</asp:content>
