CalendarView.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var calendarView;
  2. var emptyWeeks;
  3. var emptyWeeksEnd;
  4. var totalWeeks;
  5. function SchCalendar_Export() {
  6. $("#formQuery").submit();
  7. }
  8. function getCalendarView() {
  9. if ($("#SchoolYearDropdown").length > 0 && $.data($("#SchoolYearDropdown")[0], "combobox")) {
  10. var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
  11. $.post(calenderUrl, { schoolYearID: schoolYearID }, function (data) {
  12. if (data.IsSuccess) {
  13. calendarView = data.Data;
  14. draw();
  15. } else {
  16. $.messager.alert("系统提示", data.Message);
  17. }
  18. })
  19. }
  20. }
  21. //需要在getTotalWeeks方法调用之后才调用,有依赖关系
  22. function getWeeksOfMonth(month) {
  23. //var isParaMonth = false;
  24. var startDate = eval('new ' + eval(calendarView.StartDate).source);
  25. var beginDate = startDate.addDay(-1);
  26. var weekCount = 0;
  27. for (var i = 0; i < totalWeeks; i++) {
  28. var curWeekStart = beginDate.addDay(1 + (i * 7));
  29. var curWeekEnd = beginDate.addDay((i + 1) * 7);
  30. if (curWeekEnd.getMonth() == (month - 1)) { //javascript的月份是从0开始的
  31. //isParaMonth = true;
  32. weekCount++;
  33. }
  34. // else if (isParaMonth && (curWeekStart.getMonth() == (month - 1))) {
  35. // weekCount++;
  36. // break;
  37. // }
  38. }
  39. return weekCount;
  40. }
  41. function getTotalWeeks() {
  42. var startDate = eval('new ' + eval(calendarView.StartDate).source);
  43. var endDate = eval('new ' + eval(calendarView.EndDate).source);
  44. var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
  45. emptyWeeks = Math.ceil(firstWeek.substractDay(startDate) / 7);
  46. emptyWeeksEnd = Math.floor(endDate.substractDay(firstWeek.addDay(calendarView.SchoolYear.WeeksNum * 7)) / 7);
  47. totalWeeks = calendarView.SchoolYear.WeeksNum + emptyWeeks + emptyWeeksEnd;
  48. }
  49. function draw() {
  50. var html = new Array();
  51. getTotalWeeks();
  52. html.push('<table class="calendarview-table" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">');
  53. html.push(getTitleRow());
  54. html.push(getMonthTitleRow());
  55. html.push(getDayRows());
  56. html.push(getWeekTitleRow());
  57. html.push('</table>');
  58. html.push('<br>注:表上有★者为法定节假日,停课,不补课;有阴影的为寒暑假时间。<br/>');
  59. html.push('<br>法定节假日:' + calendarView.HolidayStr + '<br/>');
  60. html.push('<br>校内安排:' + calendarView.ScalendarStr + '<br/>');
  61. $("#calendarviewcontent").html(html.join("\n"));
  62. drawSplashLine($(".calendarview-monthtitle-left")[0]);
  63. }
  64. function getTitleRow() {
  65. var html = new Array();
  66. html.push(' <tr>');
  67. // html.push(' <td class="calendarview-title" colspan="' + (totalWeeks + 1) + '">'
  68. // .concat(calendarView.UniversityName, calendarView.SchoolYear.Years, '学年', calendarView.SchoolYear.SchoolcodeName, '校历</td>'));
  69. html.push(' <td class="calendarview-title" colspan="' + (totalWeeks + 1) + '">'
  70. .concat(calendarView.UniversityName, calendarView.SchoolYear.Code, '学期校历</td>'));
  71. html.push(' </tr>');
  72. return html.join("\n");
  73. }
  74. function getConner() {
  75. var html = new Array();
  76. html.push('<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">');
  77. html.push(' <tr>');
  78. html.push(' <td></td>');
  79. html.push(' <td>月份</td>');
  80. html.push(' </tr>');
  81. html.push(' <tr>');
  82. html.push(' <td>星期</td>');
  83. html.push(' <td></td>');
  84. html.push(' </tr>');
  85. html.push('</table>');
  86. return html.join("\n");
  87. }
  88. function getMonthTitleRow() {
  89. var html = new Array();
  90. var endDate = eval('new ' + eval(calendarView.EndDate).source);
  91. html.push(' <tr>');
  92. html.push(' <td class="calendarview-monthtitle-left">' + getConner() + '</td>');
  93. for (var i = 0; i < calendarView.Months.length; i++) {
  94. var monthWeekCount = getWeeksOfMonth(calendarView.Months[i].Month);
  95. if (i == (calendarView.Months.length - 1) && endDate.getMonth() > (calendarView.Months[i].Month - 1)) monthWeekCount++;
  96. html.push(' <td class="calendarview-monthtitle" colspan="' + monthWeekCount + '">');
  97. html.push(' '.concat(calendarView.Months[i].ChineseName, '</td>'));
  98. }
  99. html.push(' </tr>');
  100. return html.join("\n");
  101. }
  102. function getWeekTitleRow() {
  103. var html = new Array();
  104. html.push(' <tr>');
  105. html.push(' <td class="calendarview-weektitle-left">周次</td>');
  106. for (var i = 0; i < totalWeeks; i++) {
  107. html.push(' <td class="calendarview-weektitle">');
  108. if (i >= emptyWeeks && i < (emptyWeeks + calendarView.SchoolYear.WeeksNum)) {
  109. html.push(calendarView.WeekNums[i - emptyWeeks].ChineseName);
  110. } else {
  111. html.push('&nbsp;');
  112. }
  113. html.push('</td>');
  114. }
  115. html.push(' </tr>');
  116. return html.join("\n");
  117. }
  118. function getDayRows() {
  119. var html = new Array();
  120. var startDate = eval('new ' + eval(calendarView.StartDate).source);
  121. var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
  122. for (var i = 0; i < 7; i++) {
  123. html.push(' <tr>');
  124. html.push(' <td class="calendarview-days-left">' + calendarView.WeekDays[i].ChineseName + '</td>');
  125. var rowStartDate = startDate.addDay(i);
  126. for (var j = 0; j < totalWeeks; j++) {
  127. var curDate = rowStartDate.addDay(j * 7);
  128. html.push(' <td class="calendarview-days');
  129. if (curDate < firstWeek ||
  130. curDate > firstWeek.addDay(calendarView.SchoolYear.WeeksNum * 7)) {
  131. html.push(' calendar-emptyday');
  132. }
  133. html.push('">');
  134. html.push(curDate.getDate());
  135. if ($.grep(calendarView.Holidays, function (val, index) { return eval('new ' + eval(val).source).valueOf() == curDate.valueOf(); }).length > 0) {
  136. html.push('★');
  137. }
  138. html.push('</td>');
  139. }
  140. html.push(' </tr>');
  141. }
  142. return html.join("\n");
  143. }
  144. function getTop(tdobj) {
  145. vParent = tdobj.offsetParent;
  146. t = tdobj.offsetTop;
  147. while (vParent.tagName.toUpperCase() != "BODY") {
  148. t += vParent.offsetTop;
  149. vParent = vParent.offsetParent;
  150. }
  151. return t;
  152. }
  153. function getLeft(tdobj) {
  154. vParent = tdobj.offsetParent;
  155. t = tdobj.offsetLeft;
  156. while (vParent.tagName.toUpperCase() != "BODY") {
  157. t += vParent.offsetLeft;
  158. vParent = vParent.offsetParent;
  159. }
  160. return t;
  161. }
  162. function line(startX, startY, endX, endY, container) {
  163. if (startX == endX) {
  164. if (startY > endY) {
  165. var tempY = startY;
  166. startY = endY;
  167. endY = tempY;
  168. }
  169. for (var k = startY; k < endY; k++) {
  170. createPoint(container, startX, k);
  171. }
  172. }
  173. // y = ax + b
  174. var a = (startY - endY) / (startX - endX);
  175. var b = startY - ((startY - endY) / (startX - endX)) * startX;
  176. if (Math.abs(startX - endX) > Math.abs(startY - endY)) {
  177. if (startX > endX) {
  178. var tempX = endX;
  179. endX = startX;
  180. startX = tempX;
  181. }
  182. var left = $(container).offset().left;
  183. var top = $(container).offset().top;
  184. for (var i = startX; i <= endX; i++) {
  185. createPoint(container, i, a * i + b);
  186. }
  187. } else {
  188. if (startY > endY) {
  189. var tempY = startY;
  190. startY = endY;
  191. endY = tempY;
  192. }
  193. for (var j = startY; j <= endY; j++) {
  194. createPoint(container, (j - b) / a, j);
  195. }
  196. }
  197. }
  198. function createPoint(container, x, y) {
  199. var node = document.createElement('div');
  200. node.className = 'line';
  201. container.appendChild(node);
  202. $(node).offset({
  203. left: x,
  204. top: y
  205. });
  206. }
  207. //line(1,1,100,100,"000000");
  208. function drawSplashLine(container) {
  209. line(getLeft(container), getTop(container), getLeft(container) + container.offsetWidth,
  210. getTop(container) + container.offsetHeight, container);
  211. }