Office.js 64 KB

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