DayView.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. MWF.require("MWF.widget.Calendar", null, false);
  2. MWF.xApplication.Report.DayView = new Class({
  3. Extends: MWF.widget.Common,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "date": null
  8. },
  9. initialize: function(node, app, options){
  10. this.setOptions(options);
  11. this.path = "../x_component_Report/$DayView/";
  12. this.cssPath = "../x_component_Report/$DayView/"+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.app = app;
  15. this.container = $(node);
  16. var d = this.options.date;
  17. if( d ){
  18. this.date = typeOf( d ) == "string" ? new Date( d ) : d;
  19. }else{
  20. this.date = new Date();
  21. }
  22. this.load();
  23. },
  24. recordStatus : function(){
  25. return {
  26. date : (this.days.length > 0 ? this.days[0].date.clone() : this.date)
  27. };
  28. },
  29. load: function(){
  30. this.days = [];
  31. this.scrollNode = new Element("div.scrollNode", {
  32. "styles": this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode
  33. }).inject(this.container);
  34. this.contentWarpNode = new Element("div", {
  35. "styles": this.css.contentWarpNode
  36. }).inject(this.scrollNode);
  37. this.contentContainerNode = new Element("div",{
  38. "styles" : this.css.contentContainerNode
  39. }).inject(this.contentWarpNode);
  40. this.node = new Element("div", {
  41. "styles": this.css.contentNode
  42. }).inject(this.contentContainerNode);
  43. this.leftNode = new Element("div",{
  44. "styles" : this.css.leftNode_disable
  45. }).inject(this.node);
  46. this.leftNode.addEvents( {
  47. "click" : function(){ if( this.pageNum != 1 )this.decrementDay() }.bind(this),
  48. "mouseover" : function(){ if( this.pageNum != 1 )this.leftNode.setStyles( this.css.leftNode_over ) }.bind(this),
  49. "mouseout" : function(){ if( this.pageNum != 1 )this.leftNode.setStyles( this.css.leftNode ) }.bind(this)
  50. });
  51. this.dayContainerNode = new Element("div", {
  52. "styles": this.css.dayContainerNode
  53. }).inject(this.node);
  54. this.rightNode = new Element("div",{
  55. "styles" : this.css.rightNode_disable
  56. }).inject(this.node);
  57. this.rightNode.addEvents( {
  58. "click" : function(){ if( this.pageNum < this.totalPage )this.incrementDay() }.bind(this),
  59. "mouseover" : function(){ if( this.pageNum < this.totalPage )this.rightNode.setStyles( this.css.rightNode_over ) }.bind(this),
  60. "mouseout" : function(){ if( this.pageNum < this.totalPage )this.rightNode.setStyles( this.css.rightNode ) }.bind(this)
  61. });
  62. //this.node = new Element("div", {"styles": this.css.node}).inject(this.container);
  63. //this.loadSideBar();
  64. this.resetNodeSize();
  65. this.resetNodeSizeFun = this.resetNodeSize.bind(this);
  66. this.app.addEvent("resize", this.resetNodeSizeFun );
  67. //this.dateNode = new Element("div", {"styles": this.css.dateNode}).inject(this.node);
  68. },
  69. resetNodeSize: function(){
  70. var size = this.container.getSize();
  71. var sizeY = this.app.inContainer ? 800 : size.y;
  72. var leftNodeSize = this.leftNode ? this.leftNode.getSize() : {x:0,y:0};
  73. var rightNodeSize = this.rightNode ? this.rightNode.getSize() : {x:0,y:0};
  74. var sideBarSize = this.app.sideBar ? this.app.sideBar.getSize() : {x:0,y:0};
  75. var availableX = size.x - leftNodeSize.x - rightNodeSize.x - sideBarSize.x ;
  76. this.dayNodeHeight = sizeY-110;
  77. var leftTop = ( this.dayNodeHeight - leftNodeSize.y ) / 2;
  78. var rightTop = ( this.dayNodeHeight - rightNodeSize.y ) / 2;
  79. this.leftNode.setStyle("margin-top", ""+leftTop+"px");
  80. this.rightNode.setStyle("margin-top", ""+rightTop+"px");
  81. var dayCount = (availableX/330).toInt();
  82. if( this.app.inContainer ){
  83. this.scrollNode.setStyle("min-height", ""+(sizeY-60)+"px");
  84. }else{
  85. this.scrollNode.setStyle("height", ""+(sizeY-60)+"px");
  86. }
  87. this.scrollNode.setStyle("margin-top", "60px");
  88. this.scrollNode.setStyle("margin-right", sideBarSize.x);
  89. if (this.contentWarpNode){
  90. var x = 330 * dayCount + leftNodeSize.x + rightNodeSize.x + sideBarSize.x;
  91. var m = (size.x - x)/2-10;
  92. this.contentWarpNode.setStyles({
  93. "width": ""+x+"px",
  94. "margin-left": ""+m+"px"
  95. });
  96. }
  97. if( this.dayCount != dayCount ){
  98. this.dayCount = dayCount;
  99. this.getPageNumberForDay( function(){
  100. if( !this.totalPage ){
  101. this.showNoReportNode();
  102. }else{
  103. this.adjustDay();
  104. }
  105. }.bind(this))
  106. }else{
  107. for(var i = 0; i<this.days.length; i++ ){
  108. this.days[i].resetHeight();
  109. }
  110. }
  111. },
  112. getPageNumberForDay : function( callback ){
  113. var d = this.date.format("%Y-%m-%d");
  114. this.app.restActions.getPageNumberForDay( d, this.dayCount, function( json ){
  115. this.pageNum = json.data.currentPage;
  116. this.totalPage = json.data.totalPage;
  117. //this.totalCount = 2;
  118. if( callback )callback();
  119. }.bind(this))
  120. },
  121. listDayForPage : function( callback ){
  122. this.app.restActions.listDayForPage( this.pageNum, this.dayCount, function( json ){
  123. this.data = {};
  124. json.data.each( function( d , i ){
  125. if( i == 0 ){
  126. this.date = Date.parse(d.date );
  127. }
  128. this.data[d.date] = d.reports;
  129. }.bind(this));
  130. if(callback)callback();
  131. }.bind(this))
  132. },
  133. toDay: function(date){
  134. this.date = date;
  135. this.dayContainerNode.empty();
  136. this.leftNode.setStyles( this.css.leftNode_disable );
  137. this.rightNode.setStyles( this.css.rightNode_disable );
  138. this.days = [];
  139. this.getPageNumberForDay( function(){
  140. this.adjustDay();
  141. }.bind(this))
  142. },
  143. showNoReportNode : function(){
  144. if( this.noReportNode )this.noReportNode.destroy();
  145. this.noReportNode = new Element("div",{
  146. "styles" : this.css.noReportNode,
  147. "text" : this.app.lp.noReportDayView
  148. }).inject( this.contentContainerNode, "top" );
  149. this.setLeftRightNode();
  150. },
  151. adjustDay: function(){
  152. if( this.dayCount <= this.days.length ){
  153. for(var i = 0; i<this.days.length; i++ ){
  154. if( i < this.dayCount ){
  155. this.days[i].resetHeight();
  156. }else{
  157. if(this.days[i])this.days[i].destroy();
  158. }
  159. }
  160. this.days.splice( this.dayCount, (this.days.length - this.dayCount) );
  161. this.setLeftRightNode()
  162. }else{
  163. for(var i = 0; i<this.days.length; i++ ){
  164. this.days[i].resetHeight();
  165. }
  166. this.listDayForPage( function(){
  167. for( var key in this.data ){
  168. var d = this.data[key];
  169. var flag = true;
  170. this.days.each( function( day ){
  171. if( day.date.format("%Y-%m-%d") == key ){
  172. flag = false;
  173. }
  174. }.bind(this));
  175. if( flag ){
  176. this.loadDay( Date.parse(key), d, this.days.length==0 )
  177. }
  178. }
  179. this.setLeftRightNode()
  180. }.bind(this))
  181. }
  182. },
  183. setLeftRightNode: function(){
  184. if( this.pageNum == 1 || this.totalPage==0 ){
  185. this.leftNode.setStyles( this.css.leftNode_disable );
  186. }else{
  187. this.leftNode.setStyles( this.css.leftNode );
  188. }
  189. if( this.pageNum >= this.totalPage || this.totalPage==0 ){
  190. this.rightNode.setStyles( this.css.rightNode_disable );
  191. }else{
  192. this.rightNode.setStyles( this.css.rightNode );
  193. }
  194. },
  195. incrementDay : function(){
  196. if( this.pageNum >= this.totalPage )return;
  197. this.pageNum++;
  198. this.days.each( function( day ){
  199. day.destroy();
  200. }.bind(this));
  201. this.days = [];
  202. this.dayContainerNode.empty();
  203. this.leftNode.setStyles( this.css.leftNode_disable );
  204. this.rightNode.setStyles( this.css.rightNode_disable );
  205. this.adjustDay();
  206. },
  207. decrementDay : function( node ){
  208. if( this.pageNum == 1 )return;
  209. this.pageNum--;
  210. this.days.each( function( day ){
  211. day.destroy();
  212. }.bind(this));
  213. this.days = [];
  214. this.dayContainerNode.empty();
  215. this.leftNode.setStyles( this.css.leftNode_disable );
  216. this.rightNode.setStyles( this.css.rightNode_disable );
  217. this.adjustDay();
  218. },
  219. loadDay: function( date, data, setFirst ){
  220. var day = new MWF.xApplication.Report.DayView.Day(this, this.dayContainerNode, null, date, setFirst, data );
  221. this.days.push( day );
  222. //this.dayA.loadAction();
  223. },
  224. hide: function(){
  225. //this.app.removeEvent("resize", this.resetNodeSizeFun );
  226. var fx = new Fx.Morph(this.scrollNode, {
  227. "duration": "300",
  228. "transition": Fx.Transitions.Expo.easeOut
  229. });
  230. fx.start({
  231. "opacity": 0
  232. }).chain(function(){
  233. this.scrollNode.setStyle("display", "none");
  234. }.bind(this));
  235. },
  236. show: function(){
  237. //this.app.addEvent("resize", this.resetNodeSizeFun );
  238. this.scrollNode.setStyles(this.app.inContainer ? this.css.scrollNode_inContainer : this.css.scrollNode);
  239. this.scrollNode.setStyles({"display" : ""});
  240. var fx = new Fx.Morph(this.scrollNode, {
  241. "duration": "800",
  242. "transition": Fx.Transitions.Expo.easeOut
  243. });
  244. this.app.fireAppEvent("resize");
  245. fx.start({
  246. "opacity": 1,
  247. "left": "0px"
  248. }).chain(function(){
  249. this.scrollNode.setStyles({
  250. "position": "static",
  251. "width": "auto",
  252. "display" : ""
  253. });
  254. }.bind(this));
  255. },
  256. reload: function(){
  257. this.date = (this.days.length > 0 ? this.days[0].date.clone() : this.date);
  258. this.days.each( function(d){
  259. d.destroy();
  260. });
  261. this.dayContainerNode.empty();
  262. this.days = [];
  263. this.getPageNumberForDay( function(){
  264. if( !this.totalPage ){
  265. this.showNoReportNode();
  266. }else{
  267. this.adjustDay();
  268. }
  269. }.bind(this))
  270. },
  271. destroy : function(){
  272. this.days.each( function(d){
  273. d.destroy();
  274. });
  275. this.app.removeEvent("resize", this.resetNodeSizeFun );
  276. this.scrollNode.destroy();
  277. }
  278. });
  279. MWF.xApplication.Report.DayView.Day = new Class({
  280. Implements: [Events],
  281. initialize: function(view, node, position, date, isFirst, data){
  282. this.view = view;
  283. this.css = this.view.css;
  284. this.container = node;
  285. this.position = position || "bottom";
  286. this.app = this.view.app;
  287. this.date = (date) ? date.clone().clearTime() : (new Date()).clearTime();
  288. this.data = data;
  289. this.today = new Date().clearTime();
  290. this.isToday = (this.date.diff(this.today)==0);
  291. this.times = [];
  292. this.reports = [];
  293. this.isFirst = isFirst;
  294. this.load();
  295. },
  296. load : function(){
  297. this.node = new Element("div.dayNode", {"styles": this.css.dayNode}).inject(this.container , this.position);
  298. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  299. this.node.addEvents( {
  300. mouseover : function(){
  301. this.node.setStyles( this.css.dayNode_over );
  302. }.bind(this),
  303. mouseout : function(){
  304. this.node.setStyles( this.css.dayNode );
  305. }.bind(this)
  306. });
  307. this.titleNode = new Element("div.titleNode", { "styles": this.css[ !this.isToday ? "dayTitleNode" : "dayTitleNode_today"] }).inject(this.node);
  308. if( this.isFirst ){
  309. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  310. }else{
  311. className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  312. }
  313. this.titleTextNode = new Element("div.dayTitleTextNode", {
  314. "styles": this.css[ className ],
  315. "text" : this.date.format("%Y年%m月%d日")
  316. }).inject(this.titleNode);
  317. if( this.isFirst ){
  318. this.calendar = new MWF.xApplication.Report.Calendar(this.titleTextNode, {
  319. "style":"meeting_blue",
  320. "target": this.node,
  321. "baseDate" : this.date,
  322. "onQueryComplate": function(e, dv, date){
  323. var selectedDate = new Date.parse(dv);
  324. this.view.toDay(selectedDate);
  325. }.bind(this)
  326. });
  327. this.calendar.app = this.app;
  328. }
  329. this.dayWeekNode = new Element("div.dayWeekNode", {
  330. "styles": this.css[ !this.isToday ? "dayWeekNode" : "dayWeekNode_today"],
  331. "text" : this.getWeek()
  332. }).inject(this.titleNode);
  333. this.dayContentNode = new Element("div.dayContentNode", {"styles": this.css.dayContentNode}).inject(this.node);
  334. this.loadReports();
  335. },
  336. resetHeight: function(){
  337. this.node.setStyle("min-height",""+this.view.dayNodeHeight+"px");
  338. if( this.noReportNode ){
  339. this.noReportNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  340. this.noReportNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  341. }
  342. },
  343. getWeek: function(){
  344. var week = this.app.lp.weeks.arr[this.date.getDay()];
  345. var title = "";
  346. var now = this.today;
  347. var d = now.diff(this.date);
  348. if (d==0){
  349. title = this.app.lp.today;
  350. }else{
  351. title = week;
  352. }
  353. return title;
  354. },
  355. setFrist: function(){
  356. if( this.isFirst )return;
  357. this.isFirst = true;
  358. className = !this.isToday ? "dayTitleTextNode_first" : "dayTitleTextNode_today_first";
  359. this.titleTextNode.setStyles( this.css[ className ] );
  360. this.calendar = new MWF.xApplication.Report.Calendar(this.titleTextNode, {
  361. "style":"meeting_blue",
  362. "target": this.node,
  363. "baseDate" : this.date,
  364. "onQueryComplate": function(e, dv, date){
  365. var selectedDate = new Date.parse(dv);
  366. this.view.toDay(selectedDate);
  367. }.bind(this)
  368. });
  369. this.calendar.app = this.app;
  370. },
  371. //disposeFrist : function(){
  372. // if( !this.isFirst )return;
  373. // this.isFirst = false;
  374. // this.titleTextNode.removeEvent("click");
  375. // this.titleTextNode.removeEvent("focus");
  376. // var className = !this.isToday ? "dayTitleTextNode" : "dayTitleTextNode_today";
  377. // this.titleTextNode.setStyles( this.css[ className ] );
  378. // this.calendar.container.destroy();
  379. // this.calendar = null;
  380. //},
  381. destroy: function(){
  382. if( this.calendar ){
  383. this.calendar.container.destroy();
  384. }
  385. this.reports.each( function(m){
  386. m.destroy();
  387. });
  388. this.reports = [];
  389. this.node.destroy();
  390. },
  391. loadReports: function(){
  392. this.data.each( function( d ){
  393. this.reports.push(new MWF.xApplication.Report.ReportArea(this.dayContentNode, this, d));
  394. }.bind(this));
  395. //
  396. //this.app.actions.listReportDay(y, m, d, function(json){
  397. // var flag = true;
  398. // if( !json.data || json.data.length == 0 ){
  399. // }else{
  400. // json.data.each(function(report, i){
  401. // if (!report.myReject){
  402. // flag = false;
  403. // this.reports.push(new MWF.xApplication.Report.DayView.Report(this.dayContentNode, this, report));
  404. // }
  405. // }.bind(this));
  406. // }
  407. // if( flag ){
  408. // this.noReportNode = new Element("div.noReportNode", {
  409. // "styles": this.css.noReportNode,
  410. // "text" : this.app.lp.noReport
  411. // }).inject(this.dayContentNode);
  412. // this.noReportNode.setStyle("min-height",""+(this.view.dayNodeHeight - 220)+"px");
  413. // this.noReportNode.setStyle("line-height",""+(this.view.dayNodeHeight - 220)+"px");
  414. // }
  415. //}.bind(this));
  416. },
  417. reload : function(){
  418. this.view.reload();
  419. }
  420. });
  421. MWF.xApplication.Report.Calendar = new Class({
  422. Extends : MWF.widget.Calendar,
  423. _setDayDate: function(table, year, month){
  424. var baseDate = this.options.baseDate;
  425. if ((year!=undefined) && (month!=undefined)){
  426. baseDate = new Date();
  427. baseDate.setDate(1);
  428. baseDate.setFullYear(year);
  429. baseDate.setMonth(month);
  430. }
  431. this.loadDayData( baseDate, function(){
  432. this._setDayD( table, year, month )
  433. }.bind(this))
  434. },
  435. loadDayData : function(date, callback){
  436. var da = date.clone();
  437. da.decrement("month", 1);
  438. this.data = {};
  439. var flag = 0;
  440. for( var i=0; i<3; i++ ){
  441. var m = this.app.common.addZero( (da.get("month")+1).toString(), 2);
  442. var y = da.get("year");
  443. this.app.restActions.listDayByYearMonth(y, m, function(json){
  444. flag++;
  445. json.data.each( function(d){
  446. this.data[d.date] = d.reports;
  447. }.bind(this));
  448. if(callback && flag==3)callback();
  449. }.bind(this), null, false );
  450. da.increment("month", 1);
  451. }
  452. },
  453. _setDayD: function(table, year, month){
  454. var dayTable = table || this.contentTable;
  455. var baseDate = this.options.baseDate;
  456. if ((year!=undefined) && (month!=undefined)){
  457. baseDate = new Date();
  458. baseDate.setDate(1);
  459. baseDate.setFullYear(year);
  460. baseDate.setMonth(month);
  461. }
  462. var tbody = dayTable.getElement("tbody");
  463. var tds = tbody.getElements("td");
  464. var firstDate = baseDate.clone();
  465. firstDate.setDate(1);
  466. var day = firstDate.getDay();
  467. var tmpDate = firstDate.clone();
  468. for (var i=day-1; i>=0; i--){
  469. var td = tds[i];
  470. tmpDate.increment("day", -1);
  471. td.set("text", tmpDate.getDate());
  472. td.addClass("gray_"+this.options.style);
  473. td.setStyles(this.css["gray_"+this.options.style]);
  474. td.store("dateValue", tmpDate.toString());
  475. if( this.data[ tmpDate.format("%Y-%m-%d") ] ){
  476. td.setStyles({
  477. "position":"relative",
  478. "cursor" : "pointer"
  479. });
  480. new Element("div",{
  481. "position" : "absolute",
  482. "top" : "2px",
  483. "right" : "2px",
  484. "width" : "2px",
  485. "height" : "2px",
  486. "background-color" : "#4990e2",
  487. "border-radius" : "5px"
  488. }).inject( td )
  489. }else{
  490. tds[i].setStyles({
  491. "cursor" : "default"
  492. });
  493. }
  494. }
  495. for (var i=day; i<tds.length; i++){
  496. tds[i].set("text", firstDate.getDate());
  497. if (firstDate.toString() == this.options.baseDate.toString()){
  498. tds[i].addClass("current_"+this.options.style);
  499. tds[i].setStyles(this.css["current_"+this.options.style]);
  500. tds[i].removeClass("gray_"+this.options.style);
  501. tds[i].setStyle("border", "1px solid #FFF");
  502. }else if (firstDate.getMonth()!=baseDate.getMonth()){
  503. tds[i].addClass("gray_"+this.options.style);
  504. tds[i].setStyles(this.css["gray_"+this.options.style]);
  505. tds[i].removeClass("current_"+this.options.style);
  506. tds[i].setStyle("border", "1px solid #FFF");
  507. }else{
  508. tds[i].setStyles(this.css["normal_"+this.options.style]);
  509. tds[i].removeClass("current_"+this.options.style);
  510. tds[i].removeClass("gray_"+this.options.style);
  511. tds[i].setStyle("border", "1px solid #FFF");
  512. }
  513. var tmp = firstDate.clone();
  514. if (tmp.clearTime().toString() == this.today.clearTime().toString()){
  515. //tds[i].addClass("today_"+this.options.style);
  516. tds[i].setStyles(this.css["today_"+this.options.style]);
  517. tds[i].setStyle("border", "0px solid #AAA");
  518. }
  519. tds[i].store("dateValue", firstDate.toString());
  520. if( this.data[ firstDate.format("%Y-%m-%d") ] ){
  521. var td = tds[i];
  522. td.setStyles({
  523. "position":"relative",
  524. "cursor" : "pointer"
  525. });
  526. new Element("div", { styles : {
  527. "position" : "absolute",
  528. "top" : "5px",
  529. "right" : "5px",
  530. "width" : "5px",
  531. "height" : "5px",
  532. "background-color" : "#4990e2",
  533. "border-radius" : "5px"
  534. }
  535. }).inject( td )
  536. }else{
  537. tds[i].setStyles({
  538. "cursor" : "default"
  539. });
  540. }
  541. firstDate.increment("day", 1);
  542. }
  543. },
  544. _selectDate: function(dateStr){
  545. var date = new Date(dateStr);
  546. if( !this.data[ date.format("%Y-%m-%d") ] ){
  547. return;
  548. }
  549. var dv = date.format(this.options.format);
  550. if (this.options.isTime){
  551. this.changeViewToTime(date);
  552. }else{
  553. if (!this.options.beforeCurrent){
  554. var now = new Date();
  555. date.setHours(23,59,59);
  556. if (date.getTime()-now.getTime()<0){
  557. alert("选择的日期必须大于当前日期!");
  558. this.node.focus();
  559. return false;
  560. }
  561. }
  562. if (this.fireEvent("queryComplate", [dv, date])){
  563. this.node.set("value", dv);
  564. this.hide();
  565. this.fireEvent("complate", [dv, date]);
  566. }
  567. }
  568. }
  569. });