Office.js 54 KB

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