Office.js 70 KB

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