Office.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Office = MWF.APPOffice = new Class({
  3. Extends: MWF.APP$Module,
  4. isActive: false,
  5. options:{
  6. "ProductCaption": "O2",
  7. "ProductKey": "EDCC626CB85C9A1D3E0D7BDDDC2637753C596725",
  8. "makerCaption": "浙江兰德纵横网络技术股份有限公司",
  9. "makerKey": "E138DABB4AC26C2D8E09FAE59AB3BDE87AFB9D7B",
  10. "version": "5.0.4.0",
  11. "clsid": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0",
  12. "codeBase": "/o2_lib/officecontrol/5040/OfficeControl.cab",
  13. "clsid64": "A64E3073-2016-4baf-A89D-FFE1FAA10EE1",
  14. "codeBase64": "/o2_lib/officecontrol/5040/ofctnewclsid.cab",
  15. "pdfType": "PDF.NtkoDocument",
  16. "pdfVersion": "4.0.0.3",
  17. "pdfCodeBase": "/o2_lib/officecontrol/5040/ntkooledocall.cab",
  18. "pdfCodeBase64": "/o2_lib/officecontrol/5040/ntkooledocall64.cab",
  19. "files": ["doc","docx","dotx","dot","xls","xlsx","xlsm","xlt","xltx","pptx","ppt","pot","potx","potm","pdf"],
  20. "moduleEvents": ["redFile",
  21. "afterOpen",
  22. "afterOpenOffice",
  23. "afterCreate",
  24. "seal",
  25. "beforeSave",
  26. "afterSave",
  27. "afterCloseOffice",
  28. "load"
  29. ]
  30. },
  31. initialize: function(node, json, form, options){
  32. this.node = $(node);
  33. this.node.store("module", this);
  34. this.json = json;
  35. this.form = form;
  36. this.field = true;
  37. this.openedAttachment = null;
  38. },
  39. _loadUserInterface: function(){
  40. this.node.empty();
  41. this.node.setStyles({
  42. "min-height": "100px"
  43. });
  44. // this.isActive = true;
  45. //if (Browser.name==="ie" || Browser.name==="chrome" || Browser.name==="firefox"){
  46. if (Browser.name==="ie"){
  47. this.isActive = true;
  48. this.file = null;
  49. if (!this.form.officeList) this.form.officeList=[];
  50. this.form.officeList.push(this);
  51. }
  52. },
  53. _afterLoaded: function(){
  54. if (!this.json.isNotLoadNow){
  55. this.loadOffice();
  56. }
  57. //this.fireEvent("load");
  58. },
  59. loadOffice: function(file){
  60. if (!this.officeLoaded){
  61. if (!this.isActive){
  62. this.loadOfficeNotActive();
  63. }else{
  64. MWF.getJSON("/o2_lib/officecontrol/config.json", function(json){
  65. this.officeConfig = json;
  66. }.bind(this), false);
  67. this.loadOfficeContorl(file);
  68. }
  69. this.officeLoaded = true;
  70. }else{
  71. if (this.officeOCX) this.officeOCX.BeginOpenFromURL(file, true, this.readonly);
  72. }
  73. },
  74. getProgID: function(){
  75. switch (this.json.officeType){
  76. case "word":
  77. return "Word.Document";
  78. case "excel":
  79. return "Excel.Sheet";
  80. case "ppt":
  81. return "PowerPoint.Show";
  82. }
  83. return "Word.Document"
  84. },
  85. defaultParam: function(readonly){
  86. var o = {
  87. "ProductCaption": this.json.productCaption || this.options.ProductCaption,
  88. "ProductKey": this.json.productKey || this.options.ProductKey,
  89. "MakerCaption": this.officeConfig.makerCaption || this.json.makerCaption || this.options.makerCaption,
  90. "MakerKey": this.officeConfig.makerKey || this.options.makerKey || this.options.MakerKey,
  91. "Titlebar": "0",
  92. "Menubar": "0",
  93. "ToolBars": (readonly) ? "0" : "1",
  94. "Statusbar": "0",
  95. "IsUseUTF8URL": "1",
  96. "IsUseUTF8Data": "1",
  97. "BorderStyle": (readonly) ? "0" : "0",
  98. "IsNoCopy": "0",
  99. "IsResetToolbarsOnOpen": "1",
  100. "FileNew": "0",
  101. "FileOpen": "1",
  102. "FileClose": "0",
  103. "FileSave": "0",
  104. "FileProperties": "0"
  105. };
  106. return o;
  107. },
  108. loadOfficeContorl: function(file){
  109. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  110. if (!layout.desktop.offices) layout.desktop.offices = {};
  111. layout.desktop.offices[this.getOfficeObjectId()] = this;
  112. if (this.readonly){
  113. this.loadOfficeRead(file);
  114. }else if (this.json.isReadonly){
  115. this.readonly = true;
  116. this.loadOfficeRead(file);
  117. }else{
  118. if (this.json.readScript && this.json.readScript.code){
  119. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  120. if (flag){
  121. this.readonly = true;
  122. this.loadOfficeRead(file);
  123. }else{
  124. this.loadOfficeEdit(file);
  125. }
  126. }else{
  127. this.loadOfficeEdit(file);
  128. }
  129. }
  130. },
  131. loadOfficeSpacer: function(){
  132. var size = this.node.getSize();
  133. this.officeNode = new Element("div#officeNode", {
  134. "styles": this.form.css.officeAreaNode
  135. }).inject(this.node);
  136. var y = size.y-40;
  137. this.officeNode.setStyle("height", ""+y+"px");
  138. this.form.app.addEvent("uncurrent", function(){
  139. var display = this.officeNode.getStyle("display");
  140. this.officeNode.store("officeDisplay", display);
  141. this.officeNode.setStyle("display", "none");
  142. }.bind(this));
  143. this.form.app.addEvent("current", function(){
  144. var display = this.officeNode.retrieve("officeDisplay");
  145. if (display) this.officeNode.setStyle("display", display);
  146. if (this.officeOCX) this.officeOCX.Activate(true);
  147. }.bind(this));
  148. this.form.app.addEvent("queryClose", function(){
  149. this.fireEvent("queryClose");
  150. var id = this.getOfficeObjectId();
  151. layout.desktop.offices[id] = null;
  152. delete layout.desktop.offices[id];
  153. }.bind(this));
  154. },
  155. hide: function(){
  156. if (this.officeNode.getStyle("display")!="none"){
  157. var display = this.officeNode.getStyle("display");
  158. this.officeNode.store("officeDisplay", display);
  159. this.officeNode.setStyle("display", "none");
  160. }
  161. },
  162. show: function(){
  163. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.form.app.appId){
  164. var display = this.officeNode.retrieve("officeDisplay");
  165. if (display) this.officeNode.setStyle("display", display);
  166. if (this.officeOCX) this.officeOCX.Activate(true);
  167. }
  168. },
  169. isCover: function(node){
  170. },
  171. getFormId: function(){
  172. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  173. return "form"+this.json.id+id;
  174. },
  175. getFileName: function(){
  176. var ename = "docx";
  177. switch (this.json.officeType){
  178. case "word":
  179. ename = "docx";
  180. break;
  181. case "excel":
  182. ename = "xlsx";
  183. break;
  184. case "ppt":
  185. ename = "pptx";
  186. }
  187. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  188. return "file"+this.json.id+id+"."+ename;
  189. },
  190. getOfficeObjectId: function(){
  191. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  192. return "NTKOOCX"+this.json.id+id;
  193. },
  194. getFileInputName: function(){
  195. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  196. return "fileInput"+this.json.id+id;
  197. },
  198. getTempleteUrl: function(){
  199. //return "/x_desktop/temp/杭州城管委文件.doc";
  200. if (this.json.template){
  201. var root = "";
  202. var flag = this.json.template.substr(0,1);
  203. if (flag==="/"){
  204. root = this.json.template.substr(1, this.json.template.indexOf("/", 1)-1);
  205. }else{
  206. root = this.json.template.substr(0, this.json.template.indexOf("/"));
  207. }
  208. if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  209. var host = MWF.Actions.getHost(root);
  210. return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  211. }
  212. }
  213. return this.json.template;
  214. },
  215. getFile: function(site){
  216. var file = null;
  217. atts = this.form.businessData.attachmentList;
  218. for (var i=0; i<atts.length; i++){
  219. //if ((atts[i].name===fileName) || (atts[i].site===this.json.id)){
  220. //if (atts[i].site===this.json.id){
  221. if (atts[i].site===site){
  222. file = atts[i];
  223. break;
  224. }
  225. }
  226. return file
  227. },
  228. getOfficeFileUrl: function(){
  229. var fileName = this.getFileName();
  230. this.readSite = this.json.id;
  231. if (this.json.fileSite && this.json.fileSite.code){
  232. this.readSite = this.form.Macro.exec(this.json.fileSite.code, this);
  233. }
  234. var file = this.getFile(this.readSite);
  235. if (!file) if (this.readSite !== this.json.id) file = this.getFile(this.json.id);
  236. if (file){
  237. this.file = file;
  238. var url = "";
  239. if (this.form.businessData.work){
  240. url = this.form.workAction.action.actions.getAttachmentData.uri;
  241. url = url.replace("{id}", encodeURIComponent(file.id));
  242. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  243. }else{
  244. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  245. url = url.replace("{id}", encodeURIComponent(file.id));
  246. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  247. }
  248. }else{
  249. return this.getTempleteUrl();
  250. }
  251. },
  252. editEnabled: function(){
  253. try {
  254. this.officeOCX.ActiveDocument.Unprotect();
  255. }catch(e){}
  256. },
  257. docReadonly: function(){
  258. this.protect(3);
  259. },
  260. protect: function(type){
  261. // wdAllowOnlyComments = 1 //批注
  262. // wdAllowOnlyFormFields = 2 //填写窗体
  263. // wdAllowOnlyReading = 3 //只读
  264. // wdAllowOnlyRevisions = 0 //修订
  265. // wdNoProtection = -1 //限制编辑样式
  266. try {
  267. this.officeOCX.ActiveDocument.Protect(type);
  268. }catch(e){}
  269. },
  270. startRevisions: function(){
  271. if (this.officeOCX && (this.officeOCX.DocType==1 || this.officeOCX.DocType==6)){
  272. this.officeOCX.ActiveDocument.Application.UserName = layout.desktop.session.user.name;
  273. if (!this.isNew){
  274. this.officeOCX.ActiveDocument.TrackRevisions = true;
  275. this.officeOCX.ActiveDocument.showRevisions = false;
  276. }else{
  277. this.officeOCX.ActiveDocument.TrackRevisions = false;
  278. this.officeOCX.ActiveDocument.showRevisions = false;
  279. }
  280. this.officeOCX.ActiveDocument.Application.UserName = layout.desktop.session.user.name;
  281. }
  282. //this.officeOCX.FullScreenMode = true;
  283. },
  284. stopRevisions: function(accept){
  285. this.officeOCX.ActiveDocument.TrackRevisions = false;
  286. this.officeOCX.ActiveDocument.showRevisions = false;
  287. if (accept) this.officeOCX.ActiveDocument.AcceptAllRevisions();
  288. },
  289. createMenuAction: function(id, title, img){
  290. var title = title || MWF.xApplication.process.Xform.LP[id];
  291. return new Element("div", {
  292. "MWFnodeid": id,
  293. "MWFnodetype": "MWFToolBarButton",
  294. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  295. "title": title,
  296. "MWFButtonAction": "menuAction",
  297. "MWFButtonText": title
  298. }).inject(this.menuNode);
  299. },
  300. createMenuActionMenu: function(id, title, img){
  301. var title = title || MWF.xApplication.process.Xform.LP[id];
  302. return new Element("div", {
  303. "MWFnodeid": id,
  304. "MWFnodetype": "MWFToolBarMenu",
  305. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  306. "title": title,
  307. "MWFButtonAction": "menuAction",
  308. "MWFButtonText": title
  309. }).inject(this.menuNode);
  310. },
  311. createMenuActionMenuItem: function(id, title, img, action){
  312. return new Element("div", {
  313. "MWFnodeid": id,
  314. "MWFnodetype": "MWFToolBarMenuItem",
  315. "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
  316. "title": title,
  317. "MWFButtonAction": action,
  318. "MWFButtonText": title
  319. }).inject(this.menuNode);
  320. },
  321. menuAction: function(button){
  322. switch (button.buttonID){
  323. case "menu_new":
  324. this.officeOCX.CreateNew(this.getProgID());
  325. break;
  326. case "menu_openfile":
  327. this.officeOCX.ShowDialog(1);
  328. break;
  329. case "menu_savefile":
  330. this.officeOCX.ShowDialog(3);
  331. break;
  332. case "revisions":
  333. this.toggleRevisions(button);
  334. break;
  335. case "menu_fullscreen":
  336. this.officeOCX.FullScreenMode = true;
  337. break;
  338. case "toolbar":
  339. var text = (this.officeOCX.ToolBars) ? MWF.xApplication.process.Xform.LP.menu_toolbar_show : MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  340. button.setText(text);
  341. this.officeOCX.ToolBars = !this.officeOCX.ToolBars;
  342. break;
  343. case "menu_preview":
  344. this.officeOCX.PrintPreview();
  345. break;
  346. case "menu_showHistory":
  347. this.showHistory(button);
  348. break;
  349. case "menu_redFile":
  350. this.redFile();
  351. break;
  352. case "menu_seal":
  353. this.seal();
  354. break;
  355. case "menu_att":
  356. button.menu.clearItems();
  357. button._loadMenuItem(this.createMenuActionMenuItem("", MWF.xApplication.process.Xform.LP.menu_file, "109.png", "openFile"));
  358. button._loadMenuLine();
  359. var attcs = this.json.attachmentIds.split(/,\s*|;\s*|,\s*|;\s*/g);
  360. attcs.each(function(att){
  361. var attc = this.form.all[att];
  362. if (attc){
  363. attc.attachmentController.attachments.each(function(a){
  364. if (this.options.files.indexOf(a.data.extension.toLowerCase())!==-1){
  365. button._loadMenuItem(this.createMenuActionMenuItem(a.data.id, a.data.name, "14.png", "openAttachment:"+a.data.id+":"+att+":"+a.data.name));
  366. }
  367. }.bind(this));
  368. }
  369. }.bind(this));
  370. }
  371. },
  372. openFile: function(bt, e, item){
  373. if (this.openedAttachment){
  374. this.save();
  375. this.loadOfficeEdit();
  376. }
  377. },
  378. openAttachment: function(id, site, name){
  379. if (!this.openedAttachment || this.openedAttachment.id!==id){
  380. this.save();
  381. if (this.form.businessData.workCompleted){
  382. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(id, this.form.businessData.workCompleted.id, function(url){
  383. this.openedAttachment = {"id": id, "site": site, "name": name};
  384. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  385. }.bind(this));
  386. }else{
  387. MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(id, this.form.businessData.work.id, function(url){
  388. this.openedAttachment = {"id": id, "site": site, "name": name};
  389. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  390. }.bind(this));
  391. }
  392. }
  393. },
  394. loadMenu: function(){
  395. if (!this.isMenuLoad){
  396. if (this.json.menuEditButtons.length){
  397. this.menuNode = new Element("div", {"styles": this.form.css.officeMenuNode}).inject(this.node, "top");
  398. MWF.require("MWF.widget.Toolbar", function(){
  399. this.toolbarWidget = new MWF.widget.Toolbar(this.menuNode, {"style": "xform_blue_simple"}, this);
  400. if (this.json.menuEditButtons.indexOf("new")!==-1){
  401. this.newItem = this.createMenuAction("menu_new", "", "99.png");
  402. }
  403. if (this.json.menuEditButtons.indexOf("open")!==-1){
  404. this.openItem = this.createMenuAction("menu_openfile", "", "77.png");
  405. }
  406. if (this.json.menuEditButtons.indexOf("save")!==-1){
  407. this.saveItem = this.createMenuAction("menu_savefile", "", "67.png");
  408. }
  409. if (this.json.menuEditButtons.indexOf("revisions")!==-1){
  410. var text = MWF.xApplication.process.Xform.LP.menu_revisions_show;
  411. try {
  412. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup !== 0){
  413. text = MWF.xApplication.process.Xform.LP.menu_revisions_hide;
  414. }
  415. }catch(e){}
  416. this.revisionsItem = this.createMenuAction("revisions", text, "76.png");
  417. }
  418. if (this.json.menuEditButtons.indexOf("fullscreen")!==-1){
  419. this.fullscreenItem = this.createMenuAction("menu_fullscreen", "", "4.png");
  420. }
  421. if (this.json.menuEditButtons.indexOf("toolbar")!==-1){
  422. if (!this.readonly){
  423. var text = MWF.xApplication.process.Xform.LP.menu_toolbar_show;
  424. if (this.officeOCX.ToolBars){
  425. text = MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  426. }
  427. this.toolbarItem = this.createMenuAction("toolbar", text, "91.png");
  428. }
  429. }
  430. if (this.json.menuEditButtons.indexOf("preview")!==-1){
  431. this.fullscreenItem = this.createMenuAction("menu_preview", "", "21.png");
  432. }
  433. if (this.json.menuEditButtons.indexOf("showHistory")!==-1){
  434. atts = this.form.businessData.attachmentList;
  435. if (atts.some(function(att){
  436. return att.site == this.json.id+"history";
  437. }.bind(this))){
  438. this.historyItem = this.createMenuAction("menu_showHistory", "", "115.png");
  439. }
  440. }
  441. if (this.json.menuEditButtons.indexOf("redfile")!==-1){
  442. if (!this.readonly) this.redItem = this.createMenuAction("menu_redfile", "", "12.png");
  443. }
  444. if (this.json.menuEditButtons.indexOf("seal")!==-1){
  445. if (!this.readonly) this.sealItem = this.createMenuAction("menu_seal", "", "84.png");
  446. }
  447. if (this.json.isOpenAttachment){
  448. if (this.json.attachmentIds){
  449. this.sealItem = this.createMenuActionMenu("menu_att", "", "14.png");
  450. }
  451. }
  452. this.toolbarWidget.load();
  453. }.bind(this));
  454. }
  455. this.isMenuLoad = true;
  456. }
  457. },
  458. showHistory: function(button){
  459. if (this.historyItem.get("text") == MWF.xApplication.process.Xform.LP.menu_hideHistory){
  460. var url = this.getOfficeFileUrl();
  461. if (url){
  462. var id = this.getOfficeObjectId();
  463. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  464. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  465. button.setText(MWF.xApplication.process.Xform.LP.menu_showHistory);
  466. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  467. this.historyMode = false;
  468. }
  469. }else{
  470. MWF.require("MWF.xDesktop.Dialog", function(){
  471. var width = 680;
  472. var height = 500;
  473. var p = MWF.getCenterPosition(this.form.app.content, width, height);
  474. var _self = this;
  475. var dlg = new MWF.xDesktop.Dialog({
  476. "title": MWF.xApplication.process.Xform.LP.menu_showHistory,
  477. "style": "work",
  478. "top": p.y-100,
  479. "left": p.x,
  480. "fromTop": p.y-100,
  481. "fromLeft": p.x,
  482. "width": width,
  483. "height": height,
  484. "html": "<div></div>",
  485. "container": this.form.app.content,
  486. "isClose": true,
  487. "buttonList": [
  488. {
  489. "text": MWF.xApplication.process.Xform.LP.close,
  490. "action": function(){this.close();}
  491. }
  492. ],
  493. "onPostShow": function(){
  494. this.showHistoryContent(dlg, button)
  495. }.bind(this)
  496. });
  497. dlg.show();
  498. }.bind(this));
  499. }
  500. },
  501. showHistoryContent: function(dlg, button){
  502. dlg.content.setStyle("overflow", "auto");
  503. atts = this.form.businessData.attachmentList;
  504. var site = this.json.id+"history";
  505. for (var i=0; i<atts.length; i++){
  506. if ((atts[i].site===site)){
  507. //for (var x=0; x<31; x++){
  508. file = atts[i];
  509. var div = new Element("div", {
  510. "styles": {
  511. "margin": "20px auto 0px auto",
  512. "height": "30px",
  513. "line-height": "30px",
  514. "width": "80%",
  515. "font-size": "16px",
  516. "color": "#666666",
  517. "border-bottom": "1px solid #CCCCCC"
  518. },
  519. "value": file.id
  520. }).inject(dlg.content);
  521. var fileNameNode = new Element("div", {
  522. "styles": {"float": "left"},
  523. "text": file.name
  524. }).inject(div);
  525. var buttonNode = new Element("input", {
  526. "type": "button",
  527. "styles": {"float": "right"},
  528. "value": "查看版本",
  529. "events": {
  530. "click": function(e){
  531. this.openOfficeHistory(e, dlg, button);
  532. }.bind(this)
  533. }
  534. }).inject(div);
  535. //}
  536. }
  537. }
  538. },
  539. openOfficeHistory: function(e, dlg){
  540. var fileName = e.target.getParent().get("value");
  541. if (this.form.businessData.work){
  542. url = this.form.workAction.action.actions.getAttachmentData.uri;
  543. url = url.replace("{id}", encodeURIComponent(fileName));
  544. url = this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  545. }else{
  546. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  547. url = url.replace("{id}", encodeURIComponent(fileName));
  548. url = this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.workCompleted.id));
  549. }
  550. dlg.close();
  551. this.save();
  552. this.officeOCX.BeginOpenFromURL(url, true, true);
  553. this.historyMode = true;
  554. if (button){
  555. button.setText(MWF.xApplication.process.Xform.LP.menu_hideHistory)
  556. }
  557. },
  558. seal: function(){
  559. this.fireEvent("seal");
  560. },
  561. redFile: function(){
  562. // try {
  563. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter){
  564. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  565. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  566. }
  567. this.officeOCX.ActiveDocument.showRevisions = false;
  568. this.stopRevisions(true);
  569. this.fireEvent("redFile");
  570. // this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  571. // this.officeOCX.ActiveDocument.Application.Selection.Font.Name = "仿宋";
  572. // this.officeOCX.ActiveDocument.Application.Selection.Font.Size = 14;
  573. // this.officeOCX.ActiveDocument.Application.Selection.Cut();
  574. //
  575. // this.officeOCX.OpenFromUrl("/x_desktop/temp/1.doc", false);
  576. //
  577. // var mark = this.officeOCX.ActiveDocument.Bookmarks("bodyCw");
  578. //
  579. // mark.Range.PasteSpecial(false, false, 0, false, 2);
  580. //mark.Range.Paste();
  581. // }catch(e){
  582. // throw e;
  583. // }
  584. },
  585. showRevisions: function(){
  586. try {
  587. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter) {
  588. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  589. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  590. }
  591. this.officeOCX.ActiveDocument.showRevisions = true;
  592. }catch(e){}
  593. },
  594. hideRevisions: function(){
  595. try {
  596. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter) {
  597. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  598. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  599. }
  600. this.officeOCX.ActiveDocument.showRevisions = false;
  601. }catch(e){}
  602. },
  603. toggleRevisions: function(button){
  604. var t = this.revisionsItem.get("text");
  605. if (t===MWF.xApplication.process.Xform.LP.menu_revisions_show){
  606. button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_hide);
  607. try {
  608. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  609. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  610. }catch(e){}
  611. try {
  612. this.officeOCX.ActiveDocument.showRevisions = true;
  613. }catch(e){}
  614. }else{
  615. button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_show);
  616. try {
  617. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  618. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  619. }catch(e){}
  620. try {
  621. this.officeOCX.ActiveDocument.showRevisions = false;
  622. }catch(e){}
  623. }
  624. },
  625. afterOpen: function(){
  626. // this.officeOCX.AddCustomButtonOnMenu(0,"按钮0",false);
  627. // this.officeOCX.AddCustomButtonOnMenu(1,"按钮1",true,1);
  628. // this.officeOCX.AddCustomButtonOnMenu(2,"按钮2",true,2);
  629. // this.officeOCX.AddCustomButtonOnMenu(3,"按钮3",false,3);
  630. //
  631. //
  632. // this.officeOCX.AddCustomToolButton("预览(0)", 10);
  633. //
  634. // alert(111);
  635. if (this.readonly) this.docReadonly();
  636. if (this.json.trackRevisions==="1") this.startRevisions();
  637. var scale = (this.readonly) ? this.json.readScale : this.json.editScale;
  638. if (scale) scale = scale.toInt();
  639. if (scale){
  640. this.officeOCX.ActiveDocument.ActiveWindow.ActivePane.View.Zoom.Percentage = scale;
  641. }
  642. var display = this.officeNode.getStyle("display");
  643. //window.setTimeout(function(){
  644. this.officeOCX.Activate(false);
  645. this.officeNode.setStyle("display", "none");
  646. window.setTimeout(function(){
  647. this.officeNode.setStyle("display", display);
  648. this.officeOCX.Activate(true);
  649. }.bind(this), 10);
  650. //}.bind(this), 10);
  651. //if (this.officeOCX) this.officeOCX.Activate(true);
  652. // this.officeNode.scrollIntoView();
  653. // this.form.app.node.scrollTo(0);
  654. },
  655. loadOfficeEditFirefox: function(file){
  656. if (!this.officeOCX){
  657. this.loadOfficeSpacer();
  658. this.node.setStyle("pisition", "absolute");
  659. var codeBase = this.json.codeBase || this.options.codeBase;
  660. var version = this.json.version || this.options.version;
  661. var classid = this.json.clsid || this.options.clsid;
  662. var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  663. "type='application/ntko-plug' " +
  664. "style='HEIGHT: 99%; WIDTH: 100%' " +
  665. "height='99%' width='100%' " +
  666. "codeBase='"+codeBase+"#version="+version+"' " +
  667. "classid='{"+classid+"}' ";
  668. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  669. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  670. objectHtml += "ForOndocumentopened='OnComplete3' ";
  671. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  672. var pars = this.defaultParam();
  673. pars = Object.merge(pars, this.json.ntkoEditProperties);
  674. pars = Object.merge(pars, this.json.editProperties);
  675. Object.each(pars, function(p, key){
  676. objectHtml += "_"+key+"='"+p+"'";
  677. });
  678. objectHtml += ">";
  679. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"/o2_lib/officecontrol/ntkoplugins.xpi\">安装组件</a></SPAN>";
  680. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  681. this.officeNode.appendHTML(objectHtml);
  682. this.officeForm = this.officeNode.getFirst();
  683. this.officeOCX = this.officeNode.getFirst().getFirst();
  684. this.doOfficeOCXEvents();
  685. }
  686. var url = this.getOfficeFileUrl();
  687. if (url){
  688. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  689. }else{
  690. this.officeOCX.CreateNew(this.getProgID());
  691. this.fireEvent("afterCreate");
  692. }
  693. },
  694. loadOfficeEditChrome: function(file){
  695. if (!this.officeOCX){
  696. this.loadOfficeSpacer();
  697. this.node.setStyle("pisition", "absolute");
  698. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  699. var version = this.officeConfig.version || this.json.version || this.options.version;
  700. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  701. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  702. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  703. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  704. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  705. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  706. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  707. var objectHtml = "";
  708. if(window.navigator.platform=="Win64"){
  709. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  710. "style='HEIGHT: 99%; WIDTH: 100%' " +
  711. "codeBase='"+codeBase64+"#version="+version+"' " +
  712. "classid='{"+classid64+"}'>";
  713. }else{
  714. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  715. "style='HEIGHT: 99%; WIDTH: 100%' " +
  716. "codeBase='"+codeBase+"#version="+version+"' " +
  717. "classid='{"+classid+"}'";
  718. }
  719. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  720. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  721. objectHtml += "ForOndocumentopened='OnComplete3' ";
  722. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  723. var pars = this.defaultParam();
  724. pars = Object.merge(pars, this.json.ntkoEditProperties);
  725. pars = Object.merge(pars, this.json.editProperties);
  726. Object.each(pars, function(p, key){
  727. objectHtml += "_"+key+"='"+p+"'";
  728. });
  729. objectHtml += ">";
  730. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"/o2_lib/officecontrol/ntkoplugins.crx\">安装组件</a></SPAN>";
  731. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  732. this.officeNode.appendHTML(objectHtml);
  733. this.officeForm = this.officeNode.getFirst();
  734. this.officeOCX = this.officeNode.getFirst().getFirst();
  735. if(window.navigator.platform=="Win64"){
  736. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  737. }else{
  738. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  739. }
  740. //this.doOfficeOCXEvents();
  741. }
  742. var url = this.getOfficeFileUrl();
  743. if (url){
  744. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  745. }else{
  746. this.officeOCX.CreateNew(this.getProgID());
  747. this.fireEvent("afterCreate");
  748. }
  749. },
  750. loadOfficeEdit: function(file){
  751. if (Browser.name==="chrome"){
  752. this.loadOfficeEditChrome(file);
  753. }else if (Browser.name==="firefox") {
  754. this.loadOfficeEditFirefox(file);
  755. }else{
  756. this.loadOfficeEditIE(file);
  757. }
  758. this.openedAttachment = null
  759. },
  760. loadOfficeEditIE: function(file){
  761. if (!this.officeOCX){
  762. this.loadOfficeSpacer();
  763. //this.loadMenu();
  764. this.node.setStyle("pisition", "absolute");
  765. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  766. var version = this.officeConfig.version || this.json.version || this.options.version;
  767. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  768. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  769. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  770. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  771. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  772. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  773. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  774. var objectHtml = "";
  775. if(window.navigator.platform=="Win64"){
  776. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  777. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  778. "codeBase=\""+codeBase64+"#version="+version+"\" " +
  779. "classid=\"clsid:"+classid64+"\">";
  780. }else{
  781. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  782. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  783. "codeBase=\""+codeBase+"#version="+version+"\" " +
  784. "classid=\"clsid:"+classid+"\">";
  785. }
  786. var pars = this.defaultParam();
  787. pars = Object.merge(pars, this.json.ntkoEditProperties);
  788. pars = Object.merge(pars, this.json.editProperties);
  789. Object.each(pars, function(p, key){
  790. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  791. });
  792. //objectHtml += "<div style=\"color:red; position:relative; top:-800px; background:#eeeeee; height:760px; padding:20px; text-align:center; font-size:18px; cursor: pointer \">如果不能自动安装控件,请将在点击此处下载并安装签章客户端。</div>";
  793. 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>";
  794. this.officeNode.appendHTML(objectHtml);
  795. this.officeForm = this.officeNode.getFirst();
  796. this.officeOCX = this.officeNode.getFirst().getFirst();
  797. if(window.navigator.platform=="Win64"){
  798. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  799. }else{
  800. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  801. }
  802. //TANGER_OCX_OBJ.CreateNew("word.document");
  803. //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.7","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  804. this.doOfficeOCXEvents();
  805. }
  806. var url = file || this.getOfficeFileUrl();
  807. if (url){
  808. //layout.desktop.tmpOffice = this;
  809. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  810. }else{
  811. this.isNew = true;
  812. this.officeOCX.CreateNew(this.getProgID());
  813. this.fireEvent("afterCreate");
  814. }
  815. },
  816. doOfficeOCXEvents: function(){
  817. var id = this.getOfficeObjectId();
  818. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  819. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  820. this.addOfficeEvent(id, "OnDocumentClosed()", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentClosed();");
  821. },
  822. OnDocumentClosed: function(){
  823. this.fireEvent("afterCloseOffice");
  824. },
  825. OnDocumentOpened: function(url, doc){
  826. this.afterOpen();
  827. this.loadMenu();
  828. this.fireEvent("afterOpenOffice");
  829. },
  830. AfterOpenFromURL: function(doc, statusCode){
  831. this.fireEvent("afterOpen", [doc, statusCode]);
  832. },
  833. addOfficeEvent: function(id, event, code){
  834. var script = document.createElement("script");
  835. script.setAttribute("for", id);
  836. script.setAttribute("event", event);
  837. script.innerText = code;
  838. this.officeForm.appendChild(script);
  839. },
  840. loadOfficeRead: function(file){
  841. this.loadOfficeSpacer();
  842. this.node.setStyle("pisition", "absolute");
  843. // var codeBase = this.json.codeBase || this.options.codeBase;
  844. // var version = this.json.version || this.options.version;
  845. // var classid = this.json.clsid || this.options.clsid;
  846. var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
  847. var version = this.officeConfig.version || this.json.version || this.options.version;
  848. var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
  849. var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
  850. var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;
  851. var pdfType = this.officeConfig.pdfType || this.json.pdfType || this.options.pdfType;
  852. var pdfVersion = this.officeConfig.pdfVersion || this.json.pdfVersion || this.options.pdfVersion;
  853. var pdfCodeBase = this.officeConfig.pdfCodeBase || this.json.pdfCodeBase || this.options.pdfCodeBase;
  854. var pdfCodeBase64 = this.officeConfig.pdfCodeBase64 || this.json.pdfCodeBase64 || this.options.pdfCodeBase64;
  855. // var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\""+
  856. // "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  857. // "codeBase=\""+codeBase+"#version="+version+"\" " +
  858. // "classid=\"clsid:"+classid+"\">";
  859. var objectHtml = "";
  860. if(window.navigator.platform=="Win64"){
  861. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  862. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  863. "codeBase=\""+codeBase64+"#version="+version+"\" " +
  864. "classid=\"clsid:"+classid64+"\">";
  865. }else{
  866. objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  867. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  868. "codeBase=\""+codeBase+"#version="+version+"\" " +
  869. "classid=\"clsid:"+classid+"\">";
  870. }
  871. var pars = this.defaultParam(true);
  872. pars = Object.merge(pars, this.json.ntkoReadProperties);
  873. pars = Object.merge(pars, this.json.readProperties);
  874. Object.each(pars, function(p, key){
  875. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  876. });
  877. objectHtml += "</object></form>";
  878. this.officeNode.set("html", objectHtml);
  879. this.officeForm = this.officeNode.getFirst();
  880. this.officeOCX = this.officeNode.getFirst().getFirst();
  881. if(window.navigator.platform=="Win64"){
  882. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase64,51,true);
  883. }else{
  884. this.officeOCX.AddDocTypePlugin(".pdf",pdfType,pdfVersion,pdfCodeBase,51,true);
  885. }
  886. //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  887. var url = file || this.getOfficeFileUrl();
  888. if (url){
  889. var id = this.getOfficeObjectId();
  890. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  891. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  892. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  893. }
  894. },
  895. createUploadFileNode: function(){
  896. this.uploadFileAreaNode = new Element("div", {"styles": {"display": "none"}});
  897. var html = "<input name=\"file\" type=\"file\"/>";
  898. this.uploadFileAreaNode.set("html", html);
  899. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  900. this.uploadFileAreaNode.inject(this.officeForm);
  901. },
  902. getData: function(){
  903. if (this.officeOCX && (this.officeOCX.DocType==1 || this.officeOCX.DocType==6)){
  904. this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  905. var content = this.officeOCX.ActiveDocument.Application.Selection.Text;
  906. return content;
  907. }else{
  908. return this._getBusinessData();
  909. }
  910. },
  911. setData: function(){},
  912. save: function(history){
  913. //if (!this.uploadFileAreaNode) this.createUploadFileNode();
  914. if (!this.readonly){
  915. if (this.historyMode) return true;
  916. if (!this.officeForm) return true;
  917. this.fireEvent("beforeSave");
  918. try{
  919. if (this.openedAttachment){
  920. this.officeForm.getElement("input").set("value", this.openedAttachment.site);
  921. url = this.form.workAction.action.actions.replaceAttachment.uri;
  922. url = url.replace("{id}", this.openedAttachment.id);
  923. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  924. this.officeOCX.SaveToURL(url, "file", "", this.openedAttachment.name, this.getFormId());
  925. }else{
  926. if (history){
  927. if (this.json.isHistory) this.saveHistory();
  928. }
  929. //this.saveHTML();
  930. this.officeForm.getElement("input").set("value", this.json.id);
  931. var url = "";
  932. if (this.file){
  933. url = this.form.workAction.action.actions.replaceAttachment.uri;
  934. url = url.replace("{id}", this.file.id);
  935. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  936. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  937. }else{
  938. url = this.form.workAction.action.actions.uploadAttachment.uri;
  939. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  940. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  941. this.form.workAction.getWorkContent(this.form.businessData.work.id, function(json){
  942. this.form.businessData.attachmentList = json.data.attachmentList;
  943. this.getOfficeFileUrl();
  944. }.bind(this));
  945. }
  946. }
  947. }catch (e){}
  948. this.fireEvent("afterSave");
  949. }
  950. },
  951. getHistoryFileName: function(){
  952. var ename = "docx";
  953. switch (this.json.officeType){
  954. case "word":
  955. ename = "docx";
  956. break;
  957. case "excel":
  958. ename = "xlsx";
  959. break;
  960. case "ppt":
  961. ename = "pptx";
  962. }
  963. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  964. var activity = (this.form.businessData.work) ? this.form.businessData.work.activityName : MWF.xApplication.process.Xform.LP.completed;
  965. var name = MWF.name.cn(layout.session.user.name);
  966. var d = Date.parse(new Date());
  967. var dText = d.format("%Y-%m-%d %H:%M");
  968. return activity+"("+name+")-"+dText+"."+ename;
  969. },
  970. saveHistory: function(){
  971. var fileName = this.getHistoryFileName();
  972. this.officeForm.getElement("input").set("value", this.json.id+"history");
  973. url = this.form.workAction.action.actions.uploadAttachment.uri;
  974. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  975. this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId());
  976. },
  977. getHTMLFileName: function(){
  978. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  979. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.workId;
  980. return id+this.json.id+".mht";
  981. },
  982. saveHTML: function(){
  983. this.officeForm.getElement("input").set("value", this.json.id+"$view");
  984. var file = null;
  985. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  986. var att = this.form.businessData.attachmentList[i];
  987. if (att.site==this.json.id+"$view"){
  988. file = att;
  989. }
  990. }
  991. var fileName = (file) ? file.name : this.getHTMLFileName();
  992. this.officeForm.getElement("input").getNext().set("value", fileName);
  993. if (file){
  994. url = this.form.workAction.action.actions.replaceAttachment.uri;
  995. url = url.replace("{id}", file.id);
  996. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  997. }else{
  998. url = this.form.workAction.action.actions.uploadAttachment.uri;
  999. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  1000. }
  1001. //this.officeOCX.PublishAsHTMLToURL(url, "file", "", fileName, this.getFormId());
  1002. this.officeOCX.SaveAsOtherFormatToURL(1, url, "file", "", fileName, this.getFormId());
  1003. //this.officeOCX.PublishAsPDFToURL(url, "file", "", fileName, this.getFormId());
  1004. },
  1005. getHTMLFileUrl: function(name){
  1006. var fileName = name || this.getHTMLFileName();
  1007. var file = null;
  1008. atts = this.form.businessData.attachmentList;
  1009. for (var i=0; i<atts.length; i++){
  1010. if ((atts[i].name===fileName) || (atts[i].site===this.json.id+"$view")){
  1011. file = atts[i];
  1012. break;
  1013. }
  1014. }
  1015. if (file){
  1016. //this.file = file;
  1017. var url = "";
  1018. if (this.form.businessData.work){
  1019. url = this.form.workAction.action.actions.getAttachmentData.uri;
  1020. url = url.replace("{id}", encodeURIComponent(file.id));
  1021. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  1022. }else{
  1023. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  1024. url = url.replace("{id}", encodeURIComponent(file.id));
  1025. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  1026. }
  1027. }else{
  1028. return this.getTempleteUrl();
  1029. }
  1030. },
  1031. validationMode: function(){},
  1032. validation: function(){return true},
  1033. loadOfficeNotActive: function(){
  1034. var fileName = this.getFileName();
  1035. var htmlName = "";
  1036. var isHtml = false;
  1037. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  1038. var att = this.form.businessData.attachmentList[i];
  1039. if (att.site==this.json.id+"$view"){
  1040. htmlName = att.name;
  1041. }
  1042. }
  1043. if (false){
  1044. this.node.setStyles({
  1045. "min-height": "600px",
  1046. "padding": "0px",
  1047. "border": "0px solid #999999",
  1048. "background-color": "#e6e6e6",
  1049. "overflow": "hidden"
  1050. });
  1051. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  1052. //this.node.setStyles(this.json.styles);
  1053. var wordNode = new Element("div", {
  1054. "styles": {
  1055. "padding": "40px",
  1056. "border": "1px solid #999999",
  1057. "background-color": "#e6e6e6",
  1058. "overflow": "auto"
  1059. }
  1060. }).inject(this.node);
  1061. var size = this.node.getSize();
  1062. var y = (size.y-80-80);
  1063. wordNode.setStyle("height", ""+y+"px");
  1064. var node = new Element("div", {
  1065. "styles": {
  1066. "width": "90%",
  1067. "height": "1900px",
  1068. "margin": "auto",
  1069. "background-color": "#ffffff"
  1070. }
  1071. }).inject(wordNode);
  1072. var iframe = new Element("iframe", {
  1073. "styles": {
  1074. "width": "100%",
  1075. "height": "100%",
  1076. "min-height": "600px",
  1077. "overflow": "auto",
  1078. "border": "1px solid #cccccc"
  1079. }
  1080. //"src": this.getHTMLFileUrl(htmlName)
  1081. }).inject(node);
  1082. //alert(iframe.contentWindow.document.body.firstChild);
  1083. iframe.contentWindow.document.addEventListener("readystatechange", function(){
  1084. alert("onreadystatechange"+ this.readyState );
  1085. alert(this.body.firstChild);
  1086. this.body.style.padding = "20px 40px";
  1087. });
  1088. // iframe.contentWindow.document.onreadystatechange = function(){
  1089. // alert("onreadystatechange"+ this.readyState );
  1090. // alert(this.body.firstChild);
  1091. // this.body.style.padding = "20px 40px";
  1092. // };
  1093. iframe.set("src", this.getHTMLFileUrl(htmlName));
  1094. // iframe.contentWindow.document.body.firstChild.style.paddingTop = "20px";
  1095. // iframe.contentWindow.document.body.firstChild.style.paddingBottom = "20px";
  1096. // iframe.contentWindow.document.body.firstChild.style.paddingLeft = "40px";
  1097. // iframe.contentWindow.document.body.firstChild.style.paddingRight = "40px";
  1098. }else{
  1099. this.node.setStyles({
  1100. "overflow": "hidden",
  1101. "background-color": "#f3f3f3",
  1102. "min-height": "24px",
  1103. "padding": "18px"
  1104. });
  1105. var str = this.getData();
  1106. if (layout.mobile || COMMON.Browser.Platform.isMobile){
  1107. if (str.length>300) str = str.substr(0,300)+"……";
  1108. }
  1109. var text = new Element("div", {
  1110. "text": str
  1111. }).inject(this.node);
  1112. }
  1113. var text = MWF.xApplication.process.Xform.LP.openOfficeInfor;
  1114. text = text.replace("{type}", this.json.officeType);
  1115. var icon = new Element("div", {
  1116. "styles": {
  1117. "width": "200px",
  1118. "height": "24px",
  1119. "margin": "auto",
  1120. "margin-top": "18px",
  1121. "padding-left": "30px",
  1122. "font-size": "16px",
  1123. "font-weight": "bold",
  1124. "color": "#2b5797",
  1125. "font-family": "Gadugi",
  1126. "cursor": "pointer",
  1127. "background": "url("+this.form.path+""+this.form.options.style+"/icon/"+this.json.officeType+".png"+") no-repeat left center"
  1128. },
  1129. "text": text
  1130. }).inject(this.node);
  1131. var url = this.getOfficeFileUrl();
  1132. if (!url){
  1133. this.node.setStyle("display", "none");
  1134. }
  1135. icon.addEvent("click", function(){
  1136. var url = this.getOfficeFileUrl();
  1137. if (url){
  1138. if (window.o2android){
  1139. window.o2android.openDocument(url);
  1140. }else if(window.webkit){
  1141. window.webkit.messageHandlers.openDocument.postMessage(url);
  1142. }else{
  1143. window.open(url);
  1144. }
  1145. }
  1146. }.bind(this));
  1147. }
  1148. });