Main.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. MWF.xApplication.Report = MWF.xApplication.Report || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. //MWF.xDesktop.requireApp("Report", "Access", null, false);
  4. //MWF.xDesktop.requireApp("Report", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  6. MWF.xDesktop.requireApp("Report", "Common", null, false);
  7. MWF.xDesktop.requireApp("Report", "Setting", null, false);
  8. MWF.xApplication.Report.options = {
  9. multitask: false,
  10. executable: true
  11. };
  12. MWF.xApplication.Report.Main = new Class({
  13. Extends: MWF.xApplication.Common.Main,
  14. Implements: [Options, Events],
  15. options: {
  16. "style": "default",
  17. "name": "Report",
  18. "view" : "all",
  19. "icon": "icon.png",
  20. "width": "1220",
  21. "height": "700",
  22. "isResize": true,
  23. "isMax": true,
  24. "sideBarEnable" : true,
  25. "title": MWF.xApplication.Report.LP.title
  26. },
  27. onQueryLoad: function () {
  28. this.lp = MWF.xApplication.Report.LP;
  29. },
  30. loadApplication: function (callback) {
  31. MWF.UD.getDataJson("reportConfig", function (json) {
  32. this.reportConfig = json || {};
  33. if (!this.options.isRefresh) {
  34. this.maxSize(function () {
  35. this.loadLayout();
  36. }.bind(this));
  37. } else {
  38. this.loadLayout();
  39. }
  40. if (callback) callback();
  41. }.bind(this));
  42. },
  43. loadLayout : function(){
  44. this.userName = ( layout.desktop.session.user || layout.user ).distinguishedName;
  45. this.restActions = MWF.Actions.get("x_report_assemble_control"); //new MWF.xApplication.Report.Actions.RestActions();
  46. this.strategyActions = MWF.Actions.get("x_strategydeploy_assemble_control");
  47. this.common = new MWF.xApplication.Report.Common(this);
  48. this.path = "/x_component_Report/$Main/" + this.options.style + "/";
  49. //this.restActions.getIdentity( this.userName, function( json ){
  50. // this.identityList = json.data.identityList;
  51. // this.identityCNList = [];
  52. // this.identityList.each( function( id ){
  53. // this.identityCNList.push(id.split("@")[0])
  54. // }.bind(this));
  55. // this.identityCNList.unique();
  56. //
  57. //}.bind(this))
  58. this.createNode();
  59. this.loadApplicationContent();
  60. },
  61. loadController: function (callback) {
  62. this.isAdmin = this.common.isAdmin();
  63. if( this.isAdmin ){
  64. this.exportAllFlag = true;
  65. }else{
  66. this.exportAllFlag = this.common.hasExportAllUnitPermission();
  67. }
  68. this.unitWithExport = [];
  69. if( !this.exportAllFlag ){
  70. this.common.getUnitWithExportPermission( function( unit ){
  71. this.unitWithExport = unit;
  72. if (callback)callback();
  73. }.bind(this))
  74. }else{
  75. //this.isAdmin = MWF.AC.isAdministrator();
  76. if (callback)callback();
  77. }
  78. },
  79. isShowExport : function(){
  80. if( this.isAdmin )return true;
  81. if( this.exportAllFlag )return true;
  82. if( this.unitWithExport && this.unitWithExport.length > 0 )return true;
  83. return false;
  84. },
  85. createNode: function(){
  86. this.content.setStyle("overflow", "hidden");
  87. this.node = new Element("div.reportNode", {
  88. "styles": {"width": "100%", "height": "100%", "overflow": "hidden", "background-color":"#eee"}
  89. }).inject(this.content);
  90. },
  91. loadApplicationContent: function () {
  92. this.loadController(function () {
  93. this.loadApplicationLayout();
  94. }.bind(this))
  95. },
  96. loadApplicationLayout: function () {
  97. if( this.status && this.status.action ){
  98. this.defaultAction = this.status.action;
  99. }else if (this.reportConfig.defaultView){
  100. this.defaultAction = this.reportConfig.defaultView;
  101. }else if( this.options.view == "todo" ) {
  102. this.defaultAction = "toTodo";
  103. }else{
  104. this.defaultAction = "toList";
  105. }
  106. if( (this.common.isAdmin() || this.isShowExport()) && this.options.view == "all" ){
  107. this.topMenu = new Element("div", {"styles": this.css.topMenu}).inject(this.node);
  108. }
  109. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  110. if( this.options.view == "todo" ){
  111. this.toTodo();
  112. }else if( (this.common.isAdmin() || this.isShowExport()) && this.options.view == "all" ){
  113. this.loadTopMenus();
  114. }else{
  115. this.toList();
  116. }
  117. if( this.options.sideBarEnable ){
  118. //this.loadSideBar();
  119. }
  120. },
  121. loadTopMenus_right: function(){
  122. this.topMenuRight = new Element("div", {"styles": this.css.topMenuRight }).inject(this.topMenu);
  123. //this.createTopMenu_right(this.lp.addReport, "icon_newapply", "addReport");
  124. var configNode = this.createTopMenu_right(this.lp.setting, "icon_shezhi", "config");
  125. configNode.setStyle("float", "right");
  126. },
  127. createTopMenu_right : function(text, icon, action){
  128. var actionNode = new Element("div", {"styles": this.css.topMenuNode_right, "title" : text}).inject(this.topMenuRight);
  129. var actionIconNode = new Element("div", {"styles": this.css.topMenuIconNode}).inject(actionNode);
  130. actionIconNode.setStyle("background", "url(/x_component_Report/$Main/default/icon/"+icon+".png) no-repeat center center");
  131. actionNode.store("icon",icon);
  132. actionNode.store("iconNode",actionIconNode);
  133. var _self = this;
  134. actionNode.addEvents({
  135. "mouseover": function(){
  136. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  137. }.bind( { node : actionNode } ),
  138. "mouseout": function(){
  139. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+".png) no-repeat center center" );
  140. }.bind({ node:actionNode }),
  141. "click": function(){
  142. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  143. if (_self[action]) _self[action].apply(_self);
  144. }.bind({ node : actionNode })
  145. });
  146. return actionNode;
  147. },
  148. loadTopMenus: function(){
  149. this.createTopMenu(this.lp.list, "icon_liebiao", "toList");
  150. //this.createTopMenu(this.lp.month, "icon_yue", "toMonth");
  151. //this.createTopMenu(this.lp.day, "icon_ri", "toDay");
  152. //this.createTopMenu(this.lp.mind, "icon_naotu", "toKeyWork");
  153. if( this.isShowExport() ){
  154. this.createTopMenu( "导出", "icon_export", "toStatistics", true);
  155. this.createTopMenu( "部门五项重点工作统览", "icon_tongji", "toSummarization", true);
  156. }
  157. if( this.common.isAdmin() ){
  158. this.createTopMenu( this.lp.startRecord, "icon_liebiao", "toStartRecord");
  159. this.loadTopMenus_right();
  160. }
  161. },
  162. createTopMenu: function(text, icon, action, isPop){
  163. var actionNode = new Element("div", {"styles": this.css.topMenuNode}).inject(this.topMenu);
  164. var actionIconNode = new Element("div", {"styles": this.css.topMenuIconNode}).inject(actionNode);
  165. actionIconNode.setStyle("background", "url(/x_component_Report/$Main/default/icon/"+icon+".png) no-repeat center center");
  166. var actionTextNode = new Element("div", {"styles": this.css.topMenuTextNode, "text": text}).inject(actionNode);
  167. actionNode.store("icon",icon);
  168. actionNode.store("iconNode",actionIconNode);
  169. actionNode.store("action",action);
  170. var _self = this;
  171. actionNode.addEvents({
  172. "mouseover": function(){
  173. if( this.node != _self.currentTopMenuNode ){
  174. this.node.setStyles(_self.css.topMenuNode_over);
  175. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  176. }
  177. }.bind( { node : actionNode } ),
  178. "mouseout": function(){
  179. if(this.node != _self.currentTopMenuNode){
  180. this.node.setStyles(_self.css.topMenuNode);
  181. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+".png) no-repeat center center" );
  182. }
  183. }.bind({ node:actionNode }),
  184. "click": function(){
  185. if( !isPop ){
  186. if( this.node != _self.currentTopMenuNode ){
  187. this.node.setStyles( _self.css.topMenuNode_down );
  188. this.node.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+this.node.retrieve("icon")+"_click.png) no-repeat center center" );
  189. }
  190. if( _self.currentTopMenuNode && this.node != _self.currentTopMenuNode){
  191. _self.currentTopMenuNode.setStyles( _self.css.topMenuNode );
  192. _self.currentTopMenuNode.retrieve("iconNode").setStyle( "background","url(/x_component_Report/$Main/default/icon/"+_self.currentTopMenuNode.retrieve("icon")+".png) no-repeat center center" );
  193. }
  194. _self.currentTopMenuNode = this.node;
  195. }
  196. if (_self[action]) _self[action].apply(_self);
  197. }.bind({ node : actionNode })
  198. });
  199. if( this.defaultAction == action ){
  200. actionNode.click();
  201. }
  202. return actionNode;
  203. },
  204. showMenu: function(){
  205. if (this.menuMode!="show") {
  206. this.topMenu.set("tween", {duration: 100, transition: "bounce:out"});
  207. this.topMenu.tween("top", "-50px", "0px");
  208. this.menuMode = "show";
  209. }
  210. },
  211. hideCurrentView: function(){
  212. if (this.currentView){
  213. this.currentView.hide();
  214. this.currentView = null;
  215. }
  216. },
  217. toMyReport: function(){
  218. this.contentNode.setStyles(this.css.contentNode);
  219. if( this.currentView ){
  220. this.currentView.destroy();
  221. this.currentView = null;
  222. }
  223. this.myReportView = null;
  224. this.getMyReportView(function(){
  225. this.myReportView.show();
  226. this.currentView = this.myReportView;
  227. }.bind(this));
  228. },
  229. getMyReportView: function(callback){
  230. if (!this.myReportView){
  231. MWF.xDesktop.requireApp("Report", "ReportView", function(){
  232. var options;
  233. if( this.status && this.status.options ){
  234. options = this.status.options
  235. }
  236. this.myReportView = new MWF.xApplication.Report.ReportView(this.contentNode, this, options);
  237. if( options )this.status.options = null;
  238. if (callback) callback();
  239. }.bind(this));
  240. }else{
  241. if (callback) callback();
  242. }
  243. },
  244. toTodo: function(){
  245. if( this.currentView ){
  246. this.currentView.destroy();
  247. this.currentView = null;
  248. }
  249. this.todoView = null;
  250. this.getTodoView(function(){
  251. this.todoView.show();
  252. this.currentView = this.todoView;
  253. }.bind(this));
  254. },
  255. getTodoView: function(callback){
  256. if (!this.todoView){
  257. MWF.xDesktop.requireApp("Report", "ListView", function(){
  258. var options;
  259. if( this.status && this.status.options ){
  260. options = this.status.options
  261. }
  262. options = options || {};
  263. options.isTodo = true;
  264. this.todoView = new MWF.xApplication.Report.ListView(this.contentNode, this, options);
  265. if( this.status && this.status.options )this.status.options = null;
  266. if (callback) callback();
  267. }.bind(this));
  268. }else{
  269. if (callback) callback();
  270. }
  271. },
  272. toList: function(){
  273. //this.contentNode.setStyle("background", "#f7f7f7");
  274. if( this.currentView ){
  275. this.currentView.destroy();
  276. this.currentView = null;
  277. }
  278. this.listView = null;
  279. this.getListView(function(){
  280. this.listView.show();
  281. this.currentView = this.listView;
  282. }.bind(this));
  283. },
  284. getListView: function(callback){
  285. if (!this.listView){
  286. MWF.xDesktop.requireApp("Report", "ListView", function(){
  287. var options;
  288. if( this.status && this.status.options ){
  289. options = this.status.options
  290. }
  291. this.listView = new MWF.xApplication.Report.ListView(this.contentNode, this, options);
  292. if( options )this.status.options = null;
  293. if (callback) callback();
  294. }.bind(this));
  295. }else{
  296. if (callback) callback();
  297. }
  298. },
  299. toMonth: function(){
  300. //this.contentNode.setStyle("background", "#f7f7f7");
  301. if( this.currentView ){
  302. this.currentView.destroy();
  303. this.currentView = null;
  304. }
  305. this.monthView = null;
  306. this.getMonthView(function(){
  307. this.monthView.show();
  308. this.currentView = this.monthView;
  309. }.bind(this));
  310. },
  311. getMonthView: function(callback){
  312. if (!this.monthView){
  313. MWF.xDesktop.requireApp("Report", "MonthView", function(){
  314. var options;
  315. if( this.status && this.status.options ){
  316. options = this.status.options
  317. }
  318. this.monthView = new MWF.xApplication.Report.MonthView(this.contentNode, this, options);
  319. if( options )this.status.options = null;
  320. if (callback) callback();
  321. }.bind(this));
  322. }else{
  323. if (callback) callback();
  324. }
  325. },
  326. toDay: function(d){
  327. //this.contentNode.setStyle("background", "#f7f7f7");
  328. if( this.currentView ){
  329. this.currentView.destroy();
  330. this.currentView = null;
  331. }
  332. this.dayView = null;
  333. this.getDayView(function(){
  334. this.dayView.show();
  335. this.currentView = this.dayView;
  336. }.bind(this), d);
  337. },
  338. getDayView: function(callback, d){
  339. if (!this.dayView){
  340. MWF.xDesktop.requireApp("Report", "DayView", function(){
  341. var options;
  342. if( this.status && this.status.options ){
  343. options = this.status.options
  344. }
  345. this.dayView = new MWF.xApplication.Report.DayView(this.contentNode, this, options || {"date": d});
  346. if(this.status)this.status.options = null;
  347. if (callback) callback();
  348. }.bind(this));
  349. }else{
  350. this.dayView.toDay(d);
  351. if (callback) callback();
  352. }
  353. },
  354. toKeyWork : function(d){
  355. //this.contentNode.setStyle("background", "#f7f7f7");
  356. if( this.currentView ){
  357. this.currentView.destroy();
  358. this.currentView = null;
  359. }
  360. this.mindView = null;
  361. this.getKeyWorkView(function(){
  362. this.mindView.load();
  363. this.currentView = this.mindView;
  364. }.bind(this), d);
  365. },
  366. getKeyWorkView: function(callback, d){
  367. if (!this.mindView){
  368. MWF.xDesktop.requireApp("Report", "MindView", function(){
  369. var options;
  370. if( this.status && this.status.options ){
  371. options = this.status.options
  372. }
  373. this.mindView = new MWF.xApplication.Report.MindView(this.contentNode, this, this.restActions, options || {"date": d});
  374. if(this.status)this.status.options = null;
  375. if (callback) callback();
  376. }.bind(this));
  377. }else{
  378. this.mindView.load(d);
  379. if (callback) callback();
  380. }
  381. },
  382. toStatistics : function(){
  383. var form = new MWF.xApplication.Report.StatisticsForm( this, {}, {}, { app : this } );
  384. form.create();
  385. },
  386. toSummarization : function(){
  387. var form = new MWF.xApplication.Report.SummarizationForm( this, {}, {}, { app : this } );
  388. form.create();
  389. },
  390. //toStatistics : function(d){
  391. // if( this.currentView ){
  392. // this.currentView.destroy();
  393. // this.currentView = null;
  394. // }
  395. // this.statisticsView = null;
  396. // this.getStatisticsView(function(){
  397. // this.statisticsView.load();
  398. // this.currentView = this.statisticsView;
  399. // }.bind(this), d);
  400. //},
  401. //getStatisticsView: function(callback, d){
  402. // if (!this.statisticsView){
  403. // MWF.xDesktop.requireApp("Report", "StatisticsView", function(){
  404. // var options;
  405. // if( this.status && this.status.options ){
  406. // options = this.status.options
  407. // }
  408. // this.statisticsView = new MWF.xApplication.Report.StatisticsView(this.contentNode, this, this.restActions, options || {"date": d});
  409. // if(this.status)this.status.options = null;
  410. // if (callback) callback();
  411. // }.bind(this));
  412. // }else{
  413. // this.statisticsView.load(d);
  414. // if (callback) callback();
  415. // }
  416. //},
  417. toStartRecord: function(){
  418. //this.contentNode.setStyle("background", "#f7f7f7");
  419. if( this.currentView ){
  420. this.currentView.destroy();
  421. this.currentView = null;
  422. }
  423. this.startRecordView = null;
  424. this.getStartRecordView(function(){
  425. this.startRecordView.show();
  426. this.currentView = this.startRecordView;
  427. }.bind(this));
  428. },
  429. getStartRecordView: function(callback){
  430. if (!this.startRecordView){
  431. MWF.xDesktop.requireApp("Report", "StartRecordView", function(){
  432. var options;
  433. if( this.status && this.status.options ){
  434. options = this.status.options
  435. }
  436. this.startRecordView = new MWF.xApplication.Report.StartRecordView(this.contentNode, this, options);
  437. if( options )this.status.options = null;
  438. if (callback) callback();
  439. }.bind(this));
  440. }else{
  441. if (callback) callback();
  442. }
  443. },
  444. config: function(){
  445. //new MWF.xApplication.Report.Config(this, this.reportConfig);
  446. var setting = new MWF.xApplication.Report.SettingForm(this, null, {
  447. height : this.common.isAdmin() ? "600" : "300",
  448. width : this.common.isAdmin() ? "1000" : "700"
  449. }, {
  450. app : this
  451. });
  452. setting.edit();
  453. },
  454. recordStatus: function(){
  455. return {
  456. action : this.currentTopMenuNode ? this.currentTopMenuNode.retrieve("action") : "toList",
  457. options : (this.currentView && this.currentView.recordStatus) ? this.currentView.recordStatus() : null
  458. };
  459. },
  460. reload: function( ){
  461. this.refresh()
  462. },
  463. loadSideBar : function(){
  464. this.sideBar = new MWF.xApplication.Report.SideBar(this.node, this);
  465. this.sideBar.show();
  466. },
  467. addReport : function(){
  468. //var data = { id : "94949494948" }; //this.data;
  469. //var appId = "ReportDocument"+data.id;
  470. //if (this.desktop.apps[appId]){
  471. // this.desktop.apps[appId].setCurrent();
  472. //}else {
  473. // this.desktop.openApplication(null, "ReportDocument", {
  474. // "id" : data.id,
  475. // "isEdited" : false,
  476. // "isNew" : false
  477. // });
  478. //}
  479. //var form = new MWF.xApplication.Report.CustomWorkForm( this, { "reportId" : this.options.id }, {}, {
  480. // app : this
  481. //} );
  482. //form.create();
  483. //MWF.xDesktop.requireApp("Template", "Test", null, false);
  484. //var test = new MWF.xApplication.Template.Test(this, { "reportId" : this.options.id }, {}, {
  485. // app : this
  486. //});
  487. //test.open();
  488. }
  489. });
  490. var getDateDiff = function (publishTime) {
  491. if(!publishTime)return "";
  492. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  493. var minute = 1000 * 60;
  494. var hour = minute * 60;
  495. var day = hour * 24;
  496. var halfamonth = day * 15;
  497. var month = day * 30;
  498. var year = month * 12;
  499. var now = new Date().getTime();
  500. var diffValue = now - dateTimeStamp;
  501. if (diffValue < 0) {
  502. //若日期不符则弹出窗口告之
  503. //alert("结束日期不能小于开始日期!");
  504. }
  505. var yesterday = new Date().decrement('day', 1);
  506. var beforYesterday = new Date().decrement('day', 2);
  507. var yearC = diffValue / year;
  508. var monthC = diffValue / month;
  509. var weekC = diffValue / (7 * day);
  510. var dayC = diffValue / day;
  511. var hourC = diffValue / hour;
  512. var minC = diffValue / minute;
  513. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  514. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  515. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  516. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  517. } else if (yearC > 1) {
  518. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  519. } else if (monthC >= 1) {
  520. //result= parseInt(monthC) + "个月前";
  521. // s.getFullYear()+"年";
  522. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  523. } else if (weekC >= 1) {
  524. result = parseInt(weekC) + "周前";
  525. } else if (dayC >= 1) {
  526. result = parseInt(dayC) + "天前";
  527. } else if (hourC >= 1) {
  528. result = parseInt(hourC) + "小时前";
  529. } else if (minC >= 1) {
  530. result = parseInt(minC) + "分钟前";
  531. } else
  532. result = "刚刚发表";
  533. return result;
  534. };