<%@ Page Language="C#" %>
<%@ Register TagPrefix="aspxform" Namespace="XFormDesigner.Framework.Web.UI" Assembly="XFormDesigner.Framework" %>
<script runat="server">

    // Insert page code here
    //

</script>
<html xmlns:xform="xmlns:xform">
<head runat="server">
    <link href="/Oimec/Styles/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <title>BPM Form</title>
    <style>
        BODY {
            FONT-SIZE: 12px;
            FONT-FAMILY: verdana;
        }

        TABLE {
            border-collapse: collapse;
            FONT-FAMILY: verdana;
        }

        P {
            PADDING-RIGHT: 0px;
            PADDING-LEFT: 0px;
            PADDING-BOTTOM: 0px;
            MARGIN: 0px;
            PADDING-TOP: 0px;
            FONT-SIZE: 12px;
            FONT-FAMILY: verdana;
        }

        TD {
            PADDING-RIGHT: 0px;
            PADDING-LEFT: 2px;
            PADDING-BOTTOM: 0px;
        }

            TD.NoPadding {
                PADDING-RIGHT: 0px;
                PADDING-LEFT: 0px;
                PADDING-BOTTOM: 0px;
                PADDING-TOP: 0px;
            }

        INPUT {
            HEIGHT: 20px;
        }

            INPUT.UL {
                BORDER-RIGHT: medium none;
                BORDER-TOP: medium none;
                BORDER-LEFT: medium none;
                BORDER-BOTTOM: #33ff33 1px solid;
            }

        TEXTAREA {
            FONT-SIZE: 12px;
        }

        .yz-inp-cnt {
            display: inline;
        }

        DIV.datetimepicker-date-hour-minutes DIV.time {
            width: 150px;
        }

        #td1 {
            border-right: #b2bcc6 1px solid;
        }
    </style>
    <script src="../../../../Oimec/Script/jquery-3.2.1.js"></script>
    <script src="../../../../Oimec/Script/jquery-3.2.1.min.js"></script>
    <script src="../../../../Scripts/kindeditor-4.1.10/kindeditor.js"></script>
    <script src="/Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>
    <script type="text/javascript">
        KindEditor.ready(function (K) {
            editor = K.create('#productContent', {
                allowImageUpload: true,
                uploadJson: '/Scripts/kindeditor-4.1.10/asp.net/upload_json.ashx',
                fileManagerJson: '/Scripts/kindeditor-4.1.10/asp.net/file_manager_json.ashx',
                allowFileManager: true
            });
        });

        Ext.onReady(function () {

            var state = request("formstate");
            if (state == "Edit") {
                //获取产品内容文件地址.
                var productContent = agent.Eles[document.getElementById("XTextBox3").getAttribute("xform_xele_index")].getValue();

                YZSoft.Ajax.request({
                    async: false,
                    url: YZSoft.$url('Oimec/ApiServices/ProductBeforLoadHandler.ashx'),
                    params: {
                        productContent: productContent
                    },
                    success: function (action) {
                        var content = action.result.ProductContent;
                        if (content == "不存在相应的目录")
                        {
                            var msg = confirm("原文件已丢失,是否需要重新进行编辑?\n若有问题请联系系统管理员"); 
                            if (msg == true)                               
                            { editor.html(""); }
                            else window.close(); 
                        }
                        else {
                            editor.html(action.result.ProductContent);
                        }
                    },
                    failure: function (response) {
                    }
                });
            }
        });

        agent.on('beforeSubmit', function () {
            var filePath = "";
            var state = request("formstate");
            var productContent = editor.html();
            //re1 = new RegExp("<strong>", "g");
            //re2 = new RegExp("</strong>", "g");
            //productContent = productContent.replace(re1, "<b>");
            //productContent = productContent.replace(re2, "</b>");
            // productContent = escape(productContent);
            // string jsonText = "{\"zone\":\"海淀\",\"zone_en\":\"haidian\"}";
            //alert(productContent_json);
            if (productContent == null || productContent == "") {
                alert("产品内容不能为空!");
                return false;
            }
            else {
                //json字符串参数
                var productContent_json = "{\"content\":\"" + encodeURIComponent(productContent) + "\"}";
                if (state == "Edit") {
                    //文件地址.
                    fileAddress = agent.Eles[document.getElementById("XTextBox3").getAttribute("xform_xele_index")].getValue();

                } else {
                    fileAddress = "";
                }

                
                var str_url = YZSoft.$url('Oimec/ApiServices/ProductBeforSubmitHandler.ashx');
                var str_data =
                    $.ajaxSetup({ async: false });
                $.post(str_url, {
                    productContent: productContent_json,
                    state: state,
                    fileAddress: fileAddress
                }, function (data) {
                    var result = eval("(" + data + ")");
                    var status = result.success;
                    if (status) {
                        agent.Eles[document.getElementById("XTextBox3").getAttribute("xform_xele_index")].setValue(result.filePath);
                        filePath = result.filePath;
                    }
                    else {
                        var msg = result.Message;
                        alert(msg);
                    }
                });
                

                /*
                YZSoft.Ajax.request({
                    async: false,
                    url: YZSoft.$url('Oimec/ApiServices/ProductBeforSubmitHandler.ashx'),
                    params: {
                        productContent: productContent_json,
                        state: state,
                        fileAddress: fileAddress
                    },
                    success: function (action) {
                      //  alert(action.result.filePath);
                        agent.Eles[document.getElementById("XTextBox3").getAttribute("xform_xele_index")].setValue(action.result.filePath);
                    },
                    failure: function (response) {
                    }
                });
                */
            }
           
        });

      
        function request(paras) {
            var url = location.href;
            var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
            var paraObj = {};
            for (i = 0; j = paraString[i]; i++) {
                paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
            }
            var returnValue = paraObj[paras.toLowerCase()];
            if (typeof (returnValue) == "undefined")
            { return ""; }
            else
            { return returnValue; }
        }

    </script>

