MWF.xDesktop.requireApp("process.Xform", "$Module", null, false); /** @class Office Office控件。 * @o2cn Ntko Office控件 * @example * //可以在脚本中获取该组件 * //方法1: * var attachment = this.form.get("name"); //获取组件 * //方法2 * var attachment = this.target; //在组件事件脚本中获取 * @extends MWF.xApplication.process.Xform.$Module * @o2category FormComponents * @o2range {Process|CMS} * @hideconstructor */ MWF.xApplication.process.Xform.Office = MWF.APPOffice = new Class( /** @lends MWF.xApplication.process.Xform.Office# */ { Extends: MWF.APP$Module, isActive: false, options:{ "ProductCaption": "O2", "ProductKey": "EDCC626CB85C9A1D3E0D7BDDDC2637753C596725", "makerCaption": "浙江兰德纵横网络技术股份有限公司", "makerKey": "E138DABB4AC26C2D8E09FAE59AB3BDE87AFB9D7B", "version": "5.0.4.0", "clsid": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0", "codeBase": "../o2_lib/officecontrol/5040/OfficeControl.cab", "clsid64": "A64E3073-2016-4baf-A89D-FFE1FAA10EE1", "codeBase64": "../o2_lib/officecontrol/5040/ofctnewclsid.cab", "pdfType": "PDF.NtkoDocument", "pdfVersion": "4.0.0.3", "pdfCodeBase": "../o2_lib/officecontrol/5040/ntkooledocall.cab", "pdfCodeBase64": "../o2_lib/officecontrol/5040/ntkooledocall64.cab", "files": ["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"], /** * @event MWF.xApplication.process.Xform.Office#queryLoad * @ignore */ /** * @event MWF.xApplication.process.Xform.Office#postLoad * @ignore */ /** * 点击套红按钮触发。 * @event MWF.xApplication.process.Xform.Office#redFile * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 点击盖章按钮触发。 * @event MWF.xApplication.process.Xform.Office#seal * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * Ntko控件执行AfterOpenFromURL事件(BeginOpenFromURL方法执行完毕之后被触发)时执行。
* 本事件可以通过this.event获取当前打开的文档对象。比如,对于一个Word文档,第二个参数是一个Word.Document对象。 * @event MWF.xApplication.process.Xform.Office#afterOpen * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * Ntko控件执行OnDocumentOpened事件(Office文档打开完毕)时触发。
* 本事件可以通过this.event获取以下内容 *

         {
            url : url, //Office文档路径或者URL
            doc : doc //Office文档的自动化接口,比如,对于一个Word文档,第二个参数是一个Word.Document对象。
        }
         
* @event MWF.xApplication.process.Xform.Office#afterOpenOffice * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 在新建Office文档后触发。 * @event MWF.xApplication.process.Xform.Office#afterCreate * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 在保存Office文档前触发。 * @event MWF.xApplication.process.Xform.Office#beforeSave * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 在保存Office文档后触发。 * @event MWF.xApplication.process.Xform.Office#afterSave * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 在关闭Office文档时执行。 * @event MWF.xApplication.process.Xform.Office#afterCloseOffice * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ "moduleEvents": ["redFile", "afterOpen", "afterOpenOffice", "afterCreate", "seal", "beforeSave", "afterSave", "afterCloseOffice", "load" ] }, initialize: function(node, json, form, options){ this.node = $(node); this.node.store("module", this); this.json = json; this.form = form; this.field = true; this.openedAttachment = null; this.fieldModuleLoaded = false; }, _loadUserInterface: function(){ this.node.empty(); this.node.setStyles({ "min-height": "100px" }); // this.isActive = true; if (Browser.name==="ie" || Browser.name==="chrome" || Browser.name==="firefox"){ // if (Browser.name==="ie"){ this.isActive = true; this.file = null; if (!this.form.officeList) this.form.officeList=[]; this.form.officeList.push(this); } }, _afterLoaded: function(){ if (!this.json.isNotLoadNow){ this.loadOffice(); } //this.fireEvent("load"); }, loadOffice: function(file){ if (!this.officeLoaded){ if (!this.isActive){ this.loadOfficeNotActive(); }else{ MWF.getJSON("../o2_lib/officecontrol/config.json", function(json){ this.officeConfig = json; }.bind(this), false); this.loadOfficeContorl(file); } this.officeLoaded = true; }else{ if (this.officeOCX) this.officeOCX.BeginOpenFromURL(file, true, this.readonly); } this.fieldModuleLoaded = true; }, getProgID: function(){ switch (this.json.officeType){ case "word": return "Word.Document"; case "excel": return "Excel.Sheet"; case "ppt": return "PowerPoint.Show"; } return "Word.Document" }, getTemplateName: function(){ switch (this.json.officeType){ case "word": return "template.docx"; case "excel": return "template.xlsx"; case "ppt": return "template.pptx"; } return "template.docx" }, defaultParam: function(readonly){ var o = { "ProductCaption": this.json.productCaption || this.options.ProductCaption, "ProductKey": this.json.productKey || this.options.ProductKey, "MakerCaption": this.officeConfig.makerCaption || this.json.makerCaption || this.options.makerCaption, "MakerKey": this.officeConfig.makerKey || this.options.makerKey || this.options.MakerKey, "Titlebar": "0", "Menubar": "0", "ToolBars": (readonly) ? "0" : "1", "Statusbar": "0", "IsUseUTF8URL": "1", "IsUseUTF8Data": "1", "BorderStyle": (readonly) ? "0" : "0", "IsNoCopy": "0", "IsResetToolbarsOnOpen": "1", "FileNew": "0", "FileOpen": "1", "FileClose": "0", "FileSave": "0", "FileProperties": "0" }; return o; }, loadOfficeContorl: function(file){ if (this.node.getSize().y<800) this.node.setStyle("height", "800px"); if (!layout.desktop.offices) layout.desktop.offices = {}; layout.desktop.offices[this.getOfficeObjectId()] = this; if (this.readonly){ this.loadOfficeEdit(file, true); }else if (this.json.isReadonly || this.form.json.isReadonly){ this.readonly = true; this.loadOfficeEdit(file, true); }else{ if (this.json.readScript && this.json.readScript.code){ var flag = this.form.Macro.exec(this.json.readScript.code, this); if (flag){ this.readonly = true; this.loadOfficeEdit(file, true); }else{ this.loadOfficeEdit(file); } }else{ this.loadOfficeEdit(file); } } }, loadOfficeSpacer: function(){ var size = this.node.getSize(); this.officeNode = new Element("div#officeNode", { "styles": this.form.css.officeAreaNode }).inject(this.node); var y = size.y-40; this.officeNode.setStyle("height", ""+y+"px"); this.form.app.addEvent("uncurrent", function(){ var display = this.officeNode.getStyle("display"); this.officeNode.store("officeDisplay", display); this.officeNode.setStyle("display", "none"); }.bind(this)); this.form.app.addEvent("current", function(){ var display = this.officeNode.retrieve("officeDisplay"); if (display) this.officeNode.setStyle("display", display); if (this.officeOCX) this.officeOCX.Activate(true); }.bind(this)); this.form.app.addEvent("queryClose", function(){ this.fireEvent("queryClose"); var id = this.getOfficeObjectId(); layout.desktop.offices[id] = null; delete layout.desktop.offices[id]; }.bind(this)); }, hide: function(){ if (this.officeNode.getStyle("display")!="none"){ var display = this.officeNode.getStyle("display"); this.officeNode.store("officeDisplay", display); this.officeNode.setStyle("display", "none"); } }, show: function(){ if ((layout.desktop.currentApp && layout.desktop.currentApp.appId===this.form.app.appId) || this.form.app.inBrowser){ var display = this.officeNode.retrieve("officeDisplay"); if (display) this.officeNode.setStyle("display", display); if (this.officeOCX) this.officeOCX.Activate(true); } }, isCover: function(node){ }, getFormId: function(){ var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "form"+this.json.id+id; }, getFileName: function(){ var ename = "docx"; switch (this.json.officeType){ case "word": ename = "docx"; break; case "excel": ename = "xlsx"; break; case "ppt": ename = "pptx"; } var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "file"+this.json.id+id+"."+ename; }, getOfficeObjectId: function(){ var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "NTKOOCX"+this.json.id+id; }, getFileInputName: function(){ var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "fileInput"+this.json.id+id; }, getTempleteUrl: function(){ //return "../x_desktop/temp/杭州城管委文件.doc"; if (this.json.template){ var root = ""; var flag = this.json.template.substr(0,1); if (flag==="/"){ root = this.json.template.substr(1, this.json.template.indexOf("/", 1)-1); }else{ root = this.json.template.substr(0, this.json.template.indexOf("/")); } if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){ var host = MWF.Actions.getHost(root); return (flag==="/") ? host+this.json.template : host+"/"+this.json.template } } return this.json.template; }, getFile: function(site){ var file = null; atts = this.form.businessData.attachmentList; for (var i=0; i", "container": this.form.app.content, "isClose": true, "buttonList": [ { "text": MWF.xApplication.process.Xform.LP.close, "action": function(){this.close();} } ], "onPostShow": function(){ this.showHistoryContent(dlg, button) }.bind(this) }); dlg.show(); }.bind(this)); } }, showHistoryContent: function(dlg, button){ dlg.content.setStyle("overflow", "auto"); atts = this.form.businessData.attachmentList; var site = this.json.id+"history"; for (var i=0; i -1) { objectHtml = "
" + "安装组件 objectHtml += ""+MWF.xApplication.process.Xform.LP.installNTKOWebChromePluginNotice_xpi+""; objectHtml += ""; this.officeNode.appendHTML(objectHtml); this.officeForm = this.officeNode.getFirst(); this.officeOCX = this.officeNode.getFirst().getFirst(); if(window.navigator.platform=="Win64"){ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true); } if(window.navigator.platform=="Win32"){ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true); } this.doOfficeOCXEvents(); } this.getAutoSavedAttachments(); if (this.autoSavedAttachments && this.autoSavedAttachments.length){ this.openRecoverAutoSaveDlg(); }else{ this.openOfficeFile(file); } }, loadOfficeEditChrome: function(file){ if (!this.officeOCX){ this.loadOfficeSpacer(); this.node.setStyle("pisition", "absolute"); var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase; var version = this.officeConfig.version || this.json.version || this.options.version; var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid; var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64; var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64; var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType; var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion; var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase; var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64; var objectHtml = ""; // if (navigator.userAgent.indexOf("Linux") > -1) { // objectHtml = "
"; // }else{ // objectHtml = "安装组件 objectHtml += ""+MWF.xApplication.process.Xform.LP.installNTKOWebChromePluginNotice_crx+""; objectHtml += ""; this.officeNode.appendHTML(objectHtml); this.officeForm = this.officeNode.getFirst(); this.officeOCX = this.officeNode.getFirst().getFirst(); if (this.officeOCX){ if(window.navigator.platform=="Win64"){ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true); } if(window.navigator.platform=="Win32"){ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true); } this.doOfficeOCXEvents(); // this.officeOCX.addEventListener('DocumentOpened', function(){ // console.log('OnDocumentOpened ...') // }) } } this.getAutoSavedAttachments(); if (this.autoSavedAttachments && this.autoSavedAttachments.length){ this.openRecoverAutoSaveDlg(); }else{ this.openOfficeFile(file); } // var url = this.getOfficeFileUrl(); // if (url){ // this.officeOCX.BeginOpenFromURL(url, true, this.readonly); // }else{ // window.setTimeout(function(){ // // if (this.officeOCX.CreateNew) this.officeOCX.CreateNew("Word.Document"); // this.officeOCX.BeginOpenFromURL('/x_component_process_Xform/widget/ntko/ntkocreatnew.docx', true, this.readonly); // }.bind(this), 500); // // //this.officeOCX.CreateNew(this.getProgID()); // this.fireEvent("afterCreate"); // } }, loadOfficeEdit: function(file, readonly){ if (Browser.name==="chrome"){ this.loadOfficeEditChrome(file, readonly); }else if (Browser.name==="firefox") { this.loadOfficeEditFirefox(file, readonly); }else{ this.loadOfficeEditIE(file, readonly); } this.openedAttachment = null }, getAutoSavedAttachments: function(){ this.autoSavedAttachments = []; this.form.businessData.attachmentList.each(function(att){ if (att.site===this.json.id+"autosave") this.autoSavedAttachments.push(att); }.bind(this)); }, loadOfficeEditIE: function(file){ if (!this.officeOCX){ this.loadOfficeSpacer(); //this.loadMenu(); this.node.setStyle("pisition", "absolute"); var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase; var version = this.officeConfig.version || this.json.version || this.options.version; var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid; var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64; var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64; var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType; var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion; var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase; var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64; var objectHtml = ""; if(window.navigator.platform=="Win64"){ objectHtml = "
"; }else{ objectHtml = ""; } var pars = this.defaultParam(); pars = Object.merge(pars, this.json.ntkoEditProperties); pars = Object.merge(pars, this.json.editProperties); Object.each(pars, function(p, key){ objectHtml += ""; }); //objectHtml += "
如果不能自动安装控件,请将在点击此处下载并安装签章客户端。
"; objectHtml += "
"; this.officeNode.appendHTML(objectHtml); this.officeForm = this.officeNode.getFirst(); this.officeOCX = this.officeNode.getFirst().getFirst(); if(window.navigator.platform=="Win64"){ this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true); }else{ this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true); } //TANGER_OCX_OBJ.CreateNew("word.document"); //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.7","../x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true); this.doOfficeOCXEvents(); } this.getAutoSavedAttachments(); if (this.autoSavedAttachments && this.autoSavedAttachments.length){ this.openRecoverAutoSaveDlg(); }else{ this.openOfficeFile(file); } }, openOfficeFile: function(file){ var url = file || this.getOfficeFileUrl(); if (url){ //layout.desktop.tmpOffice = this; this.officeOCX.BeginOpenFromURL(url, true, this.readonly); }else{ var templateName = this.getTemplateName(); this.isNew = true; this.officeOCX.BeginOpenFromURL('/x_component_process_Xform/widget/ntko/'+templateName, true, this.readonly); this.fireEvent("afterCreate"); } //begin auto save if (this.json.isAutoSave){ if (!this.autoSaveTimerID){ this.autoSave(); this.form.app.addEvent("queryClose", function(){ if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); }.bind(this)); } } }, clearAutoSaveAttachments: function(){ this.form.businessData.attachmentList.each(function(att){ if (att.site===this.json.id+"autosave") o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id); }.bind(this)); this.autoSavedAttachments = []; }, getRecoverItems: function(recoverItemNode){ var css = this.form.css; var _self = this; this.autoSavedAttachments.each(function(att){ var node = new Element("div", {"styles": css.officeRecoverItemNode}).inject(recoverItemNode); var actionNode = new Element("div", {"styles": css.officeRecoverItemActionNode}).inject(node); var titleNode = new Element("div", {"styles": css.officeRecoverItemTitleNode, "text": att.name}).inject(node); node.store("att", att); actionNode.addEvent("click", function(e){ var n = this.getParent(); var att = n.retrieve("att"); _self.form.workAction.getAttachmentData(att.id, _self.form.businessData.work.id); e.stopPropagation(); }); node.addEvents({ "mouseover": function(){ var isSelected = this.retrieve("isSelected"); if (!isSelected) this.setStyles(css.officeRecoverItemNode_over); }, "mouseout": function(){ var isSelected = this.retrieve("isSelected"); if (!isSelected) this.setStyles(css.officeRecoverItemNode) }, "click": function(){ var isSelected = this.retrieve("isSelected"); if (isSelected){ this.setStyles(css.officeRecoverItemNode); this.getFirst().setStyles(css.officeRecoverItemActionNode); this.store("isSelected", false); }else{ var items = recoverItemNode.getChildren(); items.each(function(item){ item.setStyles(css.officeRecoverItemNode); item.getFirst().setStyles(css.officeRecoverItemActionNode); item.store("isSelected", false); }); this.setStyles(css.officeRecoverItemNode_current); this.getFirst().setStyles(css.officeRecoverItemActionNode_current); this.store("isSelected", true); } } }); }.bind(this)); }, openRecoverAutoSaveDlg: function(){ var lp = MWF.xApplication.process.Xform.LP; var node = new Element("div", {"styles": {"overflow": "hidden", "padding": "0 30px"}}); var html = "
"+lp.selectVersionToRestore+"
"; html += "
"; node.set("html", html); var recoverItemNode = node.getLast(); this.getRecoverItems(recoverItemNode); node.inject(this.form.app.content); var _self = this; var dlg = o2.DL.open({ "title": lp.restoreFile, //"style": "work", "isResize": false, "content": node, "width": 600, "onPostClose": function(){ _self.clearAutoSaveAttachments(); }, "buttonList": [ { "text": MWF.xApplication.process.Xform.LP.recover, "action": function(d, e){ this.doRecoverFile(node, e, dlg); }.bind(this) }, { "text": MWF.xApplication.process.Xform.LP.notRecover, "action": function(d, e){ this.doNotRecoverFile(node, e, dlg); }.bind(this) } ] }); }, doNotRecoverFile: function(node, e, dlg){ var _self = this; this.form.app.confirm("infor", e, this.form.app.lp.notRecoverFileConfirmTitle, this.form.app.lp.notRecoverFileConfirmContent, 450, 120, function(){ this.close(); dlg.close(); _self.openOfficeFile(); }, function(){ this.close(); }, null, null, this.form.json.confirmStyle); }, doRecoverFile: function(node, e, dlg){ var recoverItemNode = node.getLast(); var items = recoverItemNode.getChildren(); var _self = this; for (var i=0; i= this.json.autoSaveNumber.toInt()){ //delete first att var att = this.autoSavedAttachments.shift(); o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id, function(){ this.checkAutoSaveNumber(callback); }.bind(this)); }else{ if (callback) callback(); } }, getAutoSaveFileName: function(){ var ename = "docx"; switch (this.json.officeType){ case "word": ename = "docx"; break; case "excel": ename = "xlsx"; break; case "ppt": ename = "pptx"; } var d = Date.parse(new Date()); var dText = d.format("%Y-%m-%d %H:%M:%S"); return MWF.xApplication.process.Xform.LP.autosave+"("+dText+")."+ename; }, autoSave: function(){ var interval = (this.json.autoSaveTime) ? this.json.autoSaveTime.toInt()*60*1000 : (5*60*1000); this.autoSaveTimerID = window.setInterval(function(){ if (!this.openedAttachment){ this.checkAutoSaveNumber(function(){ try{ var fileName = this.getAutoSaveFileName(); this.officeForm.getElement("input").set("value", this.json.id+"autosave"); url = this.form.workAction.action.actions.uploadAttachment.uri; url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id); this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId()); this.form.workAction.listAttachments(this.form.businessData.work.id, function(json){ this.form.businessData.attachmentList = json.data; for (var i=0; i"; var objectHtml = ""; if(window.navigator.platform=="Win64"){ objectHtml = "
"; }else{ objectHtml = ""; } var pars = this.defaultParam(true); pars = Object.merge(pars, this.json.ntkoReadProperties); pars = Object.merge(pars, this.json.readProperties); Object.each(pars, function(p, key){ objectHtml += ""; }); objectHtml += ""; this.officeNode.set("html", objectHtml); this.officeForm = this.officeNode.getFirst(); /** @summary Ntko Office 控件对象, 第三方控件 @see {@link http://ieoffice.ntko.com/pro/show/mid/1_8/pid/2731|NTKO官网 } @example var officeOCX = this.form.get("fieldId").officeOCX; var activeDocument = officeOCX.ActiveDocument //返回一个Office Document 对象,该对象代表活动文档。 */ this.officeOCX = this.officeNode.getFirst().getFirst(); if(window.navigator.platform=="Win64"){ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true); }else{ if (this.officeOCX.AddDocTypePlugin) this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true); } //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","../x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true); var url = file || this.getOfficeFileUrl(); if (url){ var id = this.getOfficeObjectId(); this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);"); this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);"); this.officeOCX.BeginOpenFromURL(url, true, this.readonly); } }, createUploadFileNode: function(){ this.uploadFileAreaNode = new Element("div", {"styles": {"display": "none"}}); var html = ""; this.uploadFileAreaNode.set("html", html); this.fileUploadNode = this.uploadFileAreaNode.getFirst(); this.uploadFileAreaNode.inject(this.officeForm); }, isEmpty : function(){ var data = this.getData(); return !data.trim(); }, getData: function(){ if (this.officeOCX && (this.officeOCX.DocType==1 || this.officeOCX.DocType==6)){ this.officeOCX.ActiveDocument.Application.Selection.WholeStory(); var content = this.officeOCX.ActiveDocument.Application.Selection.Text; return content; }else{ return this._getBusinessData(); } }, setData: function(){}, /** * @summary 保存Office文档到后台 * @param {Boolean} history - 是否生产保留痕迹文件 */ save: function(history){ //if (!this.uploadFileAreaNode) this.createUploadFileNode(); if (!this.readonly){ if (this.historyMode) return true; if (!this.officeForm) return true; this.fireEvent("beforeSave"); try{ if (this.openedAttachment){ this.officeForm.getElement("input").set("value", this.openedAttachment.site); url = this.form.workAction.action.actions.replaceAttachment.uri; url = url.replace("{id}", this.openedAttachment.id); url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id); this.officeOCX.SaveToURL(url, "file", "", this.openedAttachment.name, this.getFormId()); }else{ if (history){ if (this.json.isHistory) this.saveHistory(); } this.clearAutoSaveAttachments(); // if (this.autoSavedAttachments && this.autoSavedAttachments.length){ // this.autoSavedAttachments.each(function(att){ // o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id); // }.bind(this)); // this.autoSavedAttachments = []; // } //this.saveHTML(); this.officeForm.getElement("input").set("value", this.json.id); var url = ""; if (this.file){ url = this.form.workAction.action.actions.replaceAttachment.uri; url = url.replace("{id}", this.file.id); url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id); this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId()); }else{ url = this.form.workAction.action.actions.uploadAttachment.uri; url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id); this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId()); this.form.workAction.getWorkContent(this.form.businessData.work.id, function(json){ this.form.businessData.attachmentList = json.data.attachmentList; this.getOfficeFileUrl(); }.bind(this)); } } }catch (e){} this.fireEvent("afterSave"); } }, getHistoryFileName: function(){ var ename = "docx"; switch (this.json.officeType){ case "word": ename = "docx"; break; case "excel": ename = "xlsx"; break; case "ppt": ename = "pptx"; } //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; var activity = (this.form.businessData.work) ? this.form.businessData.work.activityName : MWF.xApplication.process.Xform.LP.completed; var name = MWF.name.cn(layout.session.user.name); var d = Date.parse(new Date()); var dText = d.format("%Y-%m-%d %H:%M"); return activity+"("+name+")-"+dText+"."+ename; }, saveHistory: function(){ var fileName = this.getHistoryFileName(); this.officeForm.getElement("input").set("value", this.json.id+"history"); url = this.form.workAction.action.actions.uploadAttachment.uri; url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id); this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId()); }, getHTMLFileName: function(){ //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.workId; return id+this.json.id+".mht"; }, saveHTML: function(){ this.officeForm.getElement("input").set("value", this.json.id+"$view"); var file = null; for (var i=0; i300) str = str.substr(0,300)+"……"; } var text = new Element("div", { "text": str }).inject(this.node); } } var text = MWF.xApplication.process.Xform.LP.openOfficeInfor; text = text.replace("{type}", this.json.officeType); var icon = new Element("div", { "styles": { "width": "200px", "height": "24px", "margin": "auto", "margin-top": "18px", "padding-left": "30px", "font-size": "16px", "font-weight": "bold", "color": "#2b5797", "font-family": "Gadugi", "cursor": "pointer", "background": "url("+this.form.path+""+this.form.options.style+"/icon/"+this.json.officeType+".png"+") no-repeat left center" }, "text": text }).inject(this.node); var url = this.getOfficeFileUrl(); if (!url){ this.node.setStyle("display", "none"); } icon.addEvent("click", function(){ var url = this.getOfficeFileUrl(); if (url){ if (window.o2android && window.o2android.postMessage) { var body = { type: "openDocument", data: { url: url } }; window.o2android.postMessage(JSON.stringify(body)); } else if (window.o2android && window.o2android.openDocument) { window.o2android.openDocument(url); }else if (window.webkit){ window.webkit.messageHandlers.openDocument.postMessage(url); }else{ window.open(o2.filterUrl(url)); } } }.bind(this)); } });