You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
8.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /*
  16. * This is an internal helper class for the calendar views and should not be overridden.
  17. * It is responsible for the base event rendering logic underlying all of the calendar views.
  18. */
  19. Ext.calendar.WeekEventRenderer = function() {
  20. var getEventRow = function(id, week, index) {
  21. var indexOffset = 1,
  22. //skip row with date #'s
  23. evtRow,
  24. wkRow = Ext.get(id + '-wk-' + week);
  25. if (wkRow) {
  26. var table = wkRow.child('.ext-cal-evt-tbl', true);
  27. evtRow = table.tBodies[0].childNodes[index + indexOffset];
  28. if (!evtRow) {
  29. evtRow = Ext.DomHelper.append(table.tBodies[0], '<tr></tr>');
  30. }
  31. }
  32. return Ext.get(evtRow);
  33. };
  34. return {
  35. render: function(o) {
  36. var w = 0,
  37. grid = o.eventGrid,
  38. dt = o.viewStart.clone(),
  39. eventTpl = o.tpl,
  40. max = o.maxEventsPerDay != undefined ? o.maxEventsPerDay: 999,
  41. weekCount = o.weekCount < 1 ? 6: o.weekCount,
  42. dayCount = o.weekCount == 1 ? o.dayCount: 7,
  43. cellCfg;
  44. for (; w < weekCount; w++) {
  45. if (!grid[w] || grid[w].length == 0) {
  46. // no events or span cells for the entire week
  47. if (weekCount == 1) {
  48. row = getEventRow(o.id, w, 0);
  49. cellCfg = {
  50. tag: 'td',
  51. cls: 'ext-cal-ev',
  52. id: o.id + '-empty-0-day-' + dt.format('Ymd'),
  53. html: '&nbsp;'
  54. };
  55. if (dayCount > 1) {
  56. cellCfg.colspan = dayCount;
  57. }
  58. Ext.DomHelper.append(row, cellCfg);
  59. }
  60. dt = dt.add(Date.DAY, 7);
  61. } else {
  62. var row,
  63. d = 0,
  64. wk = grid[w],
  65. startOfWeek = dt.clone(),
  66. endOfWeek = startOfWeek.add(Date.DAY, dayCount).add(Date.MILLI, -1);
  67. for (; d < dayCount; d++) {
  68. if (wk[d]) {
  69. var ev = emptyCells = skipped = 0,
  70. day = wk[d],
  71. ct = day.length,
  72. evt;
  73. for (; ev < ct; ev++) {
  74. if (!day[ev]) {
  75. emptyCells++;
  76. continue;
  77. }
  78. if (emptyCells > 0 && ev - emptyCells < max) {
  79. row = getEventRow(o.id, w, ev - emptyCells);
  80. cellCfg = {
  81. tag: 'td',
  82. cls: 'ext-cal-ev',
  83. id: o.id + '-empty-' + ct + '-day-' + dt.format('Ymd')
  84. };
  85. if (emptyCells > 1 && max - ev > emptyCells) {
  86. cellCfg.rowspan = Math.min(emptyCells, max - ev);
  87. }
  88. Ext.DomHelper.append(row, cellCfg);
  89. emptyCells = 0;
  90. }
  91. if (ev >= max) {
  92. skipped++;
  93. continue;
  94. }
  95. evt = day[ev];
  96. if (!evt.isSpan || evt.isSpanStart) {
  97. //skip non-starting span cells
  98. var item = evt.data || evt.event.data;
  99. item._weekIndex = w;
  100. item._renderAsAllDay = item[Ext.calendar.EventMappings.IsAllDay.name] || evt.isSpanStart;
  101. item.spanLeft = item[Ext.calendar.EventMappings.StartDate.name].getTime() < startOfWeek.getTime();
  102. item.spanRight = item[Ext.calendar.EventMappings.EndDate.name].getTime() > endOfWeek.getTime();
  103. item.spanCls = (item.spanLeft ? (item.spanRight ? 'ext-cal-ev-spanboth':
  104. 'ext-cal-ev-spanleft') : (item.spanRight ? 'ext-cal-ev-spanright': ''));
  105. row = getEventRow(o.id, w, ev);
  106. cellCfg = {
  107. tag: 'td',
  108. cls: 'ext-cal-ev',
  109. cn: eventTpl.apply(o.templateDataFn(item))
  110. };
  111. var diff = Ext.calendar.Date.diffDays(dt, item[Ext.calendar.EventMappings.EndDate.name]) + 1,
  112. cspan = Math.min(diff, dayCount - d);
  113. if (cspan > 1) {
  114. cellCfg.colspan = cspan;
  115. }
  116. Ext.DomHelper.append(row, cellCfg);
  117. }
  118. }
  119. if (ev > max) {
  120. row = getEventRow(o.id, w, max);
  121. Ext.DomHelper.append(row, {
  122. tag: 'td',
  123. cls: 'ext-cal-ev-more',
  124. id: 'ext-cal-ev-more-' + dt.format('Ymd'),
  125. cn: {
  126. tag: 'a',
  127. html: '+' + skipped + ' more...'
  128. }
  129. });
  130. }
  131. if (ct < o.evtMaxCount[w]) {
  132. row = getEventRow(o.id, w, ct);
  133. if (row) {
  134. cellCfg = {
  135. tag: 'td',
  136. cls: 'ext-cal-ev',
  137. id: o.id + '-empty-' + (ct + 1) + '-day-' + dt.format('Ymd')
  138. };
  139. var rowspan = o.evtMaxCount[w] - ct;
  140. if (rowspan > 1) {
  141. cellCfg.rowspan = rowspan;
  142. }
  143. Ext.DomHelper.append(row, cellCfg);
  144. }
  145. }
  146. } else {
  147. row = getEventRow(o.id, w, 0);
  148. if (row) {
  149. cellCfg = {
  150. tag: 'td',
  151. cls: 'ext-cal-ev',
  152. id: o.id + '-empty-day-' + dt.format('Ymd')
  153. };
  154. if (o.evtMaxCount[w] > 1) {
  155. cellCfg.rowSpan = o.evtMaxCount[w];
  156. }
  157. Ext.DomHelper.append(row, cellCfg);
  158. }
  159. }
  160. dt = dt.add(Date.DAY, 1);
  161. }
  162. }
  163. }
  164. }
  165. };
  166. }();