Office.js 66 KB

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