<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Template_Edit.aspx.cs" Inherits="TotCms.Web.Office.Document.Template_Edit" ValidateRequest="false" %>
<!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 id="Head1" runat="server">
    <title>上传文档</title>
    <link href="../style/global.css" rel="stylesheet" type="text/css" />
    <link href="../../swfupload/swfupload.css" rel="stylesheet" type="text/css" />
    <script src="../../swfupload/swfupload.js" type="text/javascript"></script>
    <script src="../../ckeditor/ckeditor.js" type="text/javascript"></script>
    <script src="js/handlers.js" type="text/javascript"></script>
    <script src="../ActiveX/docfun.js" type="text/javascript"></script>
    <script type="text/javascript">
      var swfu;
      window.onload = function () {
        //swf upload
        swfu = new SWFUpload({
          // Backend Settings
          upload_url: "../Upload/UploadImg.aspx",
          post_params: {
            "ASPSESSID": "<%=Session.SessionID %>"
          },

          // File Upload Settings
          file_size_limit: "200 MB",
          file_types: "*.jpg",
          file_types_description: "files",
          file_upload_limit: "0",    // Zero means unlimited

          // Event Handler Settings - these functions as defined in Handlers.js
          //  The handlers are not part of SWFUpload but are part of my website and control how
          //  my website reacts to the SWFUpload events.
          file_queue_error_handler: fileQueueError,
          file_dialog_complete_handler: fileDialogComplete,
          upload_progress_handler: uploadProgress,
          upload_error_handler: uploadError,
          upload_success_handler: uploadSuccess,
          upload_complete_handler: uploadComplete,

          // Button settings
          button_image_url: "../Upload/Images/XPButtonUploadText_61x22.png",
          button_placeholder_id: "spanButtonPlaceholder",
          button_width: 61,
          button_height: 22,
          button_text: '<span class="button"></span>',
          button_text_style: '.button { font-family: 宋体; font-size: 14px; } .buttonSmall { font-size: 12px; }',
          button_text_top_padding: 1,
          button_text_left_padding: 5,

          // Flash Settings
          flash_url: "../../swfupload/swfupload.swf", // Relative to this file

          custom_settings: {
            upload_target: "divFileProgressContainer",
            upload_returnobjid: "tbAttachment"
          },

          // Debug Settings
          debug: false
        });
      }
    </script>
    <!-- --------------------=== 调用Weboffice初始化方法 ===--------------------- -->
<script language="javascript" event="NotifyCtrlReady" for="WebOffice1">
/****************************************************
*
*	在装载完Weboffice(执行<object>...</object>)
*	控件后执行 "WebOffice1_NotifyCtrlReady"方法
*
****************************************************/
	WebOffice1_NotifyCtrlReady()
</script>

<script language="javascript" event="NotifyWordEvent(eventname)" for="WebOffice1">
<!--
 WebOffice1_NotifyWordEvent(eventname)
//-->
</script>

