Office.min.js 8.9 KB

1
  1. MWF.xDesktop.requireApp("process.Xform","Office",null,false);MWF.xApplication.cms.Xform.Office=MWF.CMSOffice=new Class({Extends:MWF.APPOffice,getFormId:function(){var t=this.form.businessData.document.id;return"form"+this.json.id+t},getFileName:function(){var t="docx";switch(this.json.officeType){case"word":t="docx";break;case"excel":t="xlsx";break;case"ppt":t="pptx"}var e=this.form.businessData.document.id;return"file"+this.json.id+e+"."+t},getOfficeObjectId:function(){var t=this.form.businessData.document.id;return"NTKOOCX"+this.json.id+t},getFileInputName:function(){var t=this.form.businessData.document.id;return"fileInput"+this.json.id+t},getFile:function(t){var e=null;atts=this.form.businessData.attachmentList||[];for(var i=0;i<atts.length;i++){if(atts[i].site===t){e=atts[i];break}}return e},getTempleteUrl:function(){if(this.json.template){var t="";var e=this.json.template.substr(0,1);if(e==="/"){t=this.json.template.substr(1,this.json.template.indexOf("/",1)-1)}else{t=this.json.template.substr(0,this.json.template.indexOf("/"))}if(["x_cms_assemble_control"].indexOf(t.toLowerCase())!==-1){var i=MWF.Actions.getHost(t);return e==="/"?i+this.json.template:i+"/"+this.json.template}}return this.json.template},getOfficeFileUrl:function(){debugger;var t=this.getFileName();this.readSite=this.json.id;if(this.json.fileSite&&this.json.fileSite.code){this.readSite=this.form.Macro.exec(this.json.fileSite.code,this)}var e=this.getFile(this.readSite);if(!e)if(this.readSite!==this.json.id)e=this.getFile(this.json.id);if(e){this.file=e;var i="";i=this.form.documentAction.action.actions.getAttachmentData.uri;i=i.replace("{id}",encodeURIComponent(e.id));return this.form.documentAction.action.address+i.replace("{documentid}",encodeURIComponent(this.form.businessData.document.id))}else{return this.getTempleteUrl()}},createMenuAction:function(t,e,i){var e=e||MWF.xApplication.process.Xform.LP[t];return new Element("div",{MWFnodeid:t,MWFnodetype:"MWFToolBarButton",MWFButtonImage:this.form.path+""+this.form.options.style+"/actionbar/"+i,title:e,MWFButtonAction:"menuAction",MWFButtonText:e}).inject(this.menuNode)},createMenuActionMenu:function(t,e,i){var e=e||MWF.xApplication.process.Xform.LP[t];return new Element("div",{MWFnodeid:t,MWFnodetype:"MWFToolBarMenu",MWFButtonImage:this.form.path+""+this.form.options.style+"/actionbar/"+i,title:e,MWFButtonAction:"menuAction",MWFButtonText:e}).inject(this.menuNode)},createMenuActionMenuItem:function(t,e,i,n){debugger;return new Element("div",{MWFnodeid:t,MWFnodetype:"MWFToolBarMenuItem",MWFButtonImage:this.form.path+""+this.form.options.style+"/actionbar/"+i,title:e,MWFButtonAction:n,MWFButtonText:e}).inject(this.menuNode)},openAttachment:function(e,i,n){if(!this.openedAttachment||this.openedAttachment.id!==e){this.save();MWF.Actions.get("x_cms_assemble_control").getAttachmentUrl(e,this.form.businessData.document.id,function(t){this.openedAttachment={id:e,site:i,name:n};this.officeOCX.BeginOpenFromURL(t,true,this.readonly)}.bind(this))}},openOfficeHistory:function(t,e){var i=t.target.getParent().get("value");url=this.form.documentAction.action.actions.getAttachmentData.uri;url=url.replace("{id}",encodeURIComponent(i));url=this.form.documentAction.action.address+url.replace("{documentid}",encodeURIComponent(this.form.businessData.document.id));e.close();this.save();this.officeOCX.BeginOpenFromURL(url,true,true);this.historyMode=true;if(button){button.setText(MWF.xApplication.process.Xform.LP.menu_hideHistory)}},save:function(t){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);e=this.form.documentAction.action.actions.replaceAttachment.uri;e=e.replace("{id}",this.openedAttachment.id);e=this.form.documentAction.action.address+e.replace("{documentid}",this.form.businessData.document.id);this.officeOCX.SaveToURL(e,"file","",this.openedAttachment.name,this.getFormId())}else{if(t){if(this.json.isHistory)this.saveHistory()}this.officeForm.getElement("input").set("value",this.json.id);var e="";if(this.file){e=this.form.documentAction.action.actions.replaceAttachment.uri;e=e.replace("{id}",this.file.id);e=this.form.documentAction.action.address+e.replace("{documentid}",this.form.businessData.document.id);this.officeOCX.SaveToURL(e,"file","",this.getFileName(),this.getFormId())}else{e=this.form.documentAction.action.actions.uploadAttachment.uri;e=this.form.documentAction.action.address+e.replace("{id}",this.form.businessData.document.id);this.officeOCX.SaveToURL(e,"file","",this.getFileName(),this.getFormId());this.form.documentAction.getDocument(this.form.businessData.document.id,function(t){this.form.businessData.attachmentList=t.data.attachmentList;this.getOfficeFileUrl()}.bind(this))}}}catch(t){}this.fireEvent("afterSave")}},getHistoryFileName:function(){var t="docx";switch(this.json.officeType){case"word":t="docx";break;case"excel":t="xlsx";break;case"ppt":t="pptx"}var e="";var i=MWF.name.cn(layout.session.user.name);var n=Date.parse(new Date);var o=n.format("%Y-%m-%d %H:%M");return e+"("+i+")-"+o+"."+t},saveHistory:function(){var t=this.getHistoryFileName();this.officeForm.getElement("input").set("value",this.json.id+"history");url=this.form.documentAction.action.actions.uploadAttachment.uri;url=this.form.documentAction.action.address+url.replace("{documentid}",this.form.businessData.document.id);this.officeOCX.SaveToURL(url,"file","",t,this.getFormId())},getHTMLFileName:function(){var t=this.form.businessData.document.id;return t+this.json.id+".mht"},saveHTML:function(){debugger;this.officeForm.getElement("input").set("value",this.json.id+"$view");var t=null;for(var e=0;e<this.form.businessData.attachmentList.length;e++){var i=this.form.businessData.attachmentList[e];if(i.site==this.json.id+"$view"){t=i}}var n=t?t.name:this.getHTMLFileName();this.officeForm.getElement("input").getNext().set("value",n);if(t){url=this.form.documentAction.action.actions.replaceAttachment.uri;url=url.replace("{id}",t.id);url=this.form.documentAction.action.address+url.replace("{documentid}",this.form.businessData.document.id)}else{url=this.form.documentAction.action.actions.uploadAttachment.uri;url=this.form.documentAction.action.address+url.replace("{id}",this.form.businessData.document.id)}this.officeOCX.SaveAsOtherFormatToURL(1,url,"file","",n,this.getFormId())},getHTMLFileUrl:function(t){var e=t||this.getHTMLFileName();var i=null;atts=this.form.businessData.attachmentList;for(var n=0;n<atts.length;n++){if(atts[n].name===e||atts[n].site===this.json.id+"$view"){i=atts[n];break}}if(i){var o="";o=this.form.documentAction.action.actions.getAttachmentData.uri;o=o.replace("{id}",encodeURIComponent(i.id));return this.form.documentAction.action.address+o.replace("{documentid}",encodeURIComponent(this.form.businessData.document.id))}else{return this.getTempleteUrl()}},validationMode:function(){},validation:function(){return true},loadOfficeNotActive:function(){var t=this.getFileName();var e="";var i=false;for(var n=0;n<this.form.businessData.attachmentList.length;n++){var o=this.form.businessData.attachmentList[n];if(o.site==this.json.id+"$view"){e=o.name}}debugger;if(false){this.node.setStyles({"min-height":"600px",padding:"0px",border:"0px solid #999999","background-color":"#e6e6e6",overflow:"hidden"});if(this.node.getSize().y<800)this.node.setStyle("height","800px");var s=new Element("div",{styles:{padding:"40px",border:"1px solid #999999","background-color":"#e6e6e6",overflow:"auto"}}).inject(this.node);var a=this.node.getSize();var r=a.y-80-80;s.setStyle("height",""+r+"px");var c=new Element("div",{styles:{width:"90%",height:"1900px",margin:"auto","background-color":"#ffffff"}}).inject(s);var d=new Element("iframe",{styles:{width:"100%",height:"100%","min-height":"600px",overflow:"auto",border:"1px solid #cccccc"}}).inject(c);d.contentWindow.document.addEventListener("readystatechange",function(){this.body.style.padding="20px 40px"});d.set("src",this.getHTMLFileUrl(e))}else{this.node.setStyles({overflow:"hidden","background-color":"#f3f3f3","min-height":"24px",padding:"18px"});var m=this.getData();if(layout.mobile||COMMON.Browser.Platform.isMobile){if(m.length>300)m=m.substr(0,300)+"……"}var h=new Element("div",{text:m}).inject(this.node)}var h=MWF.xApplication.process.Xform.LP.openOfficeInfor;h=h.replace("{type}",this.json.officeType);var f=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:h}).inject(this.node);var u=this.getOfficeFileUrl();if(!u){this.node.setStyle("display","none")}f.addEvent("click",function(){var t=this.getOfficeFileUrl();if(t){if(window.o2){window.o2.openDocument(t)}else if(window.webkit){window.webkit.messageHandlers.openDocument.postMessage(t)}else{window.open(t)}}}.bind(this))}});