Office.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. /** @class Office Office控件。
  3. * @example
  4. * //可以在脚本中获取该组件
  5. * //方法1:
  6. * var attachment = this.form.get("name"); //获取组件
  7. * //方法2
  8. * var attachment = this.target; //在组件事件脚本中获取
  9. * @extends MWF.xApplication.process.Xform.$Module
  10. * @o2category FormComponents
  11. * @o2range {Process|CMS}
  12. * @hideconstructor
  13. */
  14. MWF.xApplication.process.Xform.Office = MWF.APPOffice = new Class(
  15. /** @lends MWF.xApplication.process.Xform.Office# */
  16. {
  17. Extends: MWF.APP$Module,
  18. isActive: false,
  19. options:{
  20. "ProductCaption": "O2",
  21. "ProductKey": "EDCC626CB85C9A1D3E0D7BDDDC2637753C596725",
  22. "makerCaption": "浙江兰德纵横网络技术股份有限公司",
  23. "makerKey": "E138DABB4AC26C2D8E09FAE59AB3BDE87AFB9D7B",
  24. "version": "5.0.4.0",
  25. "clsid": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0",
  26. "codeBase": "../o2_lib/officecontrol/5040/OfficeControl.cab",
  27. "clsid64": "A64E3073-2016-4baf-A89D-FFE1FAA10EE1",
  28. "codeBase64": "../o2_lib/officecontrol/5040/ofctnewclsid.cab",
  29. "pdfType": "PDF.NtkoDocument",
  30. "pdfVersion": "4.0.0.3",
  31. "pdfCodeBase": "../o2_lib/officecontrol/5040/ntkooledocall.cab",
  32. "pdfCodeBase64": "../o2_lib/officecontrol/5040/ntkooledocall64.cab",
  33. "files": ["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"],
  34. /**
  35. * @event MWF.xApplication.process.Xform.Office#queryLoad
  36. * @ignore
  37. */
  38. /**
  39. * @event MWF.xApplication.process.Xform.Office#postLoad
  40. * @ignore
  41. */
  42. /**
  43. * 点击套红按钮触发。
  44. * @event MWF.xApplication.process.Xform.Office#redFile
  45. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  46. */
  47. /**
  48. * 点击盖章按钮触发。
  49. * @event MWF.xApplication.process.Xform.Office#seal
  50. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  51. */
  52. /**
  53. * Ntko控件执行AfterOpenFromURL事件(BeginOpenFromURL方法执行完毕之后被触发)时执行。</br>
  54. * 本事件可以通过this.event获取当前打开的文档对象。比如,对于一个Word文档,第二个参数是一个Word.Document对象。
  55. * @event MWF.xApplication.process.Xform.Office#afterOpen
  56. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  57. */
  58. /**
  59. * Ntko控件执行OnDocumentOpened事件(Office文档打开完毕)时触发。<br/>
  60. * 本事件可以通过this.event获取以下内容
  61. * <pre><code>
  62. {
  63. url : url, //Office文档路径或者URL
  64. doc : doc //Office文档的自动化接口,比如,对于一个Word文档,第二个参数是一个Word.Document对象。
  65. }
  66. </pre></code>
  67. * @event MWF.xApplication.process.Xform.Office#afterOpenOffice
  68. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  69. */
  70. /**
  71. * 在新建Office文档后触发。
  72. * @event MWF.xApplication.process.Xform.Office#afterCreate
  73. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  74. */
  75. /**
  76. * 在保存Office文档前触发。
  77. * @event MWF.xApplication.process.Xform.Office#beforeSave
  78. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  79. */
  80. /**
  81. * 在保存Office文档后触发。
  82. * @event MWF.xApplication.process.Xform.Office#afterSave
  83. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  84. */
  85. /**
  86. * 在关闭Office文档时执行。
  87. * @event MWF.xApplication.process.Xform.Office#afterCloseOffice
  88. * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
  89. */
  90. "moduleEvents": ["redFile",
  91. "afterOpen",
  92. "afterOpenOffice",
  93. "afterCreate",
  94. "seal",
  95. "beforeSave",
  96. "afterSave",
  97. "afterCloseOffice",
  98. "load"
  99. ]
  100. },
  101. initialize: function(node, json, form, options){
  102. this.node = $(node);
  103. this.node.store("module", this);
  104. this.json = json;
  105. this.form = form;
  106. this.field = true;
  107. this.openedAttachment = null;
  108. },
  109. _loadUserInterface: function(){
  110. this.node.empty();
  111. this.node.setStyles({
  112. "min-height": "100px"
  113. });
  114. // this.isActive = true;
  115. debugger;
  116. if (Browser.name==="ie" || Browser.name==="chrome" || Browser.name==="firefox"){
  117. //if (Browser.name==="ie"){
  118. this.isActive = true;
  119. this.file = null;
  120. if (!this.form.officeList) this.form.officeList=[];
  121. this.form.officeList.push(this);
  122. }
  123. },
  124. _afterLoaded: function(){
  125. if (!this.json.isNotLoadNow){
  126. this.loadOffice();
  127. }
  128. //this.fireEvent("load");
  129. },
  130. loadOffice: function(file){
  131. if (!this.officeLoaded){
  132. if (!this.isActive){
  133. this.loadOfficeNotActive();
  134. }else{
  135. MWF.getJSON("../o2_lib/officecontrol/config.json", function(json){
  136. this.officeConfig = json;
  137. }.bind(this), false);
  138. this.loadOfficeContorl(file);
  139. }
  140. this.officeLoaded = true;
  141. }else{
  142. if (this.officeOCX) this.officeOCX.BeginOpenFromURL(file, true, this.readonly);
  143. }
  144. },
  145. getProgID: function(){
  146. switch (this.json.officeType){
  147. case "word":
  148. return "Word.Document";
  149. case "excel":
  150. return "Excel.Sheet";
  151. case "ppt":
  152. return "PowerPoint.Show";
  153. }
  154. return "Word.Document"
  155. },
  156. defaultParam: function(readonly){
  157. var o = {
  158. "ProductCaption": this.json.productCaption || this.options.ProductCaption,
  159. "ProductKey": this.json.productKey || this.options.ProductKey,
  160. "MakerCaption": this.officeConfig.makerCaption || this.json.makerCaption || this.options.makerCaption,
  161. "MakerKey": this.officeConfig.makerKey || this.options.makerKey || this.options.MakerKey,
  162. "Titlebar": "0",
  163. "Menubar": "0",
  164. "ToolBars": (readonly) ? "0" : "1",
  165. "Statusbar": "0",
  166. "IsUseUTF8URL": "1",
  167. "IsUseUTF8Data": "1",
  168. "BorderStyle": (readonly) ? "0" : "0",
  169. "IsNoCopy": "0",
  170. "IsResetToolbarsOnOpen": "1",
  171. "FileNew": "0",
  172. "FileOpen": "1",
  173. "FileClose": "0",
  174. "FileSave": "0",
  175. "FileProperties": "0"
  176. };
  177. return o;
  178. },
  179. loadOfficeContorl: function(file){
  180. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  181. if (!layout.desktop.offices) layout.desktop.offices = {};
  182. layout.desktop.offices[this.getOfficeObjectId()] = this;
  183. if (this.readonly){
  184. this.loadOfficeRead(file);
  185. }else if (this.json.isReadonly){
  186. this.readonly = true;
  187. this.loadOfficeRead(file);
  188. }else{
  189. if (this.json.readScript && this.json.readScript.code){
  190. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  191. if (flag){
  192. this.readonly = true;
  193. this.loadOfficeRead(file);
  194. }else{
  195. this.loadOfficeEdit(file);
  196. }
  197. }else{
  198. this.loadOfficeEdit(file);
  199. }
  200. }
  201. },
  202. loadOfficeSpacer: function(){
  203. var size = this.node.getSize();
  204. this.officeNode = new Element("div#officeNode", {
  205. "styles": this.form.css.officeAreaNode
  206. }).inject(this.node);
  207. var y = size.y-40;
  208. this.officeNode.setStyle("height", ""+y+"px");
  209. this.form.app.addEvent("uncurrent", function(){
  210. var display = this.officeNode.getStyle("display");
  211. this.officeNode.store("officeDisplay", display);
  212. this.officeNode.setStyle("display", "none");
  213. }.bind(this));
  214. this.form.app.addEvent("current", function(){
  215. var display = this.officeNode.retrieve("officeDisplay");
  216. if (display) this.officeNode.setStyle("display", display);
  217. if (this.officeOCX) this.officeOCX.Activate(true);
  218. }.bind(this));
  219. this.form.app.addEvent("queryClose", function(){
  220. this.fireEvent("queryClose");
  221. var id = this.getOfficeObjectId();
  222. layout.desktop.offices[id] = null;
  223. delete layout.desktop.offices[id];
  224. }.bind(this));
  225. },
  226. hide: function(){
  227. if (this.officeNode.getStyle("display")!="none"){
  228. var display = this.officeNode.getStyle("display");
  229. this.officeNode.store("officeDisplay", display);
  230. this.officeNode.setStyle("display", "none");
  231. }
  232. },
  233. show: function(){
  234. if ((layout.desktop.currentApp && layout.desktop.currentApp.appId===this.form.app.appId) || this.form.app.inBrowser){
  235. var display = this.officeNode.retrieve("officeDisplay");
  236. if (display) this.officeNode.setStyle("display", display);
  237. if (this.officeOCX) this.officeOCX.Activate(true);
  238. }
  239. },
  240. isCover: function(node){
  241. },
  242. getFormId: function(){
  243. var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  244. return "form"+this.json.id+id;
  245. },
  246. getFileName: function(){
  247. var ename = "docx";
  248. switch (this.json.officeType){
  249. case "word":
  250. ename = "docx";
  251. break;
  252. case "excel":
  253. ename = "xlsx";
  254. break;
  255. case "ppt":
  256. ename = "pptx";
  257. }
  258. var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  259. return "file"+this.json.id+id+"."+ename;
  260. },
  261. getOfficeObjectId: function(){
  262. var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  263. return "NTKOOCX"+this.json.id+id;
  264. },
  265. getFileInputName: function(){
  266. var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  267. return "fileInput"+this.json.id+id;
  268. },
  269. getTempleteUrl: function(){
  270. //return "../x_desktop/temp/杭州城管委文件.doc";
  271. if (this.json.template){
  272. var root = "";
  273. var flag = this.json.template.substr(0,1);
  274. if (flag==="/"){
  275. root = this.json.template.substr(1, this.json.template.indexOf("/", 1)-1);
  276. }else{
  277. root = this.json.template.substr(0, this.json.template.indexOf("/"));
  278. }
  279. if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  280. var host = MWF.Actions.getHost(root);
  281. return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  282. }
  283. }
  284. return this.json.template;
  285. },
  286. getFile: function(site){
  287. var file = null;
  288. atts = this.form.businessData.attachmentList;
  289. for (var i=0; i<atts.length; i++){
  290. //if ((atts[i].name===fileName) || (atts[i].site===this.json.id)){
  291. //if (atts[i].site===this.json.id){
  292. if (atts[i].site===site){
  293. file = atts[i];
  294. break;
  295. }
  296. }
  297. return file
  298. },
  299. getOfficeFileUrl: function(){
  300. var fileName = this.getFileName();
  301. this.readSite = this.json.id;
  302. if (this.json.fileSite && this.json.fileSite.code){
  303. this.readSite = this.form.Macro.exec(this.json.fileSite.code, this);
  304. }
  305. var file = this.getFile(this.readSite);
  306. if (!file) if (this.readSite !== this.json.id) file = this.getFile(this.json.id);
  307. if (file){
  308. this.file = file;
  309. var url = "";
  310. if (!this.form.businessData.workCompleted){
  311. url = this.form.workAction.action.actions.getAttachmentData.uri;
  312. url = url.replace("{id}", encodeURIComponent(file.id));
  313. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  314. }else{
  315. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  316. url = url.replace("{id}", encodeURIComponent(file.id));
  317. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  318. }
  319. }else{
  320. return this.getTempleteUrl();
  321. }
  322. },
  323. /**
  324. * @summary 允许编辑Office文档
  325. * @example
  326. * this.form.get("fieldId").editEnabled();
  327. */
  328. editEnabled: function(){
  329. try {
  330. this.officeOCX.ActiveDocument.Unprotect();
  331. }catch(e){}
  332. },
  333. /**
  334. * @summary 设置Office文档为只读
  335. * @example
  336. * this.form.get("fieldId").docReadonly();
  337. */
  338. docReadonly: function(){
  339. this.protect(3);
  340. },
  341. /**
  342. * @summary 设置Office文档状态
  343. * @example
  344. * this.form.get("fieldId").protect(1);
  345. * @param {Number} type 1(批注),2(填写窗体),3(只读),0(修订),-1(限制编辑样式)
  346. */
  347. protect: function(type){
  348. // wdAllowOnlyComments = 1 //批注
  349. // wdAllowOnlyFormFields = 2 //填写窗体
  350. // wdAllowOnlyReading = 3 //只读
  351. // wdAllowOnlyRevisions = 0 //修订
  352. // wdNoProtection = -1 //限制编辑样式
  353. try {
  354. this.officeOCX.ActiveDocument.Protect(type);
  355. }catch(e){}
  356. },
  357. /**
  358. * @summary 设置Office文档保留痕迹
  359. */
  360. startRevisions: function(){
  361. if (this.officeOCX && (this.officeOCX.DocType==1 || this.officeOCX.DocType==6)){
  362. this.officeOCX.ActiveDocument.Application.UserName = layout.desktop.session.user.name;
  363. this.officeOCX.ActiveDocument.Application.UserInitials = layout.desktop.session.user.name;
  364. if (!this.isNew){
  365. this.officeOCX.ActiveDocument.TrackRevisions = true;
  366. this.officeOCX.ActiveDocument.showRevisions = false;
  367. }else{
  368. this.officeOCX.ActiveDocument.TrackRevisions = false;
  369. this.officeOCX.ActiveDocument.showRevisions = false;
  370. }
  371. this.officeOCX.ActiveDocument.Application.UserName = layout.desktop.session.user.name;
  372. if( this.officeOCX.ActiveDocument && this.officeOCX.ActiveDocument.Application ){
  373. if(15==this.officeOCX.getOfficeVer()){//如果是OFFICE 2013则设置Options.UseLocalUserInfo属性为true,TANGER_OCX_OBJ为文档控件对象
  374. this.officeOCX.ActiveDocument.Application.Options.UseLocalUserInfo=true;
  375. this.officeOCX.WebUserName= layout.desktop.session.user.name;
  376. }
  377. }
  378. }
  379. //this.officeOCX.FullScreenMode = true;
  380. },
  381. /**
  382. * @summary 设置Office文档取消保留痕迹
  383. */
  384. stopRevisions: function(accept){
  385. this.officeOCX.ActiveDocument.TrackRevisions = false;
  386. this.officeOCX.ActiveDocument.showRevisions = false;
  387. if (accept) this.officeOCX.ActiveDocument.AcceptAllRevisions();
  388. },
  389. createMenuAction: function(id, title, img){
  390. var title = title || MWF.xApplication.process.Xform.LP[id];
  391. return new Element("div", {
  392. "MWFnodeid": id,
  393. "MWFnodetype": "MWFToolBarButton",
  394. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  395. "title": title,
  396. "MWFButtonAction": "menuAction",
  397. "MWFButtonText": title
  398. }).inject(this.menuNode);
  399. },
  400. createMenuActionMenu: function(id, title, img){
  401. var title = title || MWF.xApplication.process.Xform.LP[id];
  402. return new Element("div", {
  403. "MWFnodeid": id,
  404. "MWFnodetype": "MWFToolBarMenu",
  405. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  406. "title": title,
  407. "MWFButtonAction": "menuAction",
  408. "MWFButtonText": title
  409. }).inject(this.menuNode);
  410. },
  411. createMenuActionMenuItem: function(id, title, img, action){
  412. return new Element("div", {
  413. "MWFnodeid": id,
  414. "MWFnodetype": "MWFToolBarMenuItem",
  415. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  416. "title": title,
  417. "MWFButtonAction": action,
  418. "MWFButtonText": title
  419. }).inject(this.menuNode);
  420. },
  421. menuAction: function(button){
  422. switch (button.buttonID){
  423. case "menu_new":
  424. this.officeOCX.CreateNew(this.getProgID());
  425. break;
  426. case "menu_openfile":
  427. this.officeOCX.ShowDialog(1);
  428. break;
  429. case "menu_savefile":
  430. this.officeOCX.ShowDialog(3);
  431. break;
  432. case "revisions":
  433. this.toggleRevisions(button);
  434. break;
  435. case "menu_fullscreen":
  436. this.officeOCX.FullScreenMode = true;
  437. break;
  438. case "toolbar":
  439. var text = (this.officeOCX.ToolBars) ? MWF.xApplication.process.Xform.LP.menu_toolbar_show : MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  440. button.setText(text);
  441. this.officeOCX.ToolBars = !this.officeOCX.ToolBars;
  442. break;
  443. case "menu_preview":
  444. this.officeOCX.PrintPreview();
  445. break;
  446. case "menu_showHistory":
  447. this.showHistory(button);
  448. break;
  449. case "menu_redfile":
  450. this.redFile();
  451. break;
  452. case "menu_seal":
  453. this.seal();
  454. break;
  455. case "menu_att":
  456. button.menu.clearItems();
  457. button._loadMenuItem(this.createMenuActionMenuItem("", MWF.xApplication.process.Xform.LP.menu_file, "109.png", "openFile"));
  458. button._loadMenuLine();
  459. var attcs = this.json.attachmentIds.split(/,\s*|;\s*|,\s*|;\s*/g);
  460. attcs.each(function(att){
  461. this.form.businessData.attachmentList.each(function (attachement) {
  462. if(attachement.site===att){
  463. if (attachement.control.allowEdit){
  464. if (this.options.files.indexOf(attachement.extension.toLowerCase())!==-1){
  465. button._loadMenuItem(this.createMenuActionMenuItem(attachement.id, attachement.name, "14.png", "openAttachment:"+attachement.id+":"+att+":"+attachement.name));
  466. }
  467. }
  468. }
  469. }.bind(this));
  470. /*var attc = this.form.all[att];
  471. if (attc){
  472. attc.attachmentController.attachments.each(function(a){
  473. if (a.data.control.allowEdit){
  474. if (this.options.files.indexOf(a.data.extension.toLowerCase())!==-1){
  475. button._loadMenuItem(this.createMenuActionMenuItem(a.data.id, a.data.name, "14.png", "openAttachment:"+a.data.id+":"+att+":"+a.data.name));
  476. }
  477. }
  478. }.bind(this));
  479. }*/
  480. }.bind(this));
  481. }
  482. },
  483. openFile: function(bt, e, item){
  484. if (this.openedAttachment){
  485. this.save();
  486. this.loadOfficeEdit();
  487. }
  488. },
  489. openAttachment: function(id, site, name){
  490. if (!this.openedAttachment || this.openedAttachment.id!==id){
  491. this.save();
  492. if (this.form.businessData.workCompleted){
  493. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(id, this.form.businessData.workCompleted.id, function(url){
  494. this.openedAttachment = {"id": id, "site": site, "name": name};
  495. this.officeOCX.BeginOpenFromURL(url, true, this.readonly || this.json.isAttReadonly );
  496. }.bind(this));
  497. }else{
  498. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(id, this.form.businessData.work.id, function(url){
  499. this.openedAttachment = {"id": id, "site": site, "name": name};
  500. this.officeOCX.BeginOpenFromURL(url, true, this.readonly || this.json.isAttReadonly);
  501. }.bind(this));
  502. }
  503. }
  504. },
  505. loadMenu: function(){
  506. if (!this.isMenuLoad){
  507. if (this.json.menuEditButtons && this.json.menuEditButtons.length){
  508. this.menuNode = new Element("div", {"styles": this.form.css.officeMenuNode}).inject(this.node, "top");
  509. MWF.require("MWF.widget.Toolbar", function(){
  510. this.toolbarWidget = new MWF.widget.Toolbar(this.menuNode, {"style": "xform_blue_simple"}, this);
  511. if (this.json.menuEditButtons.indexOf("new")!==-1){
  512. this.newItem = this.createMenuAction("menu_new", "", "99.png");
  513. }
  514. if (this.json.menuEditButtons.indexOf("open")!==-1){
  515. this.openItem = this.createMenuAction("menu_openfile", "", "77.png");
  516. }
  517. if (this.json.menuEditButtons.indexOf("save")!==-1){
  518. this.saveItem = this.createMenuAction("menu_savefile", "", "67.png");
  519. }
  520. if (this.json.menuEditButtons.indexOf("revisions")!==-1){
  521. var text = MWF.xApplication.process.Xform.LP.menu_revisions_show;
  522. try {
  523. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup !== 0){
  524. text = MWF.xApplication.process.Xform.LP.menu_revisions_hide;
  525. }
  526. }catch(e){}
  527. this.revisionsItem = this.createMenuAction("revisions", text, "76.png");
  528. }
  529. if (this.json.menuEditButtons.indexOf("fullscreen")!==-1){
  530. this.fullscreenItem = this.createMenuAction("menu_fullscreen", "", "4.png");
  531. }
  532. if (this.json.menuEditButtons.indexOf("toolbar")!==-1){
  533. if (!this.readonly){
  534. var text = MWF.xApplication.process.Xform.LP.menu_toolbar_show;
  535. if (this.officeOCX.ToolBars){
  536. text = MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  537. }
  538. this.toolbarItem = this.createMenuAction("toolbar", text, "91.png");
  539. }
  540. }
  541. if (this.json.menuEditButtons.indexOf("preview")!==-1){
  542. this.fullscreenItem = this.createMenuAction("menu_preview", "", "21.png");
  543. }
  544. if (this.json.menuEditButtons.indexOf("showHistory")!==-1){
  545. atts = this.form.businessData.attachmentList;
  546. if (atts.some(function(att){
  547. return att.site == this.json.id+"history";
  548. }.bind(this))){
  549. this.historyItem = this.createMenuAction("menu_showHistory", "", "115.png");
  550. }
  551. }
  552. if (this.json.menuEditButtons.indexOf("redfile")!==-1){
  553. if (!this.readonly) this.redItem = this.createMenuAction("menu_redfile", "", "12.png");
  554. }
  555. if (this.json.menuEditButtons.indexOf("seal")!==-1){
  556. if (!this.readonly) this.sealItem = this.createMenuAction("menu_seal", "", "84.png");
  557. }
  558. if (this.json.isOpenAttachment){
  559. if (this.json.attachmentIds){
  560. this.sealItem = this.createMenuActionMenu("menu_att", "", "14.png");
  561. }
  562. }
  563. this.toolbarWidget.load();
  564. }.bind(this));
  565. }
  566. this.isMenuLoad = true;
  567. }
  568. },
  569. showHistory: function(button){
  570. if (this.historyItem.get("text") == MWF.xApplication.process.Xform.LP.menu_hideHistory){
  571. var url = this.getOfficeFileUrl();
  572. if (url){
  573. var id = this.getOfficeObjectId();
  574. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  575. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  576. button.setText(MWF.xApplication.process.Xform.LP.menu_showHistory);
  577. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  578. this.historyMode = false;
  579. }
  580. }else{
  581. MWF.require("MWF.xDesktop.Dialog", function(){
  582. var width = 680;
  583. var height = 500;
  584. var p = MWF.getCenterPosition(this.form.app.content, width, height);
  585. var _self = this;
  586. var dlg = new MWF.xDesktop.Dialog({
  587. "title": MWF.xApplication.process.Xform.LP.menu_showHistory,
  588. //"style": "work",
  589. "style" : this.form.json.dialogStyle || "user",
  590. "top": p.y-100,
  591. "left": p.x,
  592. "fromTop": p.y-100,
  593. "fromLeft": p.x,
  594. "width": width,
  595. "height": height,
  596. "html": "<div></div>",
  597. "container": this.form.app.content,
  598. "isClose": true,
  599. "buttonList": [
  600. {
  601. "text": MWF.xApplication.process.Xform.LP.close,
  602. "action": function(){this.close();}
  603. }
  604. ],
  605. "onPostShow": function(){
  606. this.showHistoryContent(dlg, button)
  607. }.bind(this)
  608. });
  609. dlg.show();
  610. }.bind(this));
  611. }
  612. },
  613. showHistoryContent: function(dlg, button){
  614. dlg.content.setStyle("overflow", "auto");
  615. atts = this.form.businessData.attachmentList;
  616. var site = this.json.id+"history";
  617. for (var i=0; i<atts.length; i++){
  618. if ((atts[i].site===site)){
  619. //for (var x=0; x<31; x++){
  620. file = atts[i];
  621. var div = new Element("div", {
  622. "styles": {
  623. "margin": "20px auto 0px auto",
  624. "height": "30px",
  625. "line-height": "30px",
  626. "width": "80%",
  627. "font-size": "16px",
  628. "color": "#666666",
  629. "border-bottom": "1px solid #CCCCCC"
  630. },
  631. "value": file.id
  632. }).inject(dlg.content);
  633. var fileNameNode = new Element("div", {
  634. "styles": {"float": "left"},
  635. "text": file.name
  636. }).inject(div);
  637. var buttonNode = new Element("input", {
  638. "type": "button",
  639. "styles": {"float": "right"},
  640. "value": "查看版本",
  641. "events": {
  642. "click": function(e){
  643. this.openOfficeHistory(e, dlg, button);
  644. }.bind(this)
  645. }
  646. }).inject(div);
  647. //}
  648. }
  649. }
  650. },
  651. openOfficeHistory: function(e, dlg, button){
  652. var fileName = e.target.getParent().get("value");
  653. if (!this.form.businessData.workCompleted){
  654. url = this.form.workAction.action.actions.getAttachmentData.uri;
  655. url = url.replace("{id}", encodeURIComponent(fileName));
  656. url = this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  657. }else{
  658. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  659. url = url.replace("{id}", encodeURIComponent(fileName));
  660. url = this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  661. }
  662. dlg.close();
  663. this.save();
  664. this.officeOCX.BeginOpenFromURL(url, true, true);
  665. this.historyMode = true;
  666. if (button){
  667. button.setText(MWF.xApplication.process.Xform.LP.menu_hideHistory)
  668. }
  669. },
  670. /**
  671. * @summary 盖章
  672. */
  673. seal: function(){
  674. this.fireEvent("seal");
  675. },
  676. /**
  677. * @summary 套红
  678. */
  679. redFile: function(){
  680. // try {
  681. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter){
  682. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  683. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  684. }
  685. this.officeOCX.ActiveDocument.showRevisions = false;
  686. this.stopRevisions(true);
  687. this.fireEvent("redFile");
  688. // this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  689. // this.officeOCX.ActiveDocument.Application.Selection.Font.Name = "仿宋";
  690. // this.officeOCX.ActiveDocument.Application.Selection.Font.Size = 14;
  691. // this.officeOCX.ActiveDocument.Application.Selection.Cut();
  692. //
  693. // this.officeOCX.OpenFromUrl("../x_desktop/temp/1.doc", false);
  694. //
  695. // var mark = this.officeOCX.ActiveDocument.Bookmarks("bodyCw");
  696. //
  697. // mark.Range.PasteSpecial(false, false, 0, false, 2);
  698. //mark.Range.Paste();
  699. // }catch(e){
  700. // throw e;
  701. // }
  702. },
  703. /**
  704. * @summary 显示痕迹
  705. */
  706. showRevisions: function(){
  707. try {
  708. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter) {
  709. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  710. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  711. }
  712. this.officeOCX.ActiveDocument.showRevisions = true;
  713. }catch(e){}
  714. },
  715. /**
  716. * @summary 隐藏痕迹
  717. */
  718. hideRevisions: function(){
  719. try {
  720. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter) {
  721. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  722. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  723. }
  724. this.officeOCX.ActiveDocument.showRevisions = false;
  725. }catch(e){}
  726. },
  727. toggleRevisions: function(button){
  728. var t = this.revisionsItem.get("text");
  729. if (t===MWF.xApplication.process.Xform.LP.menu_revisions_show){
  730. button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_hide);
  731. try {
  732. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  733. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  734. }catch(e){}
  735. try {
  736. this.officeOCX.ActiveDocument.showRevisions = true;
  737. }catch(e){}
  738. }else{
  739. button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_show);
  740. try {
  741. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  742. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  743. }catch(e){}
  744. try {
  745. this.officeOCX.ActiveDocument.showRevisions = false;
  746. }catch(e){}
  747. }
  748. },
  749. afterOpen: function(){
  750. // this.officeOCX.AddCustomButtonOnMenu(0,"按钮0",false);
  751. // this.officeOCX.AddCustomButtonOnMenu(1,"按钮1",true,1);
  752. // this.officeOCX.AddCustomButtonOnMenu(2,"按钮2",true,2);
  753. // this.officeOCX.AddCustomButtonOnMenu(3,"按钮3",false,3);
  754. //
  755. //
  756. // this.officeOCX.AddCustomToolButton("预览(0)", 10);
  757. //
  758. // alert(111);
  759. if (this.readonly) this.docReadonly();
  760. if (this.json.trackRevisions==="1") this.startRevisions();
  761. var scale = (this.readonly) ? this.json.readScale : this.json.editScale;
  762. if (scale) scale = scale.toInt();
  763. if (scale){
  764. this.officeOCX.ActiveDocument.ActiveWindow.ActivePane.View.Zoom.Percentage = scale;
  765. }
  766. var display = this.officeNode.getStyle("display");
  767. //window.setTimeout(function(){
  768. this.officeOCX.Activate(false);
  769. this.officeNode.setStyle("display", "none");
  770. window.setTimeout(function(){
  771. this.officeNode.setStyle("display", display);
  772. this.officeOCX.Activate(true);
  773. }.bind(this), 10);
  774. //}.bind(this), 10);
  775. //if (this.officeOCX) this.officeOCX.Activate(true);
  776. // this.officeNode.scrollIntoView();
  777. // this.form.app.node.scrollTo(0);
  778. },
  779. loadOfficeEditFirefox: function(file){
  780. if (!this.officeOCX){
  781. this.loadOfficeSpacer();
  782. this.node.setStyle("pisition", "absolute");
  783. var codeBase = this.json.codeBase || this.options.codeBase;
  784. var version = this.json.version || this.options.version;
  785. var classid = this.json.clsid || this.options.clsid;
  786. var objectHtml = "";
  787. if (navigator.userAgent.indexOf("Linux") > -1) {
  788. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'>" +
  789. "<OBJECT id='"+this.getOfficeObjectId()+"' " +
  790. "type='application/ntko-plug' height='99%' width='100%' style='HEIGHT: 99%; WIDTH: 100%' "
  791. }else{
  792. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  793. "type='application/ntko-plug' " +
  794. "style='HEIGHT: 99%; WIDTH: 100%' " +
  795. "height='99%' width='100%' " +
  796. "codeBase='"+codeBase+"#version="+version+"' " +
  797. "clsid='{"+classid+"}' ";
  798. }
  799. // var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  800. // "type='application/ntko-plug' " +
  801. // "style='HEIGHT: 99%; WIDTH: 100%' " +
  802. // "height='99%' width='100%' " +
  803. // "codeBase='"+codeBase+"#version="+version+"' " +
  804. // "clsid='{"+classid+"}' ";
  805. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  806. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  807. objectHtml += "ForOndocumentopened='OnComplete3' ";
  808. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  809. var pars = this.defaultParam();
  810. pars = Object.merge(pars, this.json.ntkoEditProperties);
  811. pars = Object.merge(pars, this.json.editProperties);
  812. Object.each(pars, function(p, key){
  813. objectHtml += "_"+key+"='"+p+"'";
  814. });
  815. objectHtml += ">";
  816. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"../o2_lib/officecontrol/ntkoplugins.xpi\">安装组件</a></SPAN>";
  817. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  818. this.officeNode.appendHTML(objectHtml);
  819. this.officeForm = this.officeNode.getFirst();
  820. this.officeOCX = this.officeNode.getFirst().getFirst();
  821. if(window.navigator.platform=="Win64"){
  822. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  823. }
  824. if(window.navigator.platform=="Win32"){
  825. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  826. }
  827. this.doOfficeOCXEvents();
  828. }
  829. var url = this.getOfficeFileUrl();
  830. if (url){
  831. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  832. }else{
  833. this.officeOCX.CreateNew(this.getProgID());
  834. this.fireEvent("afterCreate");
  835. }
  836. },
  837. loadOfficeEditChrome: function(file){
  838. if (!this.officeOCX){
  839. this.loadOfficeSpacer();
  840. this.node.setStyle("pisition", "absolute");
  841. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  842. var version = this.officeConfig.version || this.json.version || this.options.version;
  843. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  844. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  845. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  846. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  847. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  848. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  849. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  850. var objectHtml = "";
  851. // if (navigator.userAgent.indexOf("Linux") > -1) {
  852. // objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  853. // "type='application/ntko-plug' height='99%' width='100%' style='HEIGHT: 99%; WIDTH: 100%' "
  854. // }else{
  855. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT type='application/ntko-plug' id='"+this.getOfficeObjectId()+"' " +
  856. "height='99%' width='100%' " +
  857. "style='HEIGHT: 99%; WIDTH: 100%' " +
  858. "codeBase='"+codeBase+"#version="+version+"' " +
  859. "clsid='{"+classid+"}'";
  860. // }
  861. // if(window.navigator.platform=="Win64"){
  862. // objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  863. // "style='HEIGHT: 99%; WIDTH: 100%' " +
  864. // "codeBase='"+codeBase64+"#version="+version+"' " +
  865. // "classid='{"+classid64+"}'>";
  866. // }else{
  867. // objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  868. // "style='HEIGHT: 99%; WIDTH: 100%' " +
  869. // "codeBase='"+codeBase+"#version="+version+"' " +
  870. // "classid='{"+classid+"}'";
  871. // }
  872. // this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  873. // this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  874. // this.addOfficeEvent(id, "OnDocumentClosed()", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentClosed();");
  875. // document.write('ForOnpublishAshtmltourl="ntkopublishashtml"');
  876. // document.write('ForOnpublishAspdftourl="ntkopublishaspdf"');
  877. // document.write('ForOnSaveAsOtherFormatToUrl="ntkosaveasotherurl"');
  878. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  879. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  880. objectHtml += "ForOndocumentopened='OnComplete3' ";
  881. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  882. var pars = this.defaultParam();
  883. pars = Object.merge(pars, this.json.ntkoEditProperties);
  884. pars = Object.merge(pars, this.json.editProperties);
  885. Object.each(pars, function(p, key){
  886. objectHtml += "_"+key+"='"+p+"'";
  887. });
  888. objectHtml += ">";
  889. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"../o2_lib/officecontrol/ntkoplugins.crx\">安装组件</a></SPAN>";
  890. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  891. this.officeNode.appendHTML(objectHtml);
  892. this.officeForm = this.officeNode.getFirst();
  893. this.officeOCX = this.officeNode.getFirst().getFirst();
  894. if(window.navigator.platform=="Win64"){
  895. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  896. }
  897. if(window.navigator.platform=="Win32"){
  898. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  899. }
  900. this.doOfficeOCXEvents();
  901. }
  902. var url = this.getOfficeFileUrl();
  903. if (url){
  904. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  905. }else{
  906. window.setTimeout(function(){
  907. this.officeOCX.CreateNew("WPS.Document");
  908. }.bind(this), 5000);
  909. //this.officeOCX.CreateNew(this.getProgID());
  910. this.fireEvent("afterCreate");
  911. }
  912. },
  913. loadOfficeEdit: function(file){
  914. debugger;
  915. if (Browser.name==="chrome"){
  916. this.loadOfficeEditChrome(file);
  917. }else if (Browser.name==="firefox") {
  918. this.loadOfficeEditFirefox(file);
  919. }else{
  920. this.loadOfficeEditIE(file);
  921. }
  922. this.openedAttachment = null
  923. },
  924. getAutoSavedAttachments: function(){
  925. this.autoSavedAttachments = [];
  926. this.form.businessData.attachmentList.each(function(att){
  927. if (att.site===this.json.id+"autosave") this.autoSavedAttachments.push(att);
  928. }.bind(this));
  929. },
  930. loadOfficeEditIE: function(file){
  931. if (!this.officeOCX){
  932. this.loadOfficeSpacer();
  933. //this.loadMenu();
  934. this.node.setStyle("pisition", "absolute");
  935. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  936. var version = this.officeConfig.version || this.json.version || this.options.version;
  937. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  938. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  939. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  940. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  941. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  942. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  943. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  944. var objectHtml = "";
  945. if(window.navigator.platform=="Win64"){
  946. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  947. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  948. "codeBase=\""+codeBase64+"#version="+version+"\" " +
  949. "classid=\"clsid:"+classid64+"\">";
  950. }else{
  951. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  952. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  953. "codeBase=\""+codeBase+"#version="+version+"\" " +
  954. "classid=\"clsid:"+classid+"\">";
  955. }
  956. var pars = this.defaultParam();
  957. pars = Object.merge(pars, this.json.ntkoEditProperties);
  958. pars = Object.merge(pars, this.json.editProperties);
  959. Object.each(pars, function(p, key){
  960. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  961. });
  962. //objectHtml += "<div style=\"color:red; position:relative; top:-800px; background:#eeeeee; height:760px; padding:20px; text-align:center; font-size:18px; cursor: pointer \">如果不能自动安装控件,请将在点击此处下载并安装签章客户端。</div>";
  963. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input type='hidden' value='' name='fileName'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  964. this.officeNode.appendHTML(objectHtml);
  965. this.officeForm = this.officeNode.getFirst();
  966. this.officeOCX = this.officeNode.getFirst().getFirst();
  967. if(window.navigator.platform=="Win64"){
  968. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  969. }else{
  970. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  971. }
  972. //TANGER_OCX_OBJ.CreateNew("word.document");
  973. //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.7","../x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  974. this.doOfficeOCXEvents();
  975. }
  976. this.getAutoSavedAttachments();
  977. if (this.autoSavedAttachments && this.autoSavedAttachments.length){
  978. this.openRecoverAutoSaveDlg();
  979. }else{
  980. this.openOfficeFile(file);
  981. }
  982. },
  983. openOfficeFile: function(file){
  984. var url = file || this.getOfficeFileUrl();
  985. if (url){
  986. //layout.desktop.tmpOffice = this;
  987. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  988. }else{
  989. this.isNew = true;
  990. this.officeOCX.CreateNew(this.getProgID());
  991. this.fireEvent("afterCreate");
  992. }
  993. //begin auto save
  994. if (this.json.isAutoSave){
  995. if (!this.autoSaveTimerID){
  996. this.autoSave();
  997. this.form.app.addEvent("queryClose", function(){
  998. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  999. }.bind(this));
  1000. }
  1001. }
  1002. },
  1003. clearAutoSaveAttachments: function(){
  1004. this.form.businessData.attachmentList.each(function(att){
  1005. if (att.site===this.json.id+"autosave") o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id);
  1006. }.bind(this));
  1007. this.autoSavedAttachments = [];
  1008. },
  1009. getRecoverItems: function(recoverItemNode){
  1010. var css = this.form.css;
  1011. var _self = this;
  1012. this.autoSavedAttachments.each(function(att){
  1013. var node = new Element("div", {"styles": css.officeRecoverItemNode}).inject(recoverItemNode);
  1014. var actionNode = new Element("div", {"styles": css.officeRecoverItemActionNode}).inject(node);
  1015. var titleNode = new Element("div", {"styles": css.officeRecoverItemTitleNode, "text": att.name}).inject(node);
  1016. node.store("att", att);
  1017. actionNode.addEvent("click", function(e){
  1018. var n = this.getParent();
  1019. var att = n.retrieve("att");
  1020. _self.form.workAction.getAttachmentData(att.id, _self.form.businessData.work.id);
  1021. e.stopPropagation();
  1022. });
  1023. node.addEvents({
  1024. "mouseover": function(){
  1025. var isSelected = this.retrieve("isSelected");
  1026. if (!isSelected) this.setStyles(css.officeRecoverItemNode_over);
  1027. },
  1028. "mouseout": function(){
  1029. var isSelected = this.retrieve("isSelected");
  1030. if (!isSelected) this.setStyles(css.officeRecoverItemNode)
  1031. },
  1032. "click": function(){
  1033. var isSelected = this.retrieve("isSelected");
  1034. if (isSelected){
  1035. this.setStyles(css.officeRecoverItemNode);
  1036. this.getFirst().setStyles(css.officeRecoverItemActionNode);
  1037. this.store("isSelected", false);
  1038. }else{
  1039. var items = recoverItemNode.getChildren();
  1040. items.each(function(item){
  1041. item.setStyles(css.officeRecoverItemNode);
  1042. item.getFirst().setStyles(css.officeRecoverItemActionNode);
  1043. item.store("isSelected", false);
  1044. });
  1045. this.setStyles(css.officeRecoverItemNode_current);
  1046. this.getFirst().setStyles(css.officeRecoverItemActionNode_current);
  1047. this.store("isSelected", true);
  1048. }
  1049. }
  1050. });
  1051. }.bind(this));
  1052. },
  1053. openRecoverAutoSaveDlg: function(){
  1054. var node = new Element("div", {"styles": {"overflow": "hidden", "padding": "0 30px"}});
  1055. var html = "<div style=\"line-height: 30px; height: 30px; color: #333333; overflow: hidden\">请选择要恢复的正文版本:</div>";
  1056. html += "<div style=\"max-height: 300px; margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
  1057. node.set("html", html);
  1058. var recoverItemNode = node.getLast();
  1059. this.getRecoverItems(recoverItemNode);
  1060. node.inject(this.form.app.content);
  1061. var _self = this;
  1062. var dlg = o2.DL.open({
  1063. "title": "恢复正文",
  1064. //"style": "work",
  1065. "isResize": false,
  1066. "content": node,
  1067. "width": 600,
  1068. "onPostClose": function(){
  1069. _self.clearAutoSaveAttachments();
  1070. },
  1071. "buttonList": [
  1072. {
  1073. "text": MWF.xApplication.process.Xform.LP.recover,
  1074. "action": function(d, e){
  1075. this.doRecoverFile(node, e, dlg);
  1076. }.bind(this)
  1077. },
  1078. {
  1079. "text": MWF.xApplication.process.Xform.LP.notRecover,
  1080. "action": function(d, e){
  1081. this.doNotRecoverFile(node, e, dlg);
  1082. }.bind(this)
  1083. }
  1084. ]
  1085. });
  1086. },
  1087. doNotRecoverFile: function(node, e, dlg){
  1088. var _self = this;
  1089. this.form.app.confirm("infor", e, this.form.app.lp.notRecoverFileConfirmTitle, this.form.app.lp.notRecoverFileConfirmContent, 450, 120, function(){
  1090. this.close();
  1091. dlg.close();
  1092. _self.openOfficeFile();
  1093. }, function(){
  1094. this.close();
  1095. }, null, null, this.form.json.confirmStyle);
  1096. },
  1097. doRecoverFile: function(node, e, dlg){
  1098. var recoverItemNode = node.getLast();
  1099. var items = recoverItemNode.getChildren();
  1100. var _self = this;
  1101. for (var i=0; i<items.length; i++){
  1102. if (items[i].retrieve("isSelected")){
  1103. var text = this.form.app.lp.recoverFileConfirmContent;
  1104. var att = items[i].retrieve("att");
  1105. text = text.replace("{att}", att.name);
  1106. this.form.app.confirm("infor", e, this.form.app.lp.recoverFileConfirmTitle, text, 450, 120, function(){
  1107. this.close();
  1108. dlg.close();
  1109. _self.form.workAction.getAttachmentUrl(att.id, _self.form.businessData.work.id, function(file){
  1110. _self.openOfficeFile(file);
  1111. dlg.close();
  1112. });
  1113. }, function(){
  1114. this.close();
  1115. }, null, null, this.form.json.confirmStyle);
  1116. break;
  1117. }
  1118. }
  1119. },
  1120. checkAutoSaveNumber: function(callback){
  1121. if (!this.autoSavedAttachments) this.autoSavedAttachments = [];
  1122. if (!this.json.autoSaveNumber) this.json.autoSaveNumber = 3;
  1123. if (this.autoSavedAttachments.length >= this.json.autoSaveNumber.toInt()){
  1124. //delete first att
  1125. var att = this.autoSavedAttachments.shift();
  1126. o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id, function(){
  1127. this.checkAutoSaveNumber(callback);
  1128. }.bind(this));
  1129. }else{
  1130. if (callback) callback();
  1131. }
  1132. },
  1133. getAutoSaveFileName: function(){
  1134. var ename = "docx";
  1135. switch (this.json.officeType){
  1136. case "word":
  1137. ename = "docx";
  1138. break;
  1139. case "excel":
  1140. ename = "xlsx";
  1141. break;
  1142. case "ppt":
  1143. ename = "pptx";
  1144. }
  1145. var d = Date.parse(new Date());
  1146. var dText = d.format("%Y-%m-%d %H:%M:%S");
  1147. return MWF.xApplication.process.Xform.LP.autosave+"("+dText+")."+ename;
  1148. },
  1149. autoSave: function(){
  1150. var interval = (this.json.autoSaveTime) ? this.json.autoSaveTime.toInt()*60*1000 : (5*60*1000);
  1151. this.autoSaveTimerID = window.setInterval(function(){
  1152. if (!this.openedAttachment){
  1153. this.checkAutoSaveNumber(function(){
  1154. try{
  1155. var fileName = this.getAutoSaveFileName();
  1156. this.officeForm.getElement("input").set("value", this.json.id+"autosave");
  1157. url = this.form.workAction.action.actions.uploadAttachment.uri;
  1158. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  1159. this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId());
  1160. this.form.workAction.listAttachments(this.form.businessData.work.id, function(json){
  1161. this.form.businessData.attachmentList = json.data;
  1162. for (var i=0; i<json.data.length; i++){
  1163. var att = json.data[i];
  1164. if (att.name===fileName){
  1165. this.autoSavedAttachments.push(att);
  1166. break;
  1167. }
  1168. }
  1169. }.bind(this), null, false);
  1170. }catch(e){}
  1171. }.bind(this));
  1172. }
  1173. }.bind(this), interval);
  1174. },
  1175. doOfficeOCXEvents: function(){
  1176. var id = this.getOfficeObjectId();
  1177. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  1178. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  1179. this.addOfficeEvent(id, "OnDocumentClosed()", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentClosed();");
  1180. },
  1181. OnDocumentClosed: function(){
  1182. this.fireEvent("afterCloseOffice");
  1183. },
  1184. OnDocumentOpened: function(url, doc){
  1185. this.afterOpen();
  1186. this.loadMenu();
  1187. this.fireEvent("afterOpenOffice", {
  1188. url : url,
  1189. doc : doc
  1190. });
  1191. },
  1192. AfterOpenFromURL: function(doc, statusCode){
  1193. this.fireEvent("afterOpen", [doc, statusCode]);
  1194. },
  1195. addOfficeEvent: function(id, event, code){
  1196. var script = document.createElement("script");
  1197. script.setAttribute("for", id);
  1198. script.setAttribute("event", event);
  1199. script.innerText = code;
  1200. this.officeForm.appendChild(script);
  1201. },
  1202. loadOfficeRead: function(file){
  1203. this.loadOfficeSpacer();
  1204. this.node.setStyle("pisition", "absolute");
  1205. // var codeBase = this.json.codeBase || this.options.codeBase;
  1206. // var version = this.json.version || this.options.version;
  1207. // var classid = this.json.clsid || this.options.clsid;
  1208. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  1209. var version = this.officeConfig.version || this.json.version || this.options.version;
  1210. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  1211. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  1212. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  1213. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  1214. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  1215. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  1216. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  1217. // var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\""+
  1218. // "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  1219. // "codeBase=\""+codeBase+"#version="+version+"\" " +
  1220. // "classid=\"clsid:"+classid+"\">";
  1221. var objectHtml = "";
  1222. if(window.navigator.platform=="Win64"){
  1223. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  1224. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  1225. "codeBase=\""+codeBase64+"#version="+version+"\" " +
  1226. "classid=\"clsid:"+classid64+"\">";
  1227. }else{
  1228. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  1229. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  1230. "codeBase=\""+codeBase+"#version="+version+"\" " +
  1231. "classid=\"clsid:"+classid+"\">";
  1232. }
  1233. var pars = this.defaultParam(true);
  1234. pars = Object.merge(pars, this.json.ntkoReadProperties);
  1235. pars = Object.merge(pars, this.json.readProperties);
  1236. Object.each(pars, function(p, key){
  1237. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  1238. });
  1239. objectHtml += "</object></form>";
  1240. this.officeNode.set("html", objectHtml);
  1241. this.officeForm = this.officeNode.getFirst();
  1242. /**
  1243. @summary Ntko Office 控件对象, 第三方控件
  1244. @see {@link http://ieoffice.ntko.com/pro/show/mid/1_8/pid/2731|NTKO官网 }
  1245. @example
  1246. var officeOCX = this.form.get("fieldId").officeOCX;
  1247. var activeDocument = officeOCX.ActiveDocument //返回一个Office Document 对象,该对象代表活动文档。
  1248. */
  1249. this.officeOCX = this.officeNode.getFirst().getFirst();
  1250. if(window.navigator.platform=="Win64"){
  1251. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  1252. }else{
  1253. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  1254. }
  1255. //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","../x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  1256. var url = file || this.getOfficeFileUrl();
  1257. if (url){
  1258. var id = this.getOfficeObjectId();
  1259. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  1260. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  1261. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  1262. }
  1263. },
  1264. createUploadFileNode: function(){
  1265. this.uploadFileAreaNode = new Element("div", {"styles": {"display": "none"}});
  1266. var html = "<input name=\"file\" type=\"file\"/>";
  1267. this.uploadFileAreaNode.set("html", html);
  1268. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  1269. this.uploadFileAreaNode.inject(this.officeForm);
  1270. },
  1271. isEmpty : function(){
  1272. var data = this.getData();
  1273. return !data.trim();
  1274. },
  1275. getData: function(){
  1276. if (this.officeOCX && (this.officeOCX.DocType==1 || this.officeOCX.DocType==6)){
  1277. this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  1278. var content = this.officeOCX.ActiveDocument.Application.Selection.Text;
  1279. return content;
  1280. }else{
  1281. return this._getBusinessData();
  1282. }
  1283. },
  1284. setData: function(){},
  1285. /**
  1286. * @summary 保存Office文档到后台
  1287. * @param {Boolean} history - 是否生产保留痕迹文件
  1288. */
  1289. save: function(history){
  1290. //if (!this.uploadFileAreaNode) this.createUploadFileNode();
  1291. if (!this.readonly){
  1292. if (this.historyMode) return true;
  1293. if (!this.officeForm) return true;
  1294. this.fireEvent("beforeSave");
  1295. try{
  1296. if (this.openedAttachment){
  1297. this.officeForm.getElement("input").set("value", this.openedAttachment.site);
  1298. url = this.form.workAction.action.actions.replaceAttachment.uri;
  1299. url = url.replace("{id}", this.openedAttachment.id);
  1300. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  1301. this.officeOCX.SaveToURL(url, "file", "", this.openedAttachment.name, this.getFormId());
  1302. }else{
  1303. if (history){
  1304. if (this.json.isHistory) this.saveHistory();
  1305. }
  1306. this.clearAutoSaveAttachments();
  1307. // if (this.autoSavedAttachments && this.autoSavedAttachments.length){
  1308. // this.autoSavedAttachments.each(function(att){
  1309. // o2.Actions.get("x_processplatform_assemble_surface").deleteAttachment(att.id, this.form.businessData.work.id);
  1310. // }.bind(this));
  1311. // this.autoSavedAttachments = [];
  1312. // }
  1313. //this.saveHTML();
  1314. this.officeForm.getElement("input").set("value", this.json.id);
  1315. var url = "";
  1316. if (this.file){
  1317. url = this.form.workAction.action.actions.replaceAttachment.uri;
  1318. url = url.replace("{id}", this.file.id);
  1319. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  1320. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  1321. }else{
  1322. url = this.form.workAction.action.actions.uploadAttachment.uri;
  1323. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  1324. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  1325. this.form.workAction.getWorkContent(this.form.businessData.work.id, function(json){
  1326. this.form.businessData.attachmentList = json.data.attachmentList;
  1327. this.getOfficeFileUrl();
  1328. }.bind(this));
  1329. }
  1330. }
  1331. }catch (e){}
  1332. this.fireEvent("afterSave");
  1333. }
  1334. },
  1335. getHistoryFileName: function(){
  1336. var ename = "docx";
  1337. switch (this.json.officeType){
  1338. case "word":
  1339. ename = "docx";
  1340. break;
  1341. case "excel":
  1342. ename = "xlsx";
  1343. break;
  1344. case "ppt":
  1345. ename = "pptx";
  1346. }
  1347. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  1348. var activity = (this.form.businessData.work) ? this.form.businessData.work.activityName : MWF.xApplication.process.Xform.LP.completed;
  1349. var name = MWF.name.cn(layout.session.user.name);
  1350. var d = Date.parse(new Date());
  1351. var dText = d.format("%Y-%m-%d %H:%M");
  1352. return activity+"("+name+")-"+dText+"."+ename;
  1353. },
  1354. saveHistory: function(){
  1355. var fileName = this.getHistoryFileName();
  1356. this.officeForm.getElement("input").set("value", this.json.id+"history");
  1357. url = this.form.workAction.action.actions.uploadAttachment.uri;
  1358. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  1359. this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId());
  1360. },
  1361. getHTMLFileName: function(){
  1362. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  1363. var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.workId;
  1364. return id+this.json.id+".mht";
  1365. },
  1366. saveHTML: function(){
  1367. this.officeForm.getElement("input").set("value", this.json.id+"$view");
  1368. var file = null;
  1369. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  1370. var att = this.form.businessData.attachmentList[i];
  1371. if (att.site==this.json.id+"$view"){
  1372. file = att;
  1373. }
  1374. }
  1375. var fileName = (file) ? file.name : this.getHTMLFileName();
  1376. this.officeForm.getElement("input").getNext().set("value", fileName);
  1377. if (file){
  1378. url = this.form.workAction.action.actions.replaceAttachment.uri;
  1379. url = url.replace("{id}", file.id);
  1380. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  1381. }else{
  1382. url = this.form.workAction.action.actions.uploadAttachment.uri;
  1383. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  1384. }
  1385. //this.officeOCX.PublishAsHTMLToURL(url, "file", "", fileName, this.getFormId());
  1386. this.officeOCX.SaveAsOtherFormatToURL(1, url, "file", "", fileName, this.getFormId());
  1387. //this.officeOCX.PublishAsPDFToURL(url, "file", "", fileName, this.getFormId());
  1388. },
  1389. getHTMLFileUrl: function(name){
  1390. var fileName = name || this.getHTMLFileName();
  1391. var file = null;
  1392. atts = this.form.businessData.attachmentList;
  1393. for (var i=0; i<atts.length; i++){
  1394. if ((atts[i].name===fileName) || (atts[i].site===this.json.id+"$view")){
  1395. file = atts[i];
  1396. break;
  1397. }
  1398. }
  1399. if (file){
  1400. //this.file = file;
  1401. var url = "";
  1402. if (!this.form.businessData.workCompleted){
  1403. url = this.form.workAction.action.actions.getAttachmentData.uri;
  1404. url = url.replace("{id}", encodeURIComponent(file.id));
  1405. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  1406. }else{
  1407. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  1408. url = url.replace("{id}", encodeURIComponent(file.id));
  1409. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  1410. }
  1411. }else{
  1412. return this.getTempleteUrl();
  1413. }
  1414. },
  1415. validationMode: function(){},
  1416. validation: function(){return true},
  1417. loadOfficeNotActive: function(){
  1418. var fileName = this.getFileName();
  1419. var htmlName = "";
  1420. var isHtml = false;
  1421. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  1422. var att = this.form.businessData.attachmentList[i];
  1423. if (att.site==this.json.id+"$view"){
  1424. htmlName = att.name;
  1425. }
  1426. }
  1427. if (false){
  1428. this.node.setStyles({
  1429. "min-height": "600px",
  1430. "padding": "0px",
  1431. "border": "0px solid #999999",
  1432. "background-color": "#e6e6e6",
  1433. "overflow": "hidden"
  1434. });
  1435. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  1436. //this.node.setStyles(this.json.styles);
  1437. var wordNode = new Element("div", {
  1438. "styles": {
  1439. "padding": "40px",
  1440. "border": "1px solid #999999",
  1441. "background-color": "#e6e6e6",
  1442. "overflow": "auto"
  1443. }
  1444. }).inject(this.node);
  1445. var size = this.node.getSize();
  1446. var y = (size.y-80-80);
  1447. wordNode.setStyle("height", ""+y+"px");
  1448. var node = new Element("div", {
  1449. "styles": {
  1450. "width": "90%",
  1451. "height": "1900px",
  1452. "margin": "auto",
  1453. "background-color": "#ffffff"
  1454. }
  1455. }).inject(wordNode);
  1456. var iframe = new Element("iframe", {
  1457. "styles": {
  1458. "width": "100%",
  1459. "height": "100%",
  1460. "min-height": "600px",
  1461. "overflow": "auto",
  1462. "border": "1px solid #cccccc"
  1463. }
  1464. //"src": this.getHTMLFileUrl(htmlName)
  1465. }).inject(node);
  1466. //alert(iframe.contentWindow.document.body.firstChild);
  1467. iframe.contentWindow.document.addEventListener("readystatechange", function(){
  1468. alert("onreadystatechange"+ this.readyState );
  1469. alert(this.body.firstChild);
  1470. this.body.style.padding = "20px 40px";
  1471. });
  1472. // iframe.contentWindow.document.onreadystatechange = function(){
  1473. // alert("onreadystatechange"+ this.readyState );
  1474. // alert(this.body.firstChild);
  1475. // this.body.style.padding = "20px 40px";
  1476. // };
  1477. iframe.set("src", this.getHTMLFileUrl(htmlName));
  1478. // iframe.contentWindow.document.body.firstChild.style.paddingTop = "20px";
  1479. // iframe.contentWindow.document.body.firstChild.style.paddingBottom = "20px";
  1480. // iframe.contentWindow.document.body.firstChild.style.paddingLeft = "40px";
  1481. // iframe.contentWindow.document.body.firstChild.style.paddingRight = "40px";
  1482. }else{
  1483. if (this.json.isShowSummary!==false){
  1484. this.node.setStyles({
  1485. "overflow": "hidden",
  1486. "background-color": "#f3f3f3",
  1487. "min-height": "24px",
  1488. "padding": "18px"
  1489. });
  1490. var str = this.getData();
  1491. if (layout.mobile || COMMON.Browser.Platform.isMobile){
  1492. if (str.length>300) str = str.substr(0,300)+"……";
  1493. }
  1494. var text = new Element("div", {
  1495. "text": str
  1496. }).inject(this.node);
  1497. }
  1498. }
  1499. var text = MWF.xApplication.process.Xform.LP.openOfficeInfor;
  1500. text = text.replace("{type}", this.json.officeType);
  1501. var icon = new Element("div", {
  1502. "styles": {
  1503. "width": "200px",
  1504. "height": "24px",
  1505. "margin": "auto",
  1506. "margin-top": "18px",
  1507. "padding-left": "30px",
  1508. "font-size": "16px",
  1509. "font-weight": "bold",
  1510. "color": "#2b5797",
  1511. "font-family": "Gadugi",
  1512. "cursor": "pointer",
  1513. "background": "url("+this.form.path+""+this.form.options.style+"/icon/"+this.json.officeType+".png"+") no-repeat left center"
  1514. },
  1515. "text": text
  1516. }).inject(this.node);
  1517. var url = this.getOfficeFileUrl();
  1518. if (!url){
  1519. this.node.setStyle("display", "none");
  1520. }
  1521. icon.addEvent("click", function(){
  1522. var url = this.getOfficeFileUrl();
  1523. if (url){
  1524. if (window.o2android){
  1525. window.o2android.openDocument(url);
  1526. }else if(window.webkit){
  1527. window.webkit.messageHandlers.openDocument.postMessage(url);
  1528. }else{
  1529. window.open(o2.filterUrl(url));
  1530. }
  1531. }
  1532. }.bind(this));
  1533. }
  1534. });