Office.js 65 KB

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