MonthlyCalendar.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:10k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.MonthlyCalendar");
  9. dojo.require("dojo.date.common");
  10. dojo.require("dojo.date.format");
  11. dojo.require("dojo.widget.*");
  12. dojo.require("dojo.widget.DatePicker");
  13. dojo.require("dojo.event.*");
  14. dojo.require("dojo.html.*");
  15. dojo.require("dojo.experimental");
  16. dojo.experimental("dojo.widget.MonthlyCalendar");
  17. dojo.widget.defineWidget("dojo.widget.MonthlyCalendar", dojo.widget.DatePicker, {dayWidth:"wide", templateString:"<div class="datePickerContainer" dojoAttachPoint="datePickerContainerNode">nt<h3 class="monthLabel">nt<!--nt<span nttdojoAttachPoint="decreaseWeekNode" nttdojoAttachEvent="onClick: onIncrementWeek;" nttclass="incrementControl">ntt<img src="${dojoWidgetModuleUri}templates/decrementWeek.gif" alt="&uarr;" />nt</span>nt-->nt<span nttdojoAttachPoint="decreaseMonthNode" nttdojoAttachEvent="onClick: onIncrementMonth;" class="incrementControl">ntt<img src="${dojoWidgetModuleUri}templates/decrementMonth.gif" ntttalt="&uarr;" dojoAttachPoint="decrementMonthImageNode">nt</span>nt<span dojoAttachPoint="monthLabelNode" class="month">July</span>nt<span nttdojoAttachPoint="increaseMonthNode" nttdojoAttachEvent="onClick: onIncrementMonth;" class="incrementControl">ntt<img src="${dojoWidgetModuleUri}templates/incrementMonth.gif" ntttalt="&darr;"  dojoAttachPoint="incrementMonthImageNode">nt</span>nt<!--ntt<span dojoAttachPoint="increaseWeekNode" ntttdojoAttachEvent="onClick: onIncrementWeek;" ntttclass="incrementControl">nttt<img src="${dojoWidgetModuleUri}templates/incrementWeek.gif" ntttalt="&darr;" />ntt</span>nt-->nt</h3>nt<table class="calendarContainer">ntt<thead>nttt<tr dojoAttachPoint="dayLabelsRow">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>ntt</thead>ntt<tbody dojoAttachPoint="calendarDatesContainerNode" ntttdojoAttachEvent="onClick: onSetDate;">nttt<tr dojoAttachPoint="calendarRow0">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>nttt<tr dojoAttachPoint="calendarRow1">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>nttt<tr dojoAttachPoint="calendarRow2">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>nttt<tr dojoAttachPoint="calendarRow3">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>nttt<tr dojoAttachPoint="calendarRow4">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>nttt<tr dojoAttachPoint="calendarRow5">ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>ntttt<td></td>nttt</tr>ntt</tbody>nt</table>nt<h3 class="yearLabel">ntt<span dojoAttachPoint="previousYearLabelNode"ntttdojoAttachEvent="onClick: onIncrementYear;" class="previousYear"></span>ntt<span class="selectedYear" dojoAttachPoint="currentYearLabelNode"></span>ntt<span dojoAttachPoint="nextYearLabelNode" ntttdojoAttachEvent="onClick: onIncrementYear;" class="nextYear"></span>nt</h3>n</div>n", templateCssString:".datePickerContainer {ntmargin:0.5em 2em 0.5em 0;nt/*width:10em;*/ntfloat:left;n}nn.previousMonth {ntbackground-color:#bbbbbb;n}nn.currentMonth {ntbackground-color:#8f8f8f;n}nn.nextMonth {ntbackground-color:#eeeeee;n}nn.currentDate {nttext-decoration:underline;ntfont-style:italic;n}nn.selectedItem {ntbackground-color:#3a3a3a;ntcolor:#ffffff;n}nn.calendarContainer {ntborder-collapse:collapse;ntborder-spacing:0;ntborder-bottom:1px solid #e6e6e6;ntoverflow: hidden;nttext-align: right;n}nn.calendarContainer thead{ntborder-bottom:1px solid #e6e6e6;n}nn.calendarContainer tbody * td {n height: 100px;n border: 1px solid gray;n}nn.calendarContainer td {n width: 100px;n padding: 2px;ntvertical-align: top;n}nn.monthLabel {ntfont-size:0.9em;ntfont-weight:400;ntmargin:0;nttext-align:center;n}nn.monthLabel .month {ntpadding:0 0.4em 0 0.4em;n}nn.yearLabel {ntfont-size:0.9em;ntfont-weight:400;ntmargin:0.25em 0 0 0;nttext-align:right;ntcolor:#a3a3a3;n}nn.yearLabel .selectedYear {ntcolor:#000;ntpadding:0 0.2em;n}nn.nextYear, .previousYear {ntcursor:pointer;cursor:hand;n}nn.incrementControl {ntcursor:pointer;cursor:hand;ntwidth:1em;n}nn.dojoMonthlyCalendarEvent {ntfont-size:0.7em;ntoverflow: hidden;ntfont-color: grey;ntwhite-space: nowrap;nttext-align: left;n}n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/MonthlyCalendar.css"), initializer:function () {
  18. this.iCalendars = [];
  19. }, addCalendar:function (cal) {
  20. dojo.debug("Adding Calendar");
  21. this.iCalendars.push(cal);
  22. dojo.debug("Starting init");
  23. this.initUI();
  24. dojo.debug("done init");
  25. }, createDayContents:function (node, mydate) {
  26. dojo.html.removeChildren(node);
  27. node.appendChild(document.createTextNode(mydate.getDate()));
  28. for (var x = 0; x < this.iCalendars.length; x++) {
  29. var evts = this.iCalendars[x].getEvents(mydate);
  30. if ((dojo.lang.isArray(evts)) && (evts.length > 0)) {
  31. for (var y = 0; y < evts.length; y++) {
  32. var el = document.createElement("div");
  33. dojo.html.addClass(el, "dojoMonthlyCalendarEvent");
  34. el.appendChild(document.createTextNode(evts[y].summary.value));
  35. el.width = dojo.html.getContentBox(node).width;
  36. node.appendChild(el);
  37. }
  38. }
  39. }
  40. }, initUI:function () {
  41. var dayLabels = dojo.date.getNames("days", this.dayWidth, "standAlone", this.lang);
  42. var dayLabelNodes = this.dayLabelsRow.getElementsByTagName("td");
  43. for (var i = 0; i < 7; i++) {
  44. dayLabelNodes.item(i).innerHTML = dayLabels[i];
  45. }
  46. this.selectedIsUsed = false;
  47. this.currentIsUsed = false;
  48. var currentClassName = "";
  49. var previousDate = new Date();
  50. var calendarNodes = this.calendarDatesContainerNode.getElementsByTagName("td");
  51. var currentCalendarNode;
  52. previousDate.setHours(8);
  53. var nextDate = new Date(this.firstSaturday.year, this.firstSaturday.month, this.firstSaturday.date, 8);
  54. var lastDay = new Date(this.firstSaturday.year, this.firstSaturday.month, this.firstSaturday.date + 42, 8);
  55. if (this.iCalendars.length > 0) {
  56. for (var x = 0; x < this.iCalendars.length; x++) {
  57. this.iCalendars[x].preComputeRecurringEvents(lastDay);
  58. }
  59. }
  60. if (this.firstSaturday.date < 7) {
  61. var dayInWeek = 6;
  62. for (var i = this.firstSaturday.date; i > 0; i--) {
  63. currentCalendarNode = calendarNodes.item(dayInWeek);
  64. this.createDayContents(currentCalendarNode, nextDate);
  65. dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
  66. dayInWeek--;
  67. previousDate = nextDate;
  68. nextDate = this.incrementDate(nextDate, false);
  69. }
  70. for (var i = dayInWeek; i > -1; i--) {
  71. currentCalendarNode = calendarNodes.item(i);
  72. this.createDayContents(currentCalendarNode, nextDate);
  73. dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "previous"));
  74. previousDate = nextDate;
  75. nextDate = this.incrementDate(nextDate, false);
  76. }
  77. } else {
  78. nextDate.setDate(1);
  79. for (var i = 0; i < 7; i++) {
  80. currentCalendarNode = calendarNodes.item(i);
  81. this.createDayContents(currentCalendarNode, nextDate);
  82. dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
  83. previousDate = nextDate;
  84. nextDate = this.incrementDate(nextDate, true);
  85. }
  86. }
  87. previousDate.setDate(this.firstSaturday.date);
  88. previousDate.setMonth(this.firstSaturday.month);
  89. previousDate.setFullYear(this.firstSaturday.year);
  90. nextDate = this.incrementDate(previousDate, true);
  91. var count = 7;
  92. currentCalendarNode = calendarNodes.item(count);
  93. while ((nextDate.getMonth() == previousDate.getMonth()) && (count < 42)) {
  94. this.createDayContents(currentCalendarNode, nextDate);
  95. dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "current"));
  96. currentCalendarNode = calendarNodes.item(++count);
  97. previousDate = nextDate;
  98. nextDate = this.incrementDate(nextDate, true);
  99. }
  100. while (count < 42) {
  101. this.createDayContents(currentCalendarNode, nextDate);
  102. dojo.html.setClass(currentCalendarNode, this.getDateClassName(nextDate, "next"));
  103. currentCalendarNode = calendarNodes.item(++count);
  104. previousDate = nextDate;
  105. nextDate = this.incrementDate(nextDate, true);
  106. }
  107. this.setMonthLabel(this.firstSaturday.month);
  108. this.setYearLabels(this.firstSaturday.year);
  109. }});
  110. dojo.widget.MonthlyCalendar.util = new function () {
  111. this.toRfcDate = function (jsDate) {
  112. if (!jsDate) {
  113. jsDate = this.today;
  114. }
  115. var year = jsDate.getFullYear();
  116. var month = jsDate.getMonth() + 1;
  117. if (month < 10) {
  118. month = "0" + month.toString();
  119. }
  120. var date = jsDate.getDate();
  121. if (date < 10) {
  122. date = "0" + date.toString();
  123. }
  124. return year + "-" + month + "-" + date + "T00:00:00+00:00";
  125. };
  126. this.fromRfcDate = function (rfcDate) {
  127. var tempDate = rfcDate.split("-");
  128. if (tempDate.length < 3) {
  129. return new Date();
  130. }
  131. return new Date(parseInt(tempDate[0]), (parseInt(tempDate[1], 10) - 1), parseInt(tempDate[2].substr(0, 2), 10));
  132. };
  133. this.initFirstSaturday = function (month, year) {
  134. if (!month) {
  135. month = this.date.getMonth();
  136. }
  137. if (!year) {
  138. year = this.date.getFullYear();
  139. }
  140. var firstOfMonth = new Date(year, month, 1);
  141. return {year:year, month:month, date:7 - firstOfMonth.getDay()};
  142. };
  143. };