CalendarPage.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. o2.widget = o2.widget || {};
  2. o2.require("o2.widget.Calendar", null, false);
  3. o2.widget.CalendarPage = o2.CalendarPage = new Class({
  4. Extends: o2.widget.Calendar,
  5. Implements: [Options, Events],
  6. initialize: function(node, options){
  7. Locale.use("zh-CHS");
  8. this.setOptions(options);
  9. this.path = o2.session.path+"/widget/$Calendar/";
  10. this.cssPath = o2.session.path+"/widget/$Calendar/"+this.options.style+"/css.wcss";
  11. this._loadCss();
  12. // this.options.containerPath = this.path+this.style+"/container.html";
  13. // this.options.dayPath = this.path+this.style+"/day.html";
  14. // this.options.monthPath = this.path+this.style+"/month.html";
  15. // this.options.yearPath = this.path+this.style+"/year.html";
  16. // this.options.timePath = this.path+this.style+"/time.html";
  17. if (this.options.isTime){
  18. //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
  19. this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
  20. }else{
  21. this.options.format = Locale.get("Date").shortDate;
  22. }
  23. this.options.containerPath = this.options.path+this.options.style+"/container.html";
  24. this.options.dayPath = this.options.path+this.options.style+"/day.html";
  25. this.options.monthPath = this.options.path+this.options.style+"/month.html";
  26. this.options.yearPath = this.options.path+this.options.style+"/year.html";
  27. this.options.timePath = this.options.path+this.options.style+"/time.html";
  28. this.today = new Date();
  29. this.currentView = this.options.defaultView;
  30. this.node = $(node);
  31. this.visible = false;
  32. this.container = this.createContainer();
  33. this.container.inject(this.node);
  34. this.contentTable = this.createContentTable();
  35. this.contentTable.inject(this.contentDateNode);
  36. this.addEvents();
  37. this.fireEvent("init");
  38. },
  39. addEvents: function(){
  40. this.prevNode.addEvent("click", function(){
  41. this.getPrev();
  42. }.bind(this));
  43. this.nextNode.addEvent("click", function(){
  44. this.getNext();
  45. }.bind(this));
  46. this.currentTextNode.addEvent("click", function(){
  47. this.changeView();
  48. }.bind(this));
  49. },
  50. show: function(){
  51. if (!this.visible){
  52. var dStr = this.node.get("value");
  53. if (dStr){
  54. this.options.baseDate = Date.parse(dStr.substr(0,10));
  55. }
  56. this.currentView = this.options.defaultView;
  57. switch (this.currentView) {
  58. case "day" :
  59. this.changeViewToDay();
  60. break;
  61. case "month" :
  62. this.showMonth();
  63. break;
  64. case "year" :
  65. this.showYear();
  66. break;
  67. case "time" :
  68. this.showTime(this.options.baseDate);
  69. break;
  70. default :
  71. this.showDay();
  72. }
  73. // if (!this.morph){
  74. // this.morph = new Fx.Morph(this.container, {"duration": 200});
  75. // }
  76. this.container.setStyle("display", "block");
  77. this.visible = true;
  78. this.fireEvent("show");
  79. }
  80. },
  81. _selectDate: function(dateStr, el){
  82. var date = new Date(dateStr);
  83. var dv = date.format(this.options.format);
  84. if (this.options.isTime){
  85. this.changeViewToTime(date);
  86. }else{
  87. if (this.fireEvent("queryComplate", dateStr)){
  88. var thisYaer = this.currentTextNode.retrieve("year");
  89. var thisMonth = this.currentTextNode.retrieve("month");
  90. baseDate = new Date();
  91. baseDate.setFullYear(thisYaer);
  92. baseDate.setMonth(thisMonth-1);
  93. var selectDate =new Date(dateStr);
  94. var tbody;
  95. if (el){
  96. tbody = el.getParent("tbody");
  97. }else{
  98. tbody = this.contentTable.getElement("tbody");
  99. }
  100. var tds = tbody.getElements("td");
  101. for (var i=0; i<tds.length; i++){
  102. var thisDate = new Date(tds[i].retrieve("dateValue"));
  103. thisDate.clearTime();
  104. if (thisDate.clearTime().toString() == this.today.clearTime().toString()){
  105. tds[i].setStyles(this.css["today_"+this.options.style]);
  106. tds[i].setStyle("border", "0px solid #AAA");
  107. }else if (thisDate.clearTime().toString() == selectDate.clearTime().toString()){
  108. tds[i].addClass("current_"+this.options.style);
  109. tds[i].setStyles(this.css["current_"+this.options.style]);
  110. tds[i].removeClass("gray_"+this.options.style);
  111. tds[i].removeClass("past_"+this.options.style);
  112. tds[i].setStyle("border", "1px solid #FFF");
  113. }else if(baseDate.getMonth()!=thisDate.getMonth()){
  114. tds[i].addClass("gray_"+this.options.style);
  115. tds[i].setStyles(this.css["gray_"+this.options.style]);
  116. tds[i].removeClass("current_"+this.options.style);
  117. tds[i].removeClass("past_"+this.options.style);
  118. tds[i].setStyle("border", "1px solid #FFF");
  119. }else if (thisDate.diff(this.today)>0){
  120. if (this.css["past_"+this.options.style]) tds[i].setStyles(this.css["past_"+this.options.style]);
  121. tds[i].addClass("past_"+this.options.style);
  122. tds[i].removeClass("current_"+this.options.style);
  123. tds[i].removeClass("gray_"+this.options.style);
  124. }else{
  125. tds[i].setStyles(this.css["normal_"+this.options.style]);
  126. tds[i].addClass("normal_"+this.options.style);
  127. tds[i].removeClass("current_"+this.options.style);
  128. tds[i].removeClass("gray_"+this.options.style);
  129. tds[i].removeClass("past_"+this.options.style);
  130. tds[i].setStyle("border", "1px solid #FFF");
  131. }
  132. }
  133. //el.setStyles(this.css["current_"+this.options.style]);
  134. // this.node.set("value", dv);
  135. // this.hide();
  136. this.fireEvent("complate");
  137. }
  138. }
  139. }
  140. });