Office.js 76 KB

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