Office.js 66 KB

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