MWF.xDesktop.requireApp("process.Xform", "$Module", null, false); MWF.xApplication.process.Xform.Office = MWF.APPOffice = new Class({ 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"], "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; }, _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); } }, getProgID: function(){ switch (this.json.officeType){ case "word": return "Word.Document"; case "excel": return "Excel.Sheet"; case "ppt": return "PowerPoint.Show"; } return "Word.Document" }, 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.loadOfficeRead(file); }else if (this.json.isReadonly){ this.readonly = true; this.loadOfficeRead(file); }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.loadOfficeRead(file); }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){ 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.work) ? 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.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "file"+this.json.id+id+"."+ename; }, getOfficeObjectId: function(){ var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id; return "NTKOOCX"+this.json.id+id; }, getFileInputName: function(){ var id = (this.form.businessData.work) ? 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安装组件"; objectHtml += ""; this.officeNode.appendHTML(objectHtml); this.officeForm = this.officeNode.getFirst(); this.officeOCX = this.officeNode.getFirst().getFirst(); this.doOfficeOCXEvents(); } var url = this.getOfficeFileUrl(); if (url){ this.officeOCX.BeginOpenFromURL(url, true, this.readonly); }else{ this.officeOCX.CreateNew(this.getProgID()); this.fireEvent("afterCreate"); } }, 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(window.navigator.platform=="Win64"){ objectHtml = "
"; }else{ 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); } //this.doOfficeOCXEvents(); } var url = this.getOfficeFileUrl(); if (url){ this.officeOCX.BeginOpenFromURL(url, true, this.readonly); }else{ this.officeOCX.CreateNew(this.getProgID()); this.fireEvent("afterCreate"); } }, loadOfficeEdit: function(file){ if (Browser.name==="chrome"){ this.loadOfficeEditChrome(file); }else if (Browser.name==="firefox") { this.loadOfficeEditFirefox(file); }else{ this.loadOfficeEditIE(file); } this.openedAttachment = null }, 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(); } var url = file || this.getOfficeFileUrl(); if (url){ //layout.desktop.tmpOffice = this; this.officeOCX.BeginOpenFromURL(url, true, this.readonly); }else{ this.isNew = true; this.officeOCX.CreateNew(this.getProgID()); this.fireEvent("afterCreate"); } }, doOfficeOCXEvents: function(){ var id = this.getOfficeObjectId(); this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);"); this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);"); this.addOfficeEvent(id, "OnDocumentClosed()", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentClosed();"); }, OnDocumentClosed: function(){ this.fireEvent("afterCloseOffice"); }, OnDocumentOpened: function(url, doc){ this.afterOpen(); this.loadMenu(); this.fireEvent("afterOpenOffice"); }, AfterOpenFromURL: function(doc, statusCode){ this.fireEvent("afterOpen", [doc, statusCode]); }, addOfficeEvent: function(id, event, code){ var script = document.createElement("script"); script.setAttribute("for", id); script.setAttribute("event", event); script.innerText = code; this.officeForm.appendChild(script); }, loadOfficeRead: function(file){ this.loadOfficeSpacer(); this.node.setStyle("pisition", "absolute"); // var codeBase = this.json.codeBase || this.options.codeBase; // var version = this.json.version || this.options.version; // var classid = this.json.clsid || this.options.clsid; 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 = "
"; 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(); 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); } //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); }, 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(){}, 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.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.work) ? 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.openDocument(url); }else if(window.webkit){ window.webkit.messageHandlers.openDocument.postMessage(url); }else{ window.open(url); } } }.bind(this)); } });