</head>
<body>
    <form runat="server">
        <!-- Insert content here -->
        <table width="1200" align="center" class="head" border="0" cellspacing="0" cellpadding="0">
            <tbody>
                <tr>
                    <td class="logo">
                    </td>
                    <td class="biaoti" style="PADDING-LEFT: 30px">
                        <asp:Label id="XLabel1" runat="server" text="产品管理" value valuetodisplaytext></asp:Label></td>
                    <td class="formno">
                    </td>
                </tr>
            </tbody>
        </table>
        <br />
        <table width="1200" align="center" class="table" border="0" cellspacing="0" cellpadding="0">
            <tbody>
                <tr>
                    <td height="14" class="title1" colspan="4">
                        <asp:Label id="XLabel10" runat="server" text="产品信息" value valuetodisplaytext></asp:Label></td>
                </tr>
                <tr>
                    <td width="165" class="tsbottomlabel">
                        <asp:Label id="XLabel4" runat="server" text="产品名称" value valuetodisplaytext></asp:Label></td>
                    <td width="440" class="tsbottomtext">
                        <aspxform:XTextBox id="XTextBox1" runat="server" BorderWidth="1" BorderColor="#DCDCDC" XDataBind="DF_Web_Product.ProductName" Width="50%" CssClass="text"></aspxform:XTextBox>
                    </td>
                    <td width="165" class="tsbottomlabel">
                        <asp:Label id="XLabel5" runat="server" text="创建日期" value valuetodisplaytext></asp:Label></td>
                    <td width="461" class="tsbottomtext">
                        <aspxform:XDateTimePicker id="XDateTimePicker1" runat="server" BorderWidth="1" BorderColor="#DCDCDC" XDataBind="DF_Web_Product.CreateDate" Width="50%" CssClass="text" DisplayOnly="True"></aspxform:XDateTimePicker>
                    </td>
                </tr>
                <tr>
                    <td class="tsbottomlabel">
                        <asp:Label id="XLabel6" runat="server" text="产品内容" value valuetodisplaytext></asp:Label>
                        <aspxform:XTextBox id="XTextBox3" runat="server" BorderWidth="1" BorderColor="#DCDCDC" XDataBind="DF_Web_Product.ProductContent" Width="20px" HiddenExpress="1" HiddenInput="True"></aspxform:XTextBox>
                    </td>
                    <td class="tsbottomtext" colspan="3">
                        <textarea id="productContent" style="HEIGHT: 400px; WIDTH: 883px" rows="1" cols="1"></textarea>
                    </td>
                </tr>
            </tbody>
        </table>
        <br />
    </form>
</body>
</html>
