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

<%@ Import Namespace="Whir.Language" %>
<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" src="<%= AppName %>Editor/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="<%= AppName %>Editor/ueditor/ueditor.all.js"></script>
    <script type="text/javascript" language="javascript">
        //插入标签
        function Insert(insertTxt, q) {
            var eidtorType = "kindeditor";

            if (eidtorType == "kindeditor")//KindEditor
            {
                editorEditor1.focus();
                editorEditor1.insertHtml(insertTxt);
            }
            else if (eidtorType == "ewebeditor")//ewebeditor编辑器
            {
                var obj = document.getElementById("ifmEWebEditor").contentWindow;
                obj.setMode("EDIT");
                obj.insertHTML(insertTxt);
            }
            else if (eidtorType == "ueditor") {
                ueEditor1.execCommand("inserthtml", insertTxt);
            }
        }

        function checkFail() {
            var failEmail = $("#FailEmail").val();
            if (failEmail == '') {
                TipError('<%="发送失败，邮箱为空不能发送".ToLang() %>');
                return false;
            }
            else if ($("#Title").val() == '') {
                TipMessage('<%="邮件标题不能为空".ToLang() %>');
                return false;
            }
            else {
                __doPostBack('btnSendFail', '');
            }
            return false;
        }
    </script>
</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">
                <ul class="nav nav-tabs">
                    <li><a href="EmailMass.aspx" aria-expanded="true">邮件群发</a></li>
                    <li><a href="SendEmailLog.aspx" aria-expanded="true">发送记录</a></li>
                    <li class="active"><a data-toggle="tab" href="<%=Request.Url%>" aria-expanded="true">编辑发送记录</a></li>
                </ul>
                <div class="space15"></div>
                <div class="form_center">
                    <form id="formEdit" class="form-horizontal" form-url="<%=SysPath%>Handler/Plugin/SendEmailRecord.aspx">
                        <div class="form-group">
                            <div class="col-md-2 text-right" for="SendType">
                                <%="发送方式：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <asp:Literal ID="ltCatgory" runat="server"></asp:Literal><asp:Literal ID="ltGroupName"
                                    runat="server"></asp:Literal>
                            </div>
                        </div>
                        <div class="form-group" id="div_byMember">
                            <div class="col-md-2 control-label" for="SuccessEmail">
                                <%="已发送邮箱：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <textarea id="SuccessEmail" name="SuccessEmail" value="" class="form-control" maxlength="2000"><%=CurrentRecord.SuccessEmail%></textarea>
                            </div>
                        </div>
                        <div class="form-group" id="div1">
                            <div class="col-md-2 control-label" for="FailEmail">
                                <%="未发送邮箱：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <input type="text" id="FailEmail" name="FailEmail" value="<%=CurrentRecord.FailEmail%>" class="form-control"
                                    readonly='readonly' rows="5" validationexpression="(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*;)*"
                                    maxlength="600" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-2 control-label" for="Title">
                                <%="邮件标题：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <input type="text" id="Title" name="Title" value="<%=CurrentRecord.Title%>" class="form-control" required="true"
                                    maxlength="30" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-2 control-label" for="Title">
                                <%="常用标签：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <div id="Div_Mark" runat="Server">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-2 control-label" for="Content">
                                <%="邮件内容：".ToLang() %>
                            </div>
                            <div class="col-md-10 ">
                                <div id="Div2" runat="Server"></div>
                                <textarea id="Content" name="Content" style="width: 700px; height: 300px;"><%=CurrentRecord.Content%></textarea>
                            </div>
                        </div>
                        <script type="text/javascript">

                            // 编辑器 
                            var editorContent;
                            KindEditor.ready(function (K) {
                                editorContent = K.create('#Content', {
                                    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 () {
                                $('#Content').val(editorContent.html());
                            });
                        });
                        </script>
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10 ">
                                <input type="hidden" name="_action" value="Save" />
                                <input type="hidden" name="recordId" value="<%=CurrentRecord.ModelId%>" />
                                <div class="btn-group">
                                    <button form-action="savesubmit" form-success="refresh" class="btn btn-info"><%="重新发送所有".ToLang()%></button>
                                    <button form-action="submit" form-success="refresh" class="btn btn-info"><%="只发送未成功邮箱".ToLang()%></button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        //重新发送所有
        $("[form-action='savesubmit']").click(function() {
            var $form = $("#formEdit");
            var data = $("#formEdit").serialize() + "&cmd=resendall";
            var actionSuccess = $(this).attr("form-success");
            subMit($form, actionSuccess, data);
        });

        function subMit(form, actionSuccess, data) {
            if ($("#Title").val() === "") {
                whir.toastr.error("<%="标题不能为空".ToLang() %>");
            } else {
                var $form = form;
                $form.post({
                    data: data,
                    success: function(response) {
                        if (response.Status == true) {
                            whir.toastr.success(response.Message);
                        } else {
                            whir.toastr.error(response.Message);
                        }
                        whir.loading.remove();
                    },
                    error: function(response) {
                        whir.toastr.erro(response.Message);
                        whir.loading.remove();
                    }
                });
                return false;
            }
        }
        //只发送未成功邮箱
        $("[form-action='submit']").click(function() {
            var actionSuccess = $(this).attr("form-success");
            var $form = $("#formEdit");
            var data = $form.serialize() + "&cmd=resendfail";
            subMit($form, actionSuccess, data);
        });
    </script>
</asp:Content>
