MWF.xDesktop.requireApp("process.Xform", "$Module", null, false); MWF.xApplication.process.Xform.Office = MWF.APPOffice = new Class({ Extends: MWF.APP$Module, isActive: false, options:{ "version": "5,0,3,1", "ProductCaption": "O2", "ProductKey": "EDCC626CB85C9A1D3E0D7BDDDC2637753C596725", "MakerCaption": "浙江兰德纵横网络技术股份有限公司", "MakerKey": "E138DABB4AC26C2D8E09FAE59AB3BDE87AFB9D7B", "clsid": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0", "codeBase": "/x_desktop/res/framework/officecontrol/OfficeControl.cab", "clsid64": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0", "codeBase64": "/x_desktop/res/framework/officecontrol/OfficeControl.cab", "moduleEvents": ["redFile", "afterOpen", "afterOpenOffice", "afterCreate", "seal", "beforeSave", "afterSave", "afterCloseOffice"] }, initialize: function(node, json, form, options){ this.node = $(node); this.node.store("module", this); this.json = json; this.form = form; this.field = true; }, _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(); } }, loadOffice: function(){ if (!this.isActive){ this.loadOfficeNotActive(); }else{ this.loadOfficeContorl(); } }, 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.json.makerCaption || this.options.MakerCaption, "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(){ 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(); }else if (this.json.isReadonly){ this.readonly = true; this.loadOfficeRead(); }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(); }else{ this.loadOfficeEdit(); } }else{ this.loadOfficeEdit(); } } }, loadOfficeSpacer: function(){ var size = this.node.getSize(); this.officeNode = new Element("div", { "styles": this.form.css.officeAreaNode }).inject(this.node); this.officeNode.setStyle("height", ""+size.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)); }, 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 = "doc"; switch (this.json.officeType){ case "word": ename = "doc"; break; case "excel": ename = "xls"; break; case "ppt": ename = "ppt"; } 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; }, getOfficeFileUrl: function(){ var fileName = this.getFileName(); 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) }.bind(this) }); dlg.show(); }.bind(this)); }, showHistoryContent: function(dlg){ 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(){ 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 objectHtml = "
安装组件"; 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"); } }, loadOfficeEdit: function(){ if (Browser.name==="chrome"){ this.loadOfficeEditChrome(); }else if (Browser.name==="firefox") { this.loadOfficeEditFirefox(); }else{ this.loadOfficeEditIE(); } }, loadOfficeEditIE: function(){ this.loadOfficeSpacer(); //this.loadMenu(); this.node.setStyle("pisition", "absolute"); //if (this.json.ntkoEditProperties.load) 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 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 += "
"; this.officeNode.appendHTML(objectHtml); this.officeForm = this.officeNode.getFirst(); this.officeOCX = this.officeNode.getFirst().getFirst(); this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",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 = this.getOfficeFileUrl(); if (url){ //layout.desktop.tmpOffice = this; this.officeOCX.BeginOpenFromURL(url, true, this.readonly); }else{ this.isNew = true; // if (this.json.officeType!=="other"){ this.officeOCX.CreateNew(this.getProgID()); this.fireEvent("afterCreate"); // }else{ // // } } }, 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(){ 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 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(); this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true); var url = 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.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.officeForm) return true; this.fireEvent("beforeSave"); 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)); } // this.stopRevisions(true); // this.saveHTML(); // var url = this.getOfficeFileUrl(); // if (url){ // //layout.desktop.tmpOffice = this; // this.officeOCX.BeginOpenFromURL(url, true, this.readonly); // }else{ // // if (this.json.officeType!=="other"){ // this.officeOCX.CreateNew(this.getProgID()); // this.fireEvent("afterCreate"); // // }else{ // // // // } // } this.fireEvent("afterSave"); } }, getHistoryFileName: function(){ var ename = "doc"; switch (this.json.officeType){ case "word": ename = "doc"; break; case "excel": ename = "xls"; break; case "ppt": ename = "ppt"; } //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(){ debugger; 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.o2){ window.o2.openDocument(url); }else if(window.webkit){ window.webkit.messageHandlers.openDocument.postMessage(url); }else{ window.open(url); } } }.bind(this)); } });