Office.js 64 KB

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