Office.js 70 KB

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