Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. <div id="cal-day-box">
  2. <% if(all_day.length) {%>
  3. <div class="row-fluid clearfix cal-day-hour">
  4. <div class="span1 col-xs-1"><b><%= cal.locale.all_day %></b></div>
  5. <div class="span11 col-xs-11">
  6. <% _.each(all_day, function(event){ %>
  7. <div class="day-highlight dh-<%= event['class'] %>">
  8. <a href="<%= event.url ? event.url : 'javascript:void(0)' %>" data-event-id="<%= event.id %>"
  9. data-event-class="<%= event['class'] %>" class="event-item">
  10. <%= event.title %></a>
  11. </div>
  12. <% }); %>
  13. </div>
  14. </div>
  15. <% }; %>
  16. <% if(before_time.length) {%>
  17. <div class="row-fluid clearfix cal-day-hour">
  18. <div class="span1 col-xs-3"><b><%= cal.locale.before_time %></b></div>
  19. <div class="span5 col-xs-5">
  20. <% _.each(before_time, function(event){ %>
  21. <div class="day-highlight dh-<%= event['class'] %>">
  22. <span class="cal-hours pull-right"><%= event.end_hour %></span>
  23. <a href="<%= event.url ? event.url : 'javascript:void(0)' %>" data-event-id="<%= event.id %>"
  24. data-event-class="<%= event['class'] %>" class="event-item">
  25. <%= event.title %></a>
  26. </div>
  27. <% }); %>
  28. </div>
  29. </div>
  30. <% }; %>
  31.  
  32. <div id="cal-day-panel-hour">
  33. <% for(i = 0; i < hours; i++){ %>
  34. <div class="cal-day-hour">
  35. <% for(l = 0; l < cal._hour_min(i); l++){ %>
  36. <div class="row-fluid cal-day-hour-part">
  37. <div class="col-xs-1"><b><%= cal._hour(i, l) %></b></div>
  38. <div class="col-xs-11"></div>
  39. </div>
  40. <% }; %>
  41. </div>
  42. <% }; %>
  43. </div>
  44. <div id="cal-day-panel" class="clearfix">
  45. <%
  46. var events = [];
  47. var cal_times = hours*60;
  48. var eventsLength = by_hour.length;
  49. var timeslots = [];
  50. var event, i, j;
  51.  
  52. // Step 0: Sort events by id.
  53. events = by_hour.sort(function(a, b){return a.id - b.id;});
  54. // console.log(events);
  55.  
  56. // Step 1: Initialize timeslots.
  57. for (i=0; i<cal_times; i++) {
  58. timeslots[i] = [];
  59. }
  60.  
  61. // Step 2: Arrange the events by timeslot.
  62. for (i = 0; i < eventsLength; i++) {
  63. event = events[i];
  64.  
  65. // Safety first.
  66. var evt_start = event.top * 30;
  67. var evt_end = (event.top + event.lines) * 30;
  68. // console.log("START "+evt_start);
  69. // console.log("END "+evt_end);
  70. if (evt_start > evt_end) {
  71. var temp = evt_start;
  72. evt_start = evt_end;
  73. evt_end = temp;
  74. }
  75.  
  76. for (j=evt_start; j<evt_end; j++) {
  77. timeslots[j].push(i+1);
  78. }
  79. }
  80. // console.log(timeslots);
  81. // Step 3: Get each event it's horizontal position,
  82. // and figure out the max number of conflicts it has.
  83. for (i=0; i<cal_times; i++) {
  84. var next_hindex = 0;
  85. var timeslotLength = timeslots[i].length;
  86.  
  87.  
  88. // If there's at least one event in the timeslot,
  89. // we know how many events we will have going across for that slot.
  90. if (timeslotLength > 0) {
  91. // Store the greatest concurrent event count (cevc) for each event.
  92. for (j=0; j<timeslotLength; j++) {
  93. event = events[timeslots[i][j]-1];
  94.  
  95. if (!event.cevc || event.cevc < timeslotLength) {
  96. event.cevc = timeslotLength;
  97.  
  98. // Now is also a good time to coordinate horizontal ordering.
  99. // If this is our first conflict, start at the current index.
  100.  
  101. if(events.indexOf(timeslots[i][j]-2) == -1){
  102. event.hindex = next_hindex;
  103.  
  104. } else {
  105. var temp = events[timeslots[i][j]-2].hindex;
  106. event.hindex = temp++;
  107. next_hindex = events[timeslots[i][j]-2].hindex;
  108. }
  109.  
  110. // We also want to boost the index,
  111. // so that whoever we conflict with doesn't get the same one.
  112. next_hindex++;
  113.  
  114. }
  115. }
  116. }
  117. }
  118.  
  119. _.each(events, function(event){
  120.  
  121.  
  122. // Height and y-coordinate are already known.
  123. event.pxh = event.lines * 30;
  124. event.pxy = event.top * 30;
  125.  
  126. // Width is based on calendar width and the cevc.
  127. event.pxw = 100 / event.cevc;
  128.  
  129. // Height uses the same calendar/cevc figure,
  130. // multiplied by the horizontal index to prevent overlap.
  131. event.pxx = event.hindex * event.pxw;
  132. // console.log(event);
  133. %>
  134. <div ondblclick="edit_event(<%= event.id %>)"class="event-click day-event day-highlight dh-<%= event['class'] %>" style="top: <%= event.pxy %>px; left: <%= event.pxx %>%; height: <%= event.pxh %>px; width: <%= (event.pxw) %>%; "
  135. <span class="cal-hours"><b><%= event.start_hour %> - <%= event.end_hour %></b></span>
  136. <%= event.title %>
  137. </div>
  138. <% }); %>
  139. </div>
  140. <% if(after_time.length) {%>
  141. <div class="row-fluid clearfix cal-day-hour">
  142. <div class="span1 col-xs-3"><b><%= cal.locale.after_time %></b></div>
  143. <div class="span11 col-xs-9">
  144. <% _.each(after_time, function(event){ %>
  145. <div class="day-highlight dh-<%= event['class'] %>">
  146. <span class="cal-hours"><%= event.start_hour %></span>
  147. <a href="<%= event.url ? event.url : 'javascript:void(0)' %>" data-event-id="<%= event.id %>"
  148. data-event-class="<%= event['class'] %>" class="event-item">
  149. <%= event.title %></a>
  150. </div>
  151. <% }); %>
  152. </div>
  153. </div>
  154. <% }; %>
  155. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement