Office.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  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. "version": "5,0,3,1",
  7. "ProductCaption": "O2",
  8. "ProductKey": "EDCC626CB85C9A1D3E0D7BDDDC2637753C596725",
  9. "MakerCaption": "浙江兰德纵横网络技术股份有限公司",
  10. "MakerKey": "E138DABB4AC26C2D8E09FAE59AB3BDE87AFB9D7B",
  11. "clsid": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0",
  12. "codeBase": "/x_desktop/res/framework/officecontrol/OfficeControl.cab",
  13. "clsid64": "A64E3073-2016-4baf-A89D-FFE1FAA10EC0",
  14. "codeBase64": "/x_desktop/res/framework/officecontrol/OfficeControl.cab",
  15. "moduleEvents": ["redFile",
  16. "afterOpen",
  17. "afterOpenOffice",
  18. "afterCreate",
  19. "seal",
  20. "beforeSave",
  21. "afterSave",
  22. "afterCloseOffice"]
  23. },
  24. initialize: function(node, json, form, options){
  25. this.node = $(node);
  26. this.node.store("module", this);
  27. this.json = json;
  28. this.form = form;
  29. this.field = true;
  30. },
  31. _loadUserInterface: function(){
  32. this.node.empty();
  33. this.node.setStyles({
  34. "min-height": "100px"
  35. });
  36. // this.isActive = true;
  37. //if (Browser.name==="ie" || Browser.name==="chrome" || Browser.name==="firefox"){
  38. if (Browser.name==="ie"){
  39. this.isActive = true;
  40. this.file = null;
  41. if (!this.form.officeList) this.form.officeList=[];
  42. this.form.officeList.push(this);
  43. }
  44. },
  45. _afterLoaded: function(){
  46. if (!this.json.isNotLoadNow){
  47. this.loadOffice();
  48. }
  49. },
  50. loadOffice: function(){
  51. if (!this.isActive){
  52. this.loadOfficeNotActive();
  53. }else{
  54. this.loadOfficeContorl();
  55. }
  56. },
  57. getProgID: function(){
  58. switch (this.json.officeType){
  59. case "word":
  60. return "Word.Document";
  61. case "excel":
  62. return "Excel.Sheet";
  63. case "ppt":
  64. return "PowerPoint.Show";
  65. }
  66. return "Word.Document"
  67. },
  68. defaultParam: function(readonly){
  69. var o = {
  70. "ProductCaption": this.json.productCaption || this.options.ProductCaption,
  71. "ProductKey": this.json.productKey || this.options.ProductKey,
  72. "MakerCaption": this.json.makerCaption || this.options.MakerCaption,
  73. "MakerKey": this.options.makerKey || this.options.MakerKey,
  74. "Titlebar": "0",
  75. "Menubar": "0",
  76. "ToolBars": (readonly) ? "0" : "1",
  77. "Statusbar": "0",
  78. "IsUseUTF8URL": "1",
  79. "IsUseUTF8Data": "1",
  80. "BorderStyle": (readonly) ? "0" : "0",
  81. "IsNoCopy": "0",
  82. "IsResetToolbarsOnOpen": "1",
  83. "FileNew": "0",
  84. "FileOpen": "1",
  85. "FileClose": "0",
  86. "FileSave": "0",
  87. "FileProperties": "0"
  88. };
  89. return o;
  90. },
  91. loadOfficeContorl: function(){
  92. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  93. if (!layout.desktop.offices) layout.desktop.offices = {};
  94. layout.desktop.offices[this.getOfficeObjectId()] = this;
  95. if (this.readonly){
  96. this.loadOfficeRead();
  97. }else if (this.json.isReadonly){
  98. this.readonly = true;
  99. this.loadOfficeRead();
  100. }else{
  101. if (this.json.readScript && this.json.readScript.code){
  102. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  103. if (flag){
  104. this.readonly = true;
  105. this.loadOfficeRead();
  106. }else{
  107. this.loadOfficeEdit();
  108. }
  109. }else{
  110. this.loadOfficeEdit();
  111. }
  112. }
  113. },
  114. loadOfficeSpacer: function(){
  115. var size = this.node.getSize();
  116. this.officeNode = new Element("div", {
  117. "styles": this.form.css.officeAreaNode
  118. }).inject(this.node);
  119. this.officeNode.setStyle("height", ""+size.y+"px");
  120. this.form.app.addEvent("uncurrent", function(){
  121. var display = this.officeNode.getStyle("display");
  122. this.officeNode.store("officeDisplay", display);
  123. this.officeNode.setStyle("display", "none");
  124. }.bind(this));
  125. this.form.app.addEvent("current", function(){
  126. var display = this.officeNode.retrieve("officeDisplay");
  127. if (display) this.officeNode.setStyle("display", display);
  128. if (this.officeOCX) this.officeOCX.Activate(true);
  129. }.bind(this));
  130. this.form.app.addEvent("queryClose", function(){
  131. this.fireEvent("queryClose");
  132. var id = this.getOfficeObjectId();
  133. layout.desktop.offices[id] = null;
  134. delete layout.desktop.offices[id];
  135. }.bind(this));
  136. },
  137. getFormId: function(){
  138. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  139. return "form"+this.json.id+id;
  140. },
  141. getFileName: function(){
  142. var ename = "doc";
  143. switch (this.json.officeType){
  144. case "word":
  145. ename = "doc";
  146. break;
  147. case "excel":
  148. ename = "xls";
  149. break;
  150. case "ppt":
  151. ename = "ppt";
  152. }
  153. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  154. return "file"+this.json.id+id+"."+ename;
  155. },
  156. getOfficeObjectId: function(){
  157. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  158. return "NTKOOCX"+this.json.id+id;
  159. },
  160. getFileInputName: function(){
  161. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  162. return "fileInput"+this.json.id+id;
  163. },
  164. getTempleteUrl: function(){
  165. //return "/x_desktop/temp/杭州城管委文件.doc";
  166. if (this.json.template){
  167. var root = "";
  168. var flag = this.json.template.substr(0,1);
  169. if (flag==="/"){
  170. root = this.json.template.substr(1, this.json.template.indexOf("/", 1)-1);
  171. }else{
  172. root = this.json.template.substr(0, this.json.template.indexOf("/"));
  173. }
  174. if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  175. var host = MWF.Actions.getHost(root)
  176. return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  177. }
  178. }
  179. return this.json.template;
  180. },
  181. getOfficeFileUrl: function(){
  182. var fileName = this.getFileName();
  183. var file = null;
  184. atts = this.form.businessData.attachmentList;
  185. for (var i=0; i<atts.length; i++){
  186. if ((atts[i].name===fileName) || (atts[i].site===this.json.id)){
  187. //if (atts[i].site===this.json.id){
  188. file = atts[i];
  189. break;
  190. }
  191. }
  192. if (file){
  193. this.file = file;
  194. var url = "";
  195. if (this.form.businessData.work){
  196. url = this.form.workAction.action.actions.getAttachmentData.uri;
  197. url = url.replace("{id}", encodeURIComponent(file.id));
  198. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  199. }else{
  200. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  201. url = url.replace("{id}", encodeURIComponent(file.id));
  202. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  203. }
  204. }else{
  205. return this.getTempleteUrl();
  206. }
  207. },
  208. editEnabled: function(){
  209. try {
  210. this.officeOCX.ActiveDocument.Unprotect();
  211. }catch(e){}
  212. },
  213. docReadonly: function(){
  214. this.protect(3);
  215. },
  216. protect: function(type){
  217. // wdAllowOnlyComments = 1 //批注
  218. // wdAllowOnlyFormFields = 2 //填写窗体
  219. // wdAllowOnlyReading = 3 //只读
  220. // wdAllowOnlyRevisions = 0 //修订
  221. // wdNoProtection = -1 //限制编辑样式
  222. try {
  223. this.officeOCX.ActiveDocument.Protect(type);
  224. }catch(e){}
  225. },
  226. startRevisions: function(){
  227. this.officeOCX.ActiveDocument.Application.UserName = layout.desktop.session.user.name;
  228. if (!this.isNew){
  229. this.officeOCX.ActiveDocument.TrackRevisions = true;
  230. this.officeOCX.ActiveDocument.showRevisions = false;
  231. }else{
  232. this.officeOCX.ActiveDocument.TrackRevisions = false;
  233. this.officeOCX.ActiveDocument.showRevisions = false;
  234. }
  235. //this.officeOCX.FullScreenMode = true;
  236. },
  237. stopRevisions: function(accept){
  238. this.officeOCX.ActiveDocument.TrackRevisions = false;
  239. this.officeOCX.ActiveDocument.showRevisions = false;
  240. if (accept) this.officeOCX.ActiveDocument.AcceptAllRevisions();
  241. },
  242. loadMenu: function(){
  243. if (!this.isMenuLoad){
  244. if (this.json.menuEditButtons.length){
  245. this.menuNode = new Element("div", {"styles": this.form.css.officeMenuNode}).inject(this.node, "top");
  246. if (this.json.menuEditButtons.indexOf("new")!==-1){
  247. this.newItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_new}).inject(this.menuNode);
  248. this.newItem.addEvent("click", function(){this.officeOCX.CreateNew(this.getProgID());}.bind(this));
  249. }
  250. if (this.json.menuEditButtons.indexOf("open")!==-1){
  251. this.openItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_openfile}).inject(this.menuNode);
  252. this.openItem.addEvent("click", function(){this.officeOCX.ShowDialog(1);}.bind(this));
  253. }
  254. if (this.json.menuEditButtons.indexOf("save")!==-1){
  255. this.saveItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_savefile}).inject(this.menuNode);
  256. this.saveItem.addEvent("click", function(){this.officeOCX.ShowDialog(3);}.bind(this));
  257. }
  258. if (this.json.menuEditButtons.indexOf("revisions")!==-1){
  259. var text = MWF.xApplication.process.Xform.LP.menu_revisions_show;
  260. try {
  261. if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup !== 0){
  262. text = MWF.xApplication.process.Xform.LP.menu_revisions_hide;
  263. }
  264. }catch(e){}
  265. this.revisionsItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": text}).inject(this.menuNode);
  266. this.revisionsItem.addEvent("click", this.toggleRevisions.bind(this));
  267. }
  268. if (this.json.menuEditButtons.indexOf("fullscreen")!==-1){
  269. this.fullscreenItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_fullscreen}).inject(this.menuNode);
  270. this.fullscreenItem.addEvent("click", function(){this.officeOCX.FullScreenMode = true;}.bind(this));
  271. }
  272. if (this.json.menuEditButtons.indexOf("toolbar")!==-1){
  273. if (!this.readonly){
  274. var text = MWF.xApplication.process.Xform.LP.menu_toolbar_show;
  275. if (this.officeOCX.ToolBars){
  276. text = MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  277. }
  278. this.toolbarItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": text}).inject(this.menuNode);
  279. this.toolbarItem.addEvent("click", function(){
  280. var text = (this.officeOCX.ToolBars) ? MWF.xApplication.process.Xform.LP.menu_toolbar_show : MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
  281. this.toolbarItem.set("text", text);
  282. this.officeOCX.ToolBars = !this.officeOCX.ToolBars;
  283. }.bind(this));
  284. }
  285. }
  286. if (this.json.menuEditButtons.indexOf("preview")!==-1){
  287. this.previewItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_preview}).inject(this.menuNode);
  288. this.previewItem.addEvent("click", function(){this.officeOCX.PrintPreview();}.bind(this));
  289. }
  290. if (this.json.menuEditButtons.indexOf("showHistory")!==-1){
  291. this.historyItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_showHistory}).inject(this.menuNode);
  292. this.historyItem.addEvent("click", this.showHistory.bind(this));
  293. }
  294. if (this.json.menuEditButtons.indexOf("redfile")!==-1){
  295. if (!this.readonly){
  296. this.redItem = new Element("div", {"styles": this.form.css.officeMenuItemNode, "text": MWF.xApplication.process.Xform.LP.menu_redfile}).inject(this.menuNode);
  297. this.redItem.addEvent("click", this.redFile.bind(this));
  298. }
  299. }
  300. if (this.json.menuEditButtons.indexOf("seal")!==-1){
  301. if (!this.readonly) {
  302. this.redItem = new Element("div", {
  303. "styles": this.form.css.officeMenuItemNode,
  304. "text": MWF.xApplication.process.Xform.LP.menu_seal
  305. }).inject(this.menuNode);
  306. this.redItem.addEvent("click", this.seal.bind(this));
  307. }
  308. }
  309. }
  310. this.isMenuLoad = true;
  311. }
  312. },
  313. showHistory: function(){
  314. MWF.require("MWF.xDesktop.Dialog", function(){
  315. var width = 680;
  316. var height = 500;
  317. var p = MWF.getCenterPosition(this.form.app.content, width, height);
  318. var _self = this;
  319. var dlg = new MWF.xDesktop.Dialog({
  320. "title": MWF.xApplication.process.Xform.LP.menu_showHistory,
  321. "style": "work",
  322. "top": p.y-100,
  323. "left": p.x,
  324. "fromTop": p.y-100,
  325. "fromLeft": p.x,
  326. "width": width,
  327. "height": height,
  328. "html": "<div></div>",
  329. "container": this.form.app.content,
  330. "isClose": true,
  331. "buttonList": [
  332. {
  333. "text": MWF.xApplication.process.Xform.LP.close,
  334. "action": function(){this.close();}
  335. }
  336. ],
  337. "onPostShow": function(){
  338. this.showHistoryContent(dlg)
  339. }.bind(this)
  340. });
  341. dlg.show();
  342. }.bind(this));
  343. },
  344. showHistoryContent: function(dlg){
  345. dlg.content.setStyle("overflow", "auto");
  346. atts = this.form.businessData.attachmentList;
  347. var site = this.json.id+"history";
  348. for (var i=0; i<atts.length; i++){
  349. if ((atts[i].site===site)){
  350. for (var x=0; x<31; x++){
  351. file = atts[i];
  352. var div = new Element("div", {
  353. "styles": {
  354. "margin": "20px auto 0px auto",
  355. "height": "30px",
  356. "line-height": "30px",
  357. "width": "80%",
  358. "font-size": "16px",
  359. "color": "#666666",
  360. "border-bottom": "1px solid #CCCCCC"
  361. },
  362. "value": file.id
  363. }).inject(dlg.content);
  364. var fileNameNode = new Element("div", {
  365. "styles": {"float": "left"},
  366. "text": file.name
  367. }).inject(div);
  368. var buttonNode = new Element("input", {
  369. "type": "button",
  370. "styles": {"float": "right"},
  371. "value": "查看版本",
  372. "events": {
  373. "click": function(e){
  374. this.openOfficeHistory(e);
  375. dlg.close();
  376. }.bind(this)
  377. }
  378. }).inject(div);
  379. }
  380. }
  381. }
  382. },
  383. openOfficeHistory: function(e){
  384. var fileName = e.target.getParent().get("value");
  385. if (this.form.businessData.work){
  386. url = this.form.workAction.action.actions.getAttachmentData.uri;
  387. url = url.replace("{id}", encodeURIComponent(fileName));
  388. url = this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  389. }else{
  390. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  391. url = url.replace("{id}", encodeURIComponent(fileName));
  392. url = this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.workCompleted.id));
  393. }
  394. this.officeOCX.BeginOpenFromURL(url, true, true);
  395. },
  396. seal: function(){
  397. this.fireEvent("seal");
  398. },
  399. redFile: function(){
  400. // try {
  401. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  402. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  403. this.officeOCX.ActiveDocument.showRevisions = false;
  404. this.stopRevisions(true);
  405. this.fireEvent("redFile");
  406. // this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  407. // this.officeOCX.ActiveDocument.Application.Selection.Font.Name = "仿宋";
  408. // this.officeOCX.ActiveDocument.Application.Selection.Font.Size = 14;
  409. // this.officeOCX.ActiveDocument.Application.Selection.Cut();
  410. //
  411. // this.officeOCX.OpenFromUrl("/x_desktop/temp/1.doc", false);
  412. //
  413. // var mark = this.officeOCX.ActiveDocument.Bookmarks("bodyCw");
  414. //
  415. // mark.Range.PasteSpecial(false, false, 0, false, 2);
  416. //mark.Range.Paste();
  417. // }catch(e){
  418. // throw e;
  419. // }
  420. },
  421. showRevisions: function(){
  422. try {
  423. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  424. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  425. this.officeOCX.ActiveDocument.showRevisions = true;
  426. }catch(e){}
  427. },
  428. hideRevisions: function(){
  429. try {
  430. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  431. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  432. this.officeOCX.ActiveDocument.showRevisions = false;
  433. }catch(e){}
  434. },
  435. toggleRevisions: function(){
  436. var t = this.revisionsItem.get("text");
  437. if (t===MWF.xApplication.process.Xform.LP.menu_revisions_show){
  438. this.revisionsItem.set("text", MWF.xApplication.process.Xform.LP.menu_revisions_hide);
  439. try {
  440. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 2;
  441. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  442. }catch(e){}
  443. try {
  444. this.officeOCX.ActiveDocument.showRevisions = true;
  445. }catch(e){}
  446. }else{
  447. this.revisionsItem.set("text", MWF.xApplication.process.Xform.LP.menu_revisions_show);
  448. try {
  449. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup = 0;
  450. this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.View = 0;
  451. }catch(e){}
  452. try {
  453. this.officeOCX.ActiveDocument.showRevisions = false;
  454. }catch(e){}
  455. }
  456. },
  457. afterOpen: function(){
  458. // this.officeOCX.AddCustomButtonOnMenu(0,"按钮0",false);
  459. // this.officeOCX.AddCustomButtonOnMenu(1,"按钮1",true,1);
  460. // this.officeOCX.AddCustomButtonOnMenu(2,"按钮2",true,2);
  461. // this.officeOCX.AddCustomButtonOnMenu(3,"按钮3",false,3);
  462. //
  463. //
  464. // this.officeOCX.AddCustomToolButton("预览(0)", 10);
  465. //
  466. // alert(111);
  467. if (this.readonly) this.docReadonly();
  468. if (this.json.trackRevisions==="1") this.startRevisions();
  469. //layout.desktop.tmpOffice = null;
  470. },
  471. loadOfficeEditFirefox: function(){
  472. this.loadOfficeSpacer();
  473. this.node.setStyle("pisition", "absolute");
  474. var codeBase = this.json.codeBase || this.options.codeBase;
  475. var version = this.json.version || this.options.version;
  476. var classid = this.json.clsid || this.options.clsid;
  477. var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  478. "type='application/ntko-plug' " +
  479. "style='HEIGHT: 99%; WIDTH: 100%' " +
  480. "height='99%' width='100%' " +
  481. "codeBase='"+codeBase+"#version="+version+"' " +
  482. "classid='{"+classid+"}' ";
  483. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  484. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  485. objectHtml += "ForOndocumentopened='OnComplete3' ";
  486. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  487. var pars = this.defaultParam();
  488. pars = Object.merge(pars, this.json.ntkoEditProperties);
  489. pars = Object.merge(pars, this.json.editProperties);
  490. Object.each(pars, function(p, key){
  491. objectHtml += "_"+key+"='"+p+"'";
  492. });
  493. objectHtml += ">";
  494. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"/x_desktop/res/framework/officecontrol/ntkoplugins.xpi\">安装组件</a></SPAN>";
  495. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  496. this.officeNode.appendHTML(objectHtml);
  497. this.officeForm = this.officeNode.getFirst();
  498. this.officeOCX = this.officeNode.getFirst().getFirst();
  499. this.doOfficeOCXEvents();
  500. var url = this.getOfficeFileUrl();
  501. if (url){
  502. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  503. }else{
  504. this.officeOCX.CreateNew(this.getProgID());
  505. this.fireEvent("afterCreate");
  506. }
  507. },
  508. loadOfficeEditChrome: function(){
  509. this.loadOfficeSpacer();
  510. this.node.setStyle("pisition", "absolute");
  511. var codeBase = this.json.codeBase || this.options.codeBase;
  512. var version = this.json.version || this.options.version;
  513. var classid = this.json.clsid || this.options.clsid;
  514. var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id='"+this.getOfficeObjectId()+"' " +
  515. "style='HEIGHT: 99%; WIDTH: 100%' " +
  516. "height='99%' width='100%' " +
  517. "codeBase='"+codeBase+"#version="+version+"' " +
  518. "classid='{"+classid+"}' ";
  519. objectHtml += "ForOnSaveToURL='OnComplete2' ";
  520. objectHtml += "ForOnBeginOpenFromURL='OnComplete' ";
  521. objectHtml += "ForOndocumentopened='OnComplete3' ";
  522. objectHtml += "ForOnpublishAshtmltourl='publishashtml' ";
  523. var pars = this.defaultParam();
  524. pars = Object.merge(pars, this.json.ntkoEditProperties);
  525. pars = Object.merge(pars, this.json.editProperties);
  526. Object.each(pars, function(p, key){
  527. objectHtml += "_"+key+"='"+p+"'";
  528. });
  529. objectHtml += ">";
  530. objectHtml += "<SPAN STYLE='color:red'>尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href=\"/x_desktop/res/framework/officecontrol/ntkoplugins.crx\">安装组件</a></SPAN>";
  531. objectHtml += "</OBJECT><input type='hidden' value='"+this.json.id+"' name='site'><input style='display:none' name=\"file\" type=\"file\"/></form>";
  532. this.officeNode.appendHTML(objectHtml);
  533. this.officeForm = this.officeNode.getFirst();
  534. this.officeOCX = this.officeNode.getFirst().getFirst();
  535. this.doOfficeOCXEvents();
  536. var url = this.getOfficeFileUrl();
  537. if (url){
  538. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  539. }else{
  540. this.officeOCX.CreateNew(this.getProgID());
  541. this.fireEvent("afterCreate");
  542. }
  543. },
  544. loadOfficeEdit: function(){
  545. if (Browser.name==="chrome"){
  546. this.loadOfficeEditChrome();
  547. }else if (Browser.name==="firefox") {
  548. this.loadOfficeEditFirefox();
  549. }else{
  550. this.loadOfficeEditIE();
  551. }
  552. },
  553. loadOfficeEditIE: function(){
  554. this.loadOfficeSpacer();
  555. //this.loadMenu();
  556. this.node.setStyle("pisition", "absolute");
  557. //if (this.json.ntkoEditProperties.load)
  558. var codeBase = this.json.codeBase || this.options.codeBase;
  559. var version = this.json.version || this.options.version;
  560. var classid = this.json.clsid || this.options.clsid;
  561. var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
  562. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  563. "codeBase=\""+codeBase+"#version="+version+"\" " +
  564. "classid=\"clsid:"+classid+"\">";
  565. var pars = this.defaultParam();
  566. pars = Object.merge(pars, this.json.ntkoEditProperties);
  567. pars = Object.merge(pars, this.json.editProperties);
  568. Object.each(pars, function(p, key){
  569. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  570. });
  571. 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>";
  572. this.officeNode.appendHTML(objectHtml);
  573. this.officeForm = this.officeNode.getFirst();
  574. this.officeOCX = this.officeNode.getFirst().getFirst();
  575. this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  576. //TANGER_OCX_OBJ.CreateNew("word.document");
  577. //this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.7","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  578. this.doOfficeOCXEvents();
  579. var url = this.getOfficeFileUrl();
  580. if (url){
  581. //layout.desktop.tmpOffice = this;
  582. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  583. }else{
  584. this.isNew = true;
  585. // if (this.json.officeType!=="other"){
  586. this.officeOCX.CreateNew(this.getProgID());
  587. this.fireEvent("afterCreate");
  588. // }else{
  589. //
  590. // }
  591. }
  592. },
  593. doOfficeOCXEvents: function(){
  594. var id = this.getOfficeObjectId();
  595. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  596. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  597. this.addOfficeEvent(id, "OnDocumentClosed()", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentClosed();");
  598. },
  599. OnDocumentClosed: function(){
  600. this.fireEvent("afterCloseOffice");
  601. },
  602. OnDocumentOpened: function(url, doc){
  603. this.afterOpen();
  604. this.loadMenu();
  605. this.fireEvent("afterOpenOffice");
  606. },
  607. AfterOpenFromURL: function(doc, statusCode){
  608. this.fireEvent("afterOpen", [doc, statusCode]);
  609. },
  610. addOfficeEvent: function(id, event, code){
  611. var script = document.createElement("script");
  612. script.setAttribute("for", id);
  613. script.setAttribute("event", event);
  614. script.innerText = code;
  615. this.officeForm.appendChild(script);
  616. },
  617. loadOfficeRead: function(){
  618. this.loadOfficeSpacer();
  619. this.node.setStyle("pisition", "absolute");
  620. var codeBase = this.json.codeBase || this.options.codeBase;
  621. var version = this.json.version || this.options.version;
  622. var classid = this.json.clsid || this.options.clsid;
  623. var objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\""+
  624. "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
  625. "codeBase=\""+codeBase+"#version="+version+"\" " +
  626. "classid=\"clsid:"+classid+"\">";
  627. var pars = this.defaultParam(true);
  628. pars = Object.merge(pars, this.json.ntkoReadProperties);
  629. pars = Object.merge(pars, this.json.readProperties);
  630. Object.each(pars, function(p, key){
  631. objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
  632. });
  633. objectHtml += "</object></form>";
  634. this.officeNode.set("html", objectHtml);
  635. this.officeForm = this.officeNode.getFirst();
  636. this.officeOCX = this.officeNode.getFirst().getFirst();
  637. this.officeOCX.AddDocTypePlugin(".pdf","PDF.NtkoDocument","4.0.0.3","/x_desktop/res/framework/officecontrol/ntkooledocall.cab",51,true);
  638. var url = this.getOfficeFileUrl();
  639. if (url){
  640. var id = this.getOfficeObjectId();
  641. this.addOfficeEvent(id, "OnDocumentOpened(url, doc)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].OnDocumentOpened(url, doc);");
  642. this.addOfficeEvent(id, "AfterOpenFromURL(doc, statusCode)", "if (layout.desktop.offices[\""+id+"\"]) layout.desktop.offices[\""+id+"\"].AfterOpenFromURL(doc, statusCode);");
  643. this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  644. }
  645. },
  646. createUploadFileNode: function(){
  647. this.uploadFileAreaNode = new Element("div", {"styles": {"display": "none"}});
  648. var html = "<input name=\"file\" type=\"file\"/>";
  649. this.uploadFileAreaNode.set("html", html);
  650. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  651. this.uploadFileAreaNode.inject(this.officeForm);
  652. },
  653. getData: function(){
  654. if (this.officeOCX){
  655. this.officeOCX.ActiveDocument.Application.Selection.WholeStory();
  656. var content = this.officeOCX.ActiveDocument.Application.Selection.Text;
  657. return content;
  658. }else{
  659. return this._getBusinessData();
  660. }
  661. },
  662. setData: function(){},
  663. save: function(history){
  664. //if (!this.uploadFileAreaNode) this.createUploadFileNode();
  665. if (!this.readonly){
  666. if (!this.officeForm) return true;
  667. this.fireEvent("beforeSave");
  668. if (history){
  669. if (this.json.isHistory) this.saveHistory();
  670. }
  671. //this.saveHTML();
  672. this.officeForm.getElement("input").set("value", this.json.id);
  673. var url = "";
  674. if (this.file){
  675. url = this.form.workAction.action.actions.replaceAttachment.uri;
  676. url = url.replace("{id}", this.file.id);
  677. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  678. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  679. }else{
  680. url = this.form.workAction.action.actions.uploadAttachment.uri;
  681. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  682. this.officeOCX.SaveToURL(url, "file", "", this.getFileName(), this.getFormId());
  683. this.form.workAction.getWorkContent(this.form.businessData.work.id, function(json){
  684. this.form.businessData.attachmentList = json.data.attachmentList;
  685. this.getOfficeFileUrl();
  686. }.bind(this));
  687. }
  688. // this.stopRevisions(true);
  689. // this.saveHTML();
  690. // var url = this.getOfficeFileUrl();
  691. // if (url){
  692. // //layout.desktop.tmpOffice = this;
  693. // this.officeOCX.BeginOpenFromURL(url, true, this.readonly);
  694. // }else{
  695. // // if (this.json.officeType!=="other"){
  696. // this.officeOCX.CreateNew(this.getProgID());
  697. // this.fireEvent("afterCreate");
  698. // // }else{
  699. // //
  700. // // }
  701. // }
  702. this.fireEvent("afterSave");
  703. }
  704. },
  705. getHistoryFileName: function(){
  706. var ename = "doc";
  707. switch (this.json.officeType){
  708. case "word":
  709. ename = "doc";
  710. break;
  711. case "excel":
  712. ename = "xls";
  713. break;
  714. case "ppt":
  715. ename = "ppt";
  716. }
  717. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  718. var activity = (this.form.businessData.work) ? this.form.businessData.work.activityName : MWF.xApplication.process.Xform.LP.completed;
  719. var name = MWF.name.cn(layout.session.user.name);
  720. var d = Date.parse(new Date());
  721. var dText = d.format("%Y-%m-%d %H:%M");
  722. return activity+"("+name+")-"+dText+"."+ename;
  723. },
  724. saveHistory: function(){
  725. var fileName = this.getHistoryFileName();
  726. this.officeForm.getElement("input").set("value", this.json.id+"history");
  727. url = this.form.workAction.action.actions.uploadAttachment.uri;
  728. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  729. this.officeOCX.SaveToURL(url, "file", "", fileName, this.getFormId());
  730. },
  731. getHTMLFileName: function(){
  732. //var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
  733. var id = (this.form.businessData.work) ? this.form.businessData.work.id : this.form.businessData.workCompleted.workId;
  734. return id+this.json.id+".mht";
  735. },
  736. saveHTML: function(){
  737. debugger;
  738. this.officeForm.getElement("input").set("value", this.json.id+"$view");
  739. var file = null;
  740. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  741. var att = this.form.businessData.attachmentList[i];
  742. if (att.site==this.json.id+"$view"){
  743. file = att;
  744. }
  745. }
  746. var fileName = (file) ? file.name : this.getHTMLFileName();
  747. this.officeForm.getElement("input").getNext().set("value", fileName);
  748. if (file){
  749. url = this.form.workAction.action.actions.replaceAttachment.uri;
  750. url = url.replace("{id}", file.id);
  751. url = this.form.workAction.action.address+url.replace("{workid}", this.form.businessData.work.id);
  752. }else{
  753. url = this.form.workAction.action.actions.uploadAttachment.uri;
  754. url = this.form.workAction.action.address+url.replace("{id}", this.form.businessData.work.id);
  755. }
  756. //this.officeOCX.PublishAsHTMLToURL(url, "file", "", fileName, this.getFormId());
  757. this.officeOCX.SaveAsOtherFormatToURL(1, url, "file", "", fileName, this.getFormId());
  758. //this.officeOCX.PublishAsPDFToURL(url, "file", "", fileName, this.getFormId());
  759. },
  760. getHTMLFileUrl: function(name){
  761. var fileName = name || this.getHTMLFileName();
  762. var file = null;
  763. atts = this.form.businessData.attachmentList;
  764. for (var i=0; i<atts.length; i++){
  765. if ((atts[i].name===fileName) || (atts[i].site===this.json.id+"$view")){
  766. file = atts[i];
  767. break;
  768. }
  769. }
  770. if (file){
  771. //this.file = file;
  772. var url = "";
  773. if (this.form.businessData.work){
  774. url = this.form.workAction.action.actions.getAttachmentData.uri;
  775. url = url.replace("{id}", encodeURIComponent(file.id));
  776. return this.form.workAction.action.address+url.replace("{workid}", encodeURIComponent(this.form.businessData.work.id));
  777. }else{
  778. url = this.form.workAction.action.actions.getWorkcompletedAttachmentData.uri;
  779. url = url.replace("{id}", encodeURIComponent(file.id));
  780. return this.form.workAction.action.address+url.replace("{workCompletedId}", encodeURIComponent(this.form.businessData.workCompleted.id));
  781. }
  782. }else{
  783. return this.getTempleteUrl();
  784. }
  785. },
  786. validationMode: function(){},
  787. validation: function(){return true},
  788. loadOfficeNotActive: function(){
  789. var fileName = this.getFileName();
  790. var htmlName = "";
  791. var isHtml = false;
  792. for (var i=0; i<this.form.businessData.attachmentList.length; i++){
  793. var att = this.form.businessData.attachmentList[i];
  794. if (att.site==this.json.id+"$view"){
  795. htmlName = att.name;
  796. }
  797. }
  798. debugger;
  799. if (false){
  800. this.node.setStyles({
  801. "min-height": "600px",
  802. "padding": "0px",
  803. "border": "0px solid #999999",
  804. "background-color": "#e6e6e6",
  805. "overflow": "hidden"
  806. });
  807. if (this.node.getSize().y<800) this.node.setStyle("height", "800px");
  808. //this.node.setStyles(this.json.styles);
  809. var wordNode = new Element("div", {
  810. "styles": {
  811. "padding": "40px",
  812. "border": "1px solid #999999",
  813. "background-color": "#e6e6e6",
  814. "overflow": "auto"
  815. }
  816. }).inject(this.node);
  817. var size = this.node.getSize();
  818. var y = (size.y-80-80);
  819. wordNode.setStyle("height", ""+y+"px");
  820. var node = new Element("div", {
  821. "styles": {
  822. "width": "90%",
  823. "height": "1900px",
  824. "margin": "auto",
  825. "background-color": "#ffffff"
  826. }
  827. }).inject(wordNode);
  828. var iframe = new Element("iframe", {
  829. "styles": {
  830. "width": "100%",
  831. "height": "100%",
  832. "min-height": "600px",
  833. "overflow": "auto",
  834. "border": "1px solid #cccccc"
  835. }
  836. //"src": this.getHTMLFileUrl(htmlName)
  837. }).inject(node);
  838. //alert(iframe.contentWindow.document.body.firstChild);
  839. iframe.contentWindow.document.addEventListener("readystatechange", function(){
  840. alert("onreadystatechange"+ this.readyState );
  841. alert(this.body.firstChild);
  842. this.body.style.padding = "20px 40px";
  843. });
  844. // iframe.contentWindow.document.onreadystatechange = function(){
  845. // alert("onreadystatechange"+ this.readyState );
  846. // alert(this.body.firstChild);
  847. // this.body.style.padding = "20px 40px";
  848. // };
  849. iframe.set("src", this.getHTMLFileUrl(htmlName));
  850. // iframe.contentWindow.document.body.firstChild.style.paddingTop = "20px";
  851. // iframe.contentWindow.document.body.firstChild.style.paddingBottom = "20px";
  852. // iframe.contentWindow.document.body.firstChild.style.paddingLeft = "40px";
  853. // iframe.contentWindow.document.body.firstChild.style.paddingRight = "40px";
  854. }else{
  855. this.node.setStyles({
  856. "overflow": "hidden",
  857. "background-color": "#f3f3f3",
  858. "min-height": "24px",
  859. "padding": "18px"
  860. });
  861. var str = this.getData();
  862. if (layout.mobile || COMMON.Browser.Platform.isMobile){
  863. if (str.length>300) str = str.substr(0,300)+"……";
  864. }
  865. var text = new Element("div", {
  866. "text": str
  867. }).inject(this.node);
  868. }
  869. var text = MWF.xApplication.process.Xform.LP.openOfficeInfor;
  870. text = text.replace("{type}", this.json.officeType);
  871. var icon = new Element("div", {
  872. "styles": {
  873. "width": "200px",
  874. "height": "24px",
  875. "margin": "auto",
  876. "margin-top": "18px",
  877. "padding-left": "30px",
  878. "font-size": "16px",
  879. "font-weight": "bold",
  880. "color": "#2b5797",
  881. "font-family": "Gadugi",
  882. "cursor": "pointer",
  883. "background": "url("+this.form.path+""+this.form.options.style+"/icon/"+this.json.officeType+".png"+") no-repeat left center"
  884. },
  885. "text": text
  886. }).inject(this.node);
  887. var url = this.getOfficeFileUrl();
  888. if (!url){
  889. this.node.setStyle("display", "none");
  890. }
  891. icon.addEvent("click", function(){
  892. var url = this.getOfficeFileUrl();
  893. if (url){
  894. if (window.o2){
  895. window.o2.openDocument(url);
  896. }else if(window.webkit){
  897. window.webkit.messageHandlers.openDocument.postMessage(url);
  898. }else{
  899. window.open(url);
  900. }
  901. }
  902. }.bind(this));
  903. }
  904. });