<%@ Page Title="" Language="C#" MasterPageFile="~/Dialog/DialogMaster.Master" AutoEventWireup="true"
    CodeBehind="MailTemplateEdit.aspx.cs" Inherits="OAWeb.SMSEmail.MailTemplateEdit"
    ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script language="javascript" type="text/javascript" src='<%=ResolveUrl("~/ckeditor/ckeditor.js")%>'></script>
    <style>
        .field_tags
        {
            text-decoration: underline;
        }
    </style>
    <div class="form" style="width: 600px; height: 450px; padding: 10px;">
        <table cellpadding="0" cellspacing="0" border="0" class="table_form">
            <tr>
                <td>
                    模板简称：<asp:TextBox ID="txtTempTitle" CssClass="text width200" runat="server"></asp:TextBox>
                    &nbsp;<asp:DropDownList ID="ddlTempType" runat="server">
                        <asp:ListItem Value="0">选择类型</asp:ListItem>
                    </asp:DropDownList>
                    <asp:CheckBox ID="chkEnabled" runat="server" Text="启用" Checked="True" />
                    <asp:CheckBox ID="chkIsHtml" runat="server" Text="HTML" Checked="True" />
                </td>
            </tr>
            <tr>
                <td>
                    可插入使用标签:<span class="email_tag"></span>
                </td>
            </tr>
            <tr>
                <td>
                    邮件标题：<asp:TextBox ID="txtSubject" runat="server" CssClass="text width400" ></asp:TextBox><span class="tip01"> 标题必须手动复制标签</span>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine"></asp:TextBox>
                    <script type="text/javascript">
                        CKEDITOR.replace('<%=txtContent.ClientID %>',
                    {
                        skin: 'v2',
                        width: '600',
                        height: '200',
                        font_names: '宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;',
                        toolbar: [
                        ['Source', 'Bold', 'Italic', 'Underline', 'Strike', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', 'Link', 'Customupload', '-', 'Table', 'HorizontalRule', 'SpecialChar'],
                        ['Format', 'Font', 'FontSize', 'TextColor', 'BGColor']
                        ],
                        language: 'zh-cn'
                    })
                   
                    </script>
                </td>
            </tr>
            <tr>
                <td style="text-align: center">
                    <input id="btnSave" type="button" value=" 保 存 " class="btn_77px" />
                    <input id="btnClose" type="button" value=" 返 回 " onclick="art.dialog.close();return false;"
                        class="btn_77px" />
                </td>
            </tr>
        </table>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            var jsonTag = eval('(<%=LoadTagData() %>)');
            $("#<%=ddlTempType.ClientID %>").change(function () {
                var type = $(this).val();
                $(".email_tag").html("");
                $.each(jsonTag, function (n, value) {
                    if (n == type) {
                        $.each(value[0], function (name, field) {
                            $(".email_tag").append("<a href=\"javascript:void(0)\" class=\"field_tags\"><{" + name + "}></a> ");
                        })
                    }
                })
            });
            $("#<%=ddlTempType.ClientID %>").change();
            $(".field_tags").live("click", function () {
                CKEDITOR.instances.<%=txtContent.ClientID %>.insertHtml($(this).text());
            })
            $("#btnSave").click(function () {
                //把编辑值赋值到实际文本框，编辑器只在有post动作时才把值赋值给实际文本框。
                CKEDITOR.instances.<%=txtContent.ClientID %>.updateElement(); 
                FormPostAjax("/SMSEmail/MailTemplateEdit.aspx?op=Save&Id=<%=Id %>", "ok", CloseReload);
            });          
        });
        //插入图片
        function UploadFun() {
            if(art.dialog != "") art.dialog.data('departValue',""); //清空防止上一次的缓存
            return OpenDialog2('/crm/promote/UploadPic.aspx?r='+Math.random(), '插入图片', function () {
                var bValue = art.dialog.data('departValue');
                if (bValue != null && bValue != "") { 
                    CKEDITOR.instances.<%=txtContent.ClientID %>.insertHtml("<img src='"+bValue+"'/>");
                }
            });
        }
    </script>
</asp:Content>
