<%@ Page Language="c#" Inherits="Web.User.addContribute" CodeBehind="addContribute.aspx.cs" %>

<!DOCTYPE html>
<!--[if lt IE 9]><html class="lte-ie8"><![endif]-->
<!--[if gt IE 8]><!-->
<html>
<!--<![endif]-->
<head>
    <title>投稿</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!--#include file = "../Css/head.htm" -->
    <!--#include file = "../Css/userCssEdit.htm" -->
</head>
<body>
    <form method="post" runat="server">
        <div class="edit-func-box func-box">
            <div class="hd">投稿编辑</div>
            <div class="bd">
                <table class="edit-table" id="Table1">
                    <tr>
                        <th>投稿栏目：
                        </th>
                        <td>
                            <asp:DropDownList ID="contributeClass" runat="server" DataTextField="name" DataValueField="bigClassId" CssClass="input-md" AutoPostBack="true" OnSelectedIndexChanged="contributeClass_SelectedIndexChanged">
                            </asp:DropDownList>
                            &nbsp;<span class="lgrey">请选择当前文章的投稿去向</span>
                        </td>
                    </tr>
                    <tr>
                        <th>文章标题：
                        </th>
                        <td>
                            <asp:TextBox ID="intactTitle" runat="server" notNull="true" msgName="文章标题" class="input-md w3" MaxLength="250"></asp:TextBox>
                        </td>
                    </tr>
                    <tr runat="server" id="trPic" visible="false">
                        <th>标题配图：
                        </th>
                        <td>
                            <div class="pull-left">
                                    <img alt="" src="../images/uploadfiles/nopic.gif" runat="server" id="pho" class="pic-div pull-left" />
                                <div class="pull-left">
                                    <p><a id="uploadimg" href="javascript:void(0);" class="blue">上传图片</a></p>
                                    <p><a href="javascript:void(0);" class="blue blue-tow">从内容中自动选取</a></p>
                                    <br />
                                    <p class="lgrey">请按投稿栏目上传宽高比例合适的小图片</p>
                                </div>
                            </div>

                            <div runat="server" id="trdescript" class="pull-left" style="margin-left: 93px;" visible="true">
                                <span class="pull-left" style="line-height: 105px;">文章简介：</span>
                                <asp:TextBox ID="tbDescript" runat="server" notNull="true" msgName="文章简介" Width="300px" TextMode="MultiLine" Height="100px" MaxLength="400" CssClass="input-md pull-left fn-mr20"></asp:TextBox>
                                <asp:Label ID="lbdeslen" runat="server" CssClass="lgrey"></asp:Label><br />
                                <span id="lastlen" style="color: red;"></span>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>相关信息：
                        </th>
                        <td>
                            <asp:TextBox ID="about" runat="server" regex="[^&quot;^'^\*^\?^,^\.^(^)]+" regexMsg="相关信息格式不正确"
                                MaxLength="50" class="input-md w3"></asp:TextBox>&nbsp;<span class="lgrey">用来查找相关文章，中间用“|”隔开；不能出现""'*?,.()等字符</span>
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <div class="more-edit">
                                <div class="more-edit-fn">
                                    <label class="fn-mr20">
                                        作者：
                                        <asp:TextBox ID="author" runat="server" class="input-md" MaxLength="50" Width="60px"></asp:TextBox>
                                        作者信箱：
                        <asp:TextBox ID="authorMail" runat="server" regex="/^(\w)+(\.\w+)*@(\w)+((\.\w{2,3}){1,3})$/" regexMsg="信箱格式不正确" class="input-md" MaxLength="50" Width="108px"></asp:TextBox>
                                        &emsp;来源：<asp:TextBox ID="copyFrom" runat="server" class="input-md" MaxLength="50" Width="108"></asp:TextBox>
                                        来源地址：<asp:TextBox ID="copyFromLink" runat="server" class="input-md" MaxLength="50" Width="108"></asp:TextBox>
                                        &emsp;内容分页：
                                    <asp:DropDownList ID="pageType" runat="server" onchange="ShowPageTag(this.selectedIndex);" class="input-md" Width="80px">
                                        <asp:ListItem Value="0">不分页</asp:ListItem>
                                        <asp:ListItem Value="2">分页</asp:ListItem>
                                    </asp:DropDownList>
                                        &nbsp;
                                    <a id="pageTagA" href="javascript:void(0);" onclick="InsertPagingTag();" data-toggle="tooltip" data-placement="bottom" title="插入文章内容分页标记" style="display: none;"><span class="blue">插入分页标记</span></a>
                                        <asp:TextBox ID="autoPageCharNum" runat="server" Visible="False">10000</asp:TextBox>
                                        <asp:Panel ID="ReadPointPanel" runat="server" Visible="False">
                                            文章阅读点数：<asp:TextBox ID="readPoint" runat="server">0</asp:TextBox>
                                        </asp:Panel>
                                    </label>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>文章内容：
                        </th>
                        <td>
                            <textarea name="content" style="width: 100%; height: 380px; visibility: hidden;"></textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="ft">
                <div class="action-field text-center">
                    <asp:Button ID="ok" runat="server" class="btn btn-sm btn-primary" Text="保 存" OnClientClick="return checkAll();" OnClick="ok_Click" CommandName="add"></asp:Button>
                    &nbsp;
                <asp:Button ID="ok1" runat="server" class="btn btn-sm btn-primary" CommandName="contribute" OnClientClick="return checkAll();" OnClick="ok_Click" Text="保存并投稿"></asp:Button>
                    &nbsp;
                <asp:Button ID="cancel" runat="server" class="btn btn-sm btn-primary" Text="取 消" CausesValidation="False" OnClick="cancel_Click"></asp:Button>
                </div>
                <!--/action-field-->
            </div>
            <div>
                <input id="content1" type="hidden" name="content1" runat="server" />
                <input id="imageName" type="hidden" name="imageName" runat="server" value="" />
            </div>
        </div>
        <!--#include file = "../Css/foot.htm" -->
        <script type="text/javascript" language="javascript">
            //声明编辑器
            var contentTxt;
            KindEditor.ready(function (K) {
                var WpEditor = K.create('textarea[name="content"]');

                var initcontxt = document.getElementById("content1");
                WpEditor.insertHtml(initcontxt.value);

                //编辑时加载内容
                contentTxt = WpEditor;
                //从内容中获取图片
                var uicounts = 0;
                function updateImg() {
                    var uistr = WpEditor.html();
                    //var test = /\/([^\/]*?\.(jpg|bmp|gif))"\/>/gi;
                    var test = /src="([^"]*)"/gi;
                    var result = [];
                    var img;
                    while (img = test.exec(uistr)) {
                        result.push(img[1]);
                    }
                    if (result.length <= 0) {
                        alert("在内容中未检测到图片!");
                    }
                    else {
                        var imgurl;
                        if (uicounts < result.length) {
                            imgurl = result[uicounts];
                            uicounts = uicounts + 1;
                        }
                        else {
                            uicounts = 1;
                            imgurl = result[0];
                        }
                        document.getElementById("imageName").value = imgurl;
                        var arr = K("#imageName").val();
                        if (arr != "") {
                            K("#pho").attr('src', arr);
                        }//加载预览图片
                    }
                }
                $(".pull-left .blue-tow").click(function () {
                    updateImg();
                });
            });

        </script>

        <script type="text/javascript">
            //自定义上传图片控件加载，支持自定义上传图片功能需先引用三个文件，[themes/default/default.css] [kindeditor.js] [lang/zh_CN.js]
            KindEditor.ready(function (K) {
                var editor = K.editor({
                    uploadJson: '../Wpedt/UserEditor/aspnet/upload_json.ashx',
                    fileManagerJson: '../Wpedt/UserEditor/aspnet/file_manager_json.ashx',
                    allowFileManager: true
                });

                K('#uploadimg').click(function () {
                    editor.loadPlugin('zdyimage', function () {
                        editor.plugin.zdyimageDialog({
                            zdyimageUrl: K('#imageName').val(),
                            clickFn: function (url) {
                                K('#imageName').val(K.formatUrl(url, 'domain'));
                                editor.hideDialog();
                                var arr = K("#imageName").val();
                                if (arr != "") {
                                    K("#pho").attr('src', arr);
                                }//加载预览图片
                            }
                        });
                    });
                });

            });
        </script>
        <script type="text/javascript" language="javascript">

            //加载预览图片  （201407 shijian 统一把document.formID.objectID.**写法替换为 $("ID").写法）
            function change() {
                var arr = $("#imageName").val();
                if (arr != "") {
                    //if (arr.indexOf("http://") > -1 )
                    //{
                    //    arr = "" + arr;
                    //}
                    var imgstr = "<img src=" + arr + " />";
                    $("#pho").html(imgstr);
                }
            }

            // 显示分页标记
            function ShowPageTag(selectedIndex) {
                if (selectedIndex != 1) {
                    document.getElementById("pageTagA").style.display = "none";
                }
                else {
                    document.getElementById("pageTagA").style.display = "";
                }
            }
            //插入文章内容分页标记
            function InsertPagingTag() {
                contentTxt.focus();
                contentTxt.insertHtml("<button id=\"ZDSOFTPAGINGTAG\">分页标记</button>");
                contentTxt.focus();
            }

            //从内容中获取图片
           
            //在保存之前,验证输入是否正确；将有效日期值转换成相应的有效天数
            function checkAll() {
                //验证
                if (checkAllValidate()) {
                    //判断内容是否为空
                    var etxtisempty = contentTxt.isEmpty();
                    if (etxtisempty) {
                        alert("文章内容不能为空！");
                        return false;
                    } else {
                        //获取文章内容
                        var gettxttitle = contentTxt.html();
                        var contxt = document.getElementById("content1");
                        contxt.value = gettxttitle;
                    }
                    return true;
                } else {
                    return false;
                }
            }

            ShowPageTag(document.all.pageType.selectedIndex);

            

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