<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sms_tempate_edit.aspx.cs" Inherits="VA.Modules.JDingMember.sms.sms_tempate_edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>短信模板编辑</title>
    <!--#include virtual="/include/css/edit.aspx"-->
    <!--#include virtual="/include/js/edit.aspx"-->     
    
    <script type="text/javascript">
        function save(flag) {

            //调用asp.net验证控件自带的js数据验证脚本对控件进行验证；
            var validationResult = Page_ClientValidate('');
            if (!validationResult) {
                return;
            }

            var flag = "0";
            if ($("#hfKey").val() != "") {
                flag = "1";
            }

            if (flag == 0) {
                add();
            }
            else {
                update();
            }
        }

        function add() {
            var requestType = "POST";
            var url = pageName + "?act=add";  //pageName在BasePage中注册到的客户端；
            var dataType = "html";
            var data = $("form").eq(0).serialize();
            var successFN = function (data, textStatus) {
                if (data == "ok") {
                    showActResult("添加成功！", true, doAfterAdd);
                } else if (data.indexOf("01|") != -1) {
                    showActResult(data.substring(3), false, doAfterAdd);
                }
                else {
                    showActResult("添加失败：" + data, false, doAfterAdd);
                }
            };
            ajaxRequest(requestType,
                url,
                dataType,
                data,
                successFN,
                errorFN
                );
        }

        function update() {
            var requestType = "POST";
            var url = pageName + "?act=update";
            var dataType = "html";
            var data = $("form").eq(0).serialize();
            var successFN = function (data, textStatus) {
                if (data == "ok") {
                    showActResult("修改成功！", true, doAfterUpdate);
                } else if (data.indexOf("01|") != -1) {
                    showActResult(data.substring(3), false, doAfterUpdate);
                }
                else {
                    showActResult("修改失败：" + data, false, doAfterUpdate);
                }
            };
            ajaxRequest(requestType,
                url,
                dataType,
                data,
                successFN,
                errorFN
                );
        }

        function doAfterAdd(actResult) {
            if (actResult) {
                try {
                    if (window.parent != window.self) {
                        window.parent.completeReload();
                    }
                } catch (e) { alert(e); }
                resetPage();
            }
        }
        function doAfterUpdate(actResult) {
            if (actResult) {
                try {
                    if (window.parent != window.self) {
                        window.parent.closeFrameWindow();
                        window.parent.completeReload();
                    }
                } catch (e) { }
            }
        }

        function resetPage() {

            $("#txtTitle").val("");
            $("#txtContent").val("");

            clearInputValidatorError();

            $("#txtContent").focus();
        }

        function statContentLength() {
            var length = $("#txtContent").val().length;
            //$("#lblContentLength").html("建议短信内容在80个汉字以内。 当前已 " + length + " 个字.");
            $("#lblContentLength").html("建议短信内容在70个汉字左右。 当前已 " + length + " 个字符.");
        }

        $.fn.pasteEvents = function (delay) {
            if (delay == undefined) delay = 20;
            return $(this).each(function () {
                var $el = $(this);
                $el.on("paste", function () {
                    $el.trigger("prepaste");
                    setTimeout(function () { $el.trigger("postpaste"); }, delay);
                });
            });
        };

        $(function () {
            $("#txtContent").focus();
            $("#txtContent").keydown(function () {
                statContentLength();
            });

            $("#txtContent").on("postpaste", function () {
                statContentLength();
            }).pasteEvents();
        });

    </script>

</head>
<body>
<form id="Form1" method="post" runat="server">

<div class="editPageWrapper" style="width:660px;">

<%
    if (VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevel == VA.Modules.JDingMember.Core.Enums.SoftLevel.Free ||
        VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevel == VA.Modules.JDingMember.Core.Enums.SoftLevel.Basic)
    {
        base.ShowSoftFunctionLimitNote(VA.Modules.JDingMember.Core.SystemInfo.SoftInfo.SoftLevelName);
    }
%>

<%--<div class="centerFormTitle">
   <h1>会员登记</h1>
</div>
--%>
<table cellspacing="0" cellpadding="3" class="editTable">
<tr id="trEditResult" runat="server" visible="false">
<td colspan="2" style="text-align:center;">
    <div class="editResult">
    <asp:Literal id="litEditResult" runat="server" />
    </div>
</td>
</tr>
<tr style="display:none;">
<td class="th">(<span class="note mustfill">*</span>)模板名称：</td>
<td>              
    <VACTL:TextBox ID="txtTitle" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="400px"
            CanBeNull="No"
            FieldName="标题"
            MaxLength="100" />             
</td>
</tr>
<tr>
<td class="th">所属分类：</td>
<td>
    <asp:DropDownList ID="ddlCategory" Runat="server" Width="104px" >    
    </asp:DropDownList>
<%--    <asp:RequiredFieldValidator runat="server"
         ControlToValidate="ddlCategory"
         ErrorMessage="[所属分类]必须选择一项！" />--%>
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)模板内容：</td>
<td>              
    <VACTL:TextBox ID="txtContent" Runat="server"
            EnableViewState="False"
            CssClass="input"
            Width="540px"
            Height="60px"
            CanBeNull="No"
            TextMode="MultiLine"
            FieldName="模板内容"
            MaxLength="300" />   
    <br />      
    <asp:Label ID="lblContentLength" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="th">(<span class="note mustfill">*</span>)占位变量：</td>
<td>              
    {ShopName}:店名
</td>
</tr>
<tr>
<td colspan="2" class="footer">                        
    <% if (base.flag == 0) { %>
    <input type="button" id="btnSubmit" class="btn" style="width:100px" onclick="save()" value="保存" />
    <input type="button" id="btnClear" class="btn" style="width:100px" onclick="resetPage()" value="重置" />
    <% } else { %>
    <input type="button" id="btnSubmit" class="btn" style="width:100px" onclick="save()" value="保存" />
    <% } %>    

    <script type="text/javascript">
        statContentLength();
    </script>
    
    <asp:HiddenField ID="hfKey" runat="server" />
    
    <VACTL:Hint ID="Hint1" runat="server" HintImageUrl="/app_themes/default/images/textbox" />
    <VACTL:ValidationSummary ID="ValidationSummary1" runat="server"
            DisplayMode="List"
            EnableClientScript="true" />
    
    <!--注意：这个文件一定要放到页面底部，以便覆盖asp.net验证脚本中的同名函数-->
    <script type="text/javascript" src="/scripts/utils/aspnet_validator_extend.js"></script>
</td>

</tr>
</table>

</div><!--editPageWrapper.END-->

</form>
</body>
</html>

