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

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link rel="stylesheet" href="<%= AppName %>Editor/KindEditor/themes/default/default.css" />
    <link rel="stylesheet" href="<%= AppName %>Editor/KindEditor/plugins/code/prettify.css" />
    <script charset="utf-8" src="<%= AppName %>Editor/KindEditor/kindeditor.js"></script>
    <script charset="utf-8" src="<%= AppName %>Editor/KindEditor/lang/zh_CN.js"></script>
    <script charset="utf-8" src="<%= AppName %>Editor/KindEditor/plugins/code/prettify.js"></script>
    <script type="text/javascript">
        function openHtml(cid, name, val) {
            $("#txtName").val(name);
            $("#txtHTML").val($("#" + cid).val());
            editorContent.html($("#" + cid).val());
            $("[name='editor']").iCheck("uncheck");
            $("[name='editor'][value='" + val + "']").iCheck("check");
        }
        function canDel() {
            var select = whir.checkbox.getSelect("editor");
            if (select == "") {
                whir.toastr.error("请选择模板");
                return false;
            }
            if ($("#txtName").val() == "") {
                whir.toastr.error("请选择模板");
                return false;
            }
            //whir.dialog.confirm("确定删除该记录吗？", function () {
            //    return true;
            //});
            return confirm("确定删除该记录吗？");
        }

        function canSave() {
            var select = whir.checkbox.getSelect("editor");
            if (select == "") {
                whir.toastr.error("请选择一种编辑器");
                return false;
            }
            if ($("#txtName").val() == "") {
                whir.toastr.error("请输入模板名称");
                return false;
            }
            if (!/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/.test($("#txtName").val())) {
                whir.toastr.error("模板名称只能是字母、数字、中文");
                return false;
            }
            if ($("#txtHTML").val().indexOf("<textarea") > -1 || $("#txtHTML").val().indexOf("</textarea>") > -1) {
                whir.toastr.error("模板HTML内容不能包含textarea标签");
                return false;
            }
            return true;
        }
        // 编辑器 
        var editorContent;
        KindEditor.ready(function (K) {
            editorContent = K.create('#txtHTML', {
                urlType: 'domain', cssPath: '<%= AppName %>Editor/kindEditor/plugins/code/prettify.css',
                uploadJson: '<%= AppName %>Editor/kindEditor/asp.net/upload_json.ashx',
                fileManagerJson: '<%= AppName %>Editor/kindEditor/asp.net/file_manager_json.ashx',
                allowFileManager: true,
                filterMode: false
            });
            //页面点击（包括提交按钮点击）的时候就把编辑器的值传给取值文本框 
            $('body').click(function () {
                $('#txtHTML').val(editorContent.html());
            });
        });
    </script>
</asp:Content>
<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="Server">
    <form runat ="server">
      <div class="content-wrap">
        <div class="space15">
        </div>
        <div class="panel">
        <div class="panel-heading">编辑器模板设置</div>
            <div class="panel-body">
                    <div class="col-md-3">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                编辑器
                            </div>
                            <div class="panel-body">
                             <ul class="list-group">
                                <li class="list-group-item ">eWebEditor
                                </li>
                                <li class="list-group-item padding-left30 line-height25">
                                    <%foreach (var item in eWebEditorList)
                                      { %>
                                    <a href="javascript:openHtml('eWebEditor<%=eWebEditorList.IndexOf(item) %>','<%=item.Name %>',1)" ><%=item.Name %></a>
                                    <textarea style="display:none" id="eWebEditor<%=eWebEditorList.IndexOf(item) %>"><%=item.Html %></textarea>
                                    <br />
                                    <%} %>
                                     
                                </li>
                                <li class="list-group-item ">KindEditor
                                </li>
                                <li class="list-group-item padding-left30 line-height25">
                                    <%foreach (var item in kindEditorList)
                                      { %>
                                    <a href="javascript:openHtml('kindEditor<%=kindEditorList.IndexOf(item) %>','<%=item.Name %>',2)" ><%=item.Name %></a>
                                    <textarea style="display:none" id="kindEditor<%=kindEditorList.IndexOf(item) %>"><%=item.Html %></textarea>
                                    <br />
                                    <%} %>
                                </li>
                                  <li class="list-group-item ">百度编辑器
                                </li>
                                <li class="list-group-item padding-left30 line-height25">
                                    <%foreach (var item in uEditorList)
                                      { %>
                                    <a href="javascript:openHtml('uEditor<%=uEditorList.IndexOf(item) %>','<%=item.Name %>',3)" ><%=item.Name %></a>
                                    <textarea style="display:none"  id="uEditor<%=uEditorList.IndexOf(item) %>"><%=item.Html %></textarea>
                                    <br />
                                    <%} %>
                                </li>
                            </ul>

                            </div>
                        </div>
                    </div>
                    <div class="col-md-9 ">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                模板文件
                            </div>
                            <div class="panel-body  form-horizontal">
                                  
                                 <div class="form-group">
                                    <div class="col-md-2 text-right" >
                                         模板名称：
                                    </div>
                                    <div class="col-md-10 ">
                                        <input type="text" id="txtName" name="txtName"  class="form-control"  required="true" maxlength="10"    />
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <div class="col-md-2 text-right" >
                                         所属编辑器：
                                    </div>
                                    <div class="col-md-10 ">
                                        <ul class="list">
                                            <li>
                                                  <input type="checkbox" id="eWebEditor" name="editor" value="1"  />
                                                        <label for="IsRelated">eWebEditor</label>
                                             </li>
                                             <li>
                                                  <input type="checkbox" id="KindEditor" name="editor" value="2"  />
                                                        <label for="IsRelated">KindEditor</label>
                                             </li>
                                             <li>
                                                  <input type="checkbox" id="uEditor" name="editor" value="3"  />
                                                        <label for="IsRelated">百度编辑器</label>
                                             </li>
                                         </ul>
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <div class="col-md-2 text-right" >
                                         模板HTML：
                                    </div>
                                    <div class="col-md-10 ">
                                         <textarea type="text" id="txtHTML" name="txtHTML" class="form-control" rows="20"></textarea>
                                    </div>
                                     
                                </div>
                                 <div class="form-group">
                                    <div class="col-md-offset-2 col-md-10 ">
                                        <%if (IsCurrentRoleMenuRes("382"))
                                          { %>
                                        <asp:LinkButton ID="btnSave" runat="server" OnClick="btnSave_Click" CssClass="btn btn-info" OnClientClick="return canSave()">保存 </asp:LinkButton>
                                          <%} %>
                                         <%if (IsCurrentRoleMenuRes("383"))
                                           { %>
                                        <asp:LinkButton ID="btnDel" runat="server" OnClick="btnDel_Click" CssClass="btn text-danger border-danger"   OnClientClick="return canDel()">删除 </asp:LinkButton>
                                         <%} %>
                                    </div>
                                 </div>
                                      
                            </div>
                        </div>
                    </div>
            </div>
        </div>
    </div>
    
    </form>
  
</asp:content>

