osem-fcy/app/views/conference/_schedule.html.erb

88 lines
3.2 KiB
Text

<div id="schedule-content">
<h1 class="text-center"> Schedule for <%= @conference.title %></h1>
<ul class="nav nav-tabs">
<% @dates.each do |date| %>
<li <%= "class=active" if @dates.first == date %>>
<%= link_to date, "#" + "#{date}", "data-toggle" => "tab" %>
</li>
<% end %>
</ul>
<div class="tab-content">
<% @dates.each do |date| %>
<div class="tab-pane <%= 'active' if @dates.first == date %>" id ="<%= date %>" >
<table class="table table-bordered" id="schedule" width="100%">
<tr>
<th>Time</th>
<% @rooms.each do |room| %>
<th><%= room.name %></th>
<% end %>
</tr>
<% span = {} %>
<% @rooms.each do |room| %>
<% span[room.id] = 1 %>
<% end %>
<% conf_start = DateTime.parse("#{date} 09:00") %>
<% conf_end = DateTime.parse("#{date} 19:00") %>
<% while conf_start < conf_end %>
<%-
start_hour = conf_start.hour
start_min = conf_start.min %>
<tr>
<td style="width:5%">
<%= conf_start.strftime("%H:%M") %>
</td>
<% @rooms.each do |room| %>
<% events_for_date = @events.find_all {|e| e.room_id == room.id && e.start_time && e.start_time.to_date == date } %>
<% event = events_for_date.find_all{|e| e.start_time.hour == start_hour && e.start_time.min == start_min } %>
<% if !event.empty? %>
<!-- There is an event, calculate the span and show it -->
<% span[room.id] = event[0].event_type.length / 15 %>
<%= render partial: 'schedule_item', locals: {event: event, room: room, span: span} %>
<% span[room.id] = span[room.id] + 1 %>
<% elsif span[room.id] > 1 %>
<!-- span is <%= span[room.id] %> and bigger than 1, substract 1 from span -->
<% span[room.id] = ( span[room.id] - 1 ) if span[room.id] > 1 %>
<% end %>
<% if span[room.id] == 1 %>
<!-- span equals 1 show an empty td -->
<td style="width: <%= 95 / @rooms.length %>%">
</td>
<% end %>
<%end %>
</tr>
<% conf_start += 15.minutes %>
<%end %>
</table>
</div>
<% end %>
</div>
</div>
<%= javascript_tag do %>
$(function() {
// add a hash to the URL when the user clicks on a tab
$('a[data-toggle="tab"]').on('click', function(e) {
history.pushState(null, null, $(this).attr('href'));
});
// navigate to a tab when the history changes
window.addEventListener("popstate", function(e) {
var activeTab = $('[href=' + location.hash + ']');
if (activeTab.length) {
activeTab.tab('show');
} else {
$('.nav-tabs a[href=#<%= j @today %>]').tab('show');
}
});
});
$(function() {
var hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
});
<% end %>