<script language="javascript">
  /****************************************************
  *
  *		控件初始化WebOffice方法
  *
  ****************************************************/
  function WebOffice1_NotifyCtrlReady() {
    document.all.WebOffice1.OptionFlag |= 128;
    // 新建文档
    document.all.WebOffice1.LoadOriginalFile("<%=GetUrl()%>/Template/<%=GetId() %>.doc", "doc");

  }
  var flag = false;
  function menuOnClick(id) {
    var id = document.getElementById(id);
    var dis = id.style.display;
    if (dis != "none") {
      id.style.display = "none";

    } else {
      id.style.display = "block";
    }
  }
  /****************************************************
  *
  *		接收office事件处理方法
  *
  ****************************************************/
  var vNoCopy = 0;
  var vNoPrint = 0;
  var vNoSave = 0;
  var vClose = 0;
  function no_copy() {
    vNoCopy = 1;
  }
  function yes_copy() {
    vNoCopy = 0;
  }


  function no_print() {
    vNoPrint = 1;
  }
  function yes_print() {
    vNoPrint = 0;
  }


  function no_save() {
    vNoSave = 1;
  }
  function yes_save() {
    vNoSave = 0;
  }
  function EnableClose(flag) {
    vClose = flag;
  }
  function CloseWord() {

    document.all.WebOffice1.CloseDoc(0);
  }

  function WebOffice1_NotifyWordEvent(eventname) {
    if (eventname == "DocumentBeforeSave") {
      if (vNoSave) {
        document.all.WebOffice1.lContinue = 0;
        alert("此文档已经禁止保存");
      } else {
        document.all.WebOffice1.lContinue = 1;
      }
    } else if (eventname == "DocumentBeforePrint") {
      if (vNoPrint) {
        document.all.WebOffice1.lContinue = 0;
        alert("此文档已经禁止打印");
      } else {
        document.all.WebOffice1.lContinue = 1;
      }
    } else if (eventname == "WindowSelectionChange") {
      if (vNoCopy) {
        document.all.WebOffice1.lContinue = 0;
        //alert("此文档已经禁止复制");
      } else {
        document.all.WebOffice1.lContinue = 1;
      }
    } else if (eventname == "DocumentBeforeClose") {
      if (vClose == 0) {
        document.all.WebOffice1.lContinue = 0;
      } else {
        //alert("word");
        document.all.WebOffice1.lContinue = 1;
      }
    }
    //alert(eventname); 
  }

  function SaveDoc(id, docType) {
    try {
      var webObj = document.getElementById("WebOffice1");
      var returnValue;
      if (form1.tbTitle.value == "") {
        alert("标题不可为空")
        form1.tbTitle.focus();
        return false;
      }

      webObj.HttpInit(); 		//初始化Http引擎
      // 添加相应的Post元素
      webObj.HttpAddPostString("id", "<%=GetId() %>");
      webObj.HttpAddPostString("tbTitle", escape(form1.tbTitle.value));
      webObj.HttpAddPostString("tbAttachment", escape(form1.tbAttachment.value));
      webObj.HttpAddPostString("tbContent", "");      
      webObj.HttpAddPostCurrFile("DocContent", ""); 	// 上传文件
      returnValue = webObj.HttpPost("<%=GetUrl() %>/Template_Save.aspx"); // 判断上传是否成功
      if ("succeed" == returnValue) {
        //alert("文件上传成功");
      } else if ("failed" == returnValue)
        alert("文件上传失败");
      return_onclick('<%=GetUrl() %>/Templates.aspx');
    } catch (e) {
      //document.write(e.Description);
      alert("异常\r\nError:" + e + "\r\nError Code:" + e.number + "\r\nError Des:" + e.description);
    }
  }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <table style="width:100%;" border="0" cellpadding="0" cellspacing="1" 
      class="border">
      <tr class="suphead">
        <td colspan="2">
          <asp:Literal ID="liTitle" runat="server"></asp:Literal>
          公文模板</td>
    </tr>
    <tr>
      <td class="fields_text">
          名称</td>
      <td class="fields_input">
        <asp:TextBox ID="tbTitle" runat="server"></asp:TextBox>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
          ControlToValidate="tbTitle" ErrorMessage="名称不能为空"></asp:RequiredFieldValidator>
          </td>
    </tr>    
    
    <tr>
      <td class="fields_text">
          缩略图：</td>
      <td class="fields_input">     
      <div id="swfu_container" style="margin: 0px 0px;">
        <asp:TextBox ID="tbAttachment" runat="server" CssClass="input_middle"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
          ControlToValidate="tbAttachment" ErrorMessage="请上传文件"></asp:RequiredFieldValidator>
        <span id="spanButtonPlaceholder"></span>
        <div id="divFileProgressContainer"></div>
      </div>      
      </td>
    </tr>
    <tr>
      <td colspan="2">
      <!-- -----------------------------== 装载weboffice控件 ==--------------------------------- -->
        <object id=WebOffice1 height=768 width='100%' style='LEFT: 0px; TOP: 0px'  classid='clsid:E77E049B-23FC-4DB8-B756-60529A35FAD5' codebase='../ActiveX/weboffice_v6.0.5.0.cab#Version=6,0,5,0'>
        <param name='_ExtentX' value='6350'><param name='_ExtentY' value='6350'>
        </object>
        <!-- --------------------------------== 结束装载控件 ==----------------------------------- -->  
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center" height="35">
        <asp:TextBox ID="tbContent" runat="server" CssClass="hidden"  TextMode="MultiLine"></asp:TextBox>
        <input name="button93" type="button" onClick="return SaveDoc('293','doc')" value="确 定">
        <input id="Button2" type="reset" value="返 回" onclick="javascript:history.back();" /></td>
    </tr>
  </table>
    </form>
</body>
</html>

