YaleSTC/shifts

View on GitHub
app/views/calendars/index.html.erb

Summary

Maintainability
Test Coverage
<% if @calendar %>
  <% title @calendar.name + (@calendar.active? ? " (active)" : " (inactive)") %>
  <% subtitle "("+@calendar.start_date.strftime("%b %d, %Y")+" - "+(@calendar.default? ? "forever" : @calendar.end_date.strftime("%b %d, %Y") )+")"%>

  <% if current_user.is_admin_of?(@department) %>
    <p>
      <% unless @calendar.default? %>
        <%= link_to "Edit", edit_calendar_path(@calendar) %> |
        <%= link_to "Destroy", @calendar, confirm: 'Are you sure?', method: :delete %> |
      <% else %>
        <p>This is the default calendar, and cannot be edited or deleted.</p>
      <% end %>
      <%= link_to "View All Calendars", calendars_path %>
    </p>
  <% end %>
<% else %>
  <% title "Calendars" %>
<% end %>


<div id="AJAX_status"></div><%# to display status messages in top right corner %>
<%= render partial: 'shifts/view_preferences' %>

<table class = "tablesorter">
 <thead>
  <tr>
    <th>Name</th>
    <% unless mobile_device?%>
    <th>Start Date</th>
    <th>End Date</th>
    <th>Public</th>
    <th>Active</th>
    <% end %>
  </tr>
 </thead>
 <%= javascript_tag "var calendar_visible = new Array()" %>
  <% for calendar in @calendars %>
 <tbody>
  <%= (!calendar.active? and @calendar.nil?) ? "<tr class='disabled'>".html_safe : "<tr>".html_safe %>
      <td style="background: #<%= @color[calendar] %>"><%= link_to calendar.name, calendar %></td>
      <% unless mobile_device?%>
      <td><%= calendar.start_date.strftime("%b %d, %Y") %></td>
      <td><%= calendar.default? ? "never" : calendar.end_date.strftime("%b %d, %Y") %></td>
      <td><%= calendar.public %></td>
      <td><%= calendar.active %></td>
      <td><%= link_to_function "Toggle view", "$('.calendar#{calendar.id}').toggle(); $(this).parent().parent().toggleClass('disabled'); calendar_visible[#{calendar.id}] = !calendar_visible[#{calendar.id}]"%></td>
      <% unless calendar.default? or !current_user.is_admin_of?(@department) %>
        <td><%= button_to calendar.active ? "Deactivate" : "Activate" , toggle_calendar_path(calendar) %></td>
        <td><%= button_to "Convert Shifts to Weekly Events", {action: 'apply_schedule', id: calendar.id}, confirm: "Are you sure? This will convert all shifts on this calendar to weekly repeating events that span the dates of the calendar." %></td>
        <td><%= link_to "Copy", prepare_copy_calendar_path(calendar) %></td>
        <td><%= link_to "Destroy", calendar, confirm: 'Are you sure?', method: :delete %></td>
      <% end %>
    <% end %>
    </tr>
  </tbody>
  <%= javascript_tag do %>
    calendar_visible[<%=calendar.id%>] = <%= (@calendar ? calendar == @calendar : calendar.active?) %>;
  <% end %>
  <% end %>
</table>

<% if current_user.is_admin_of?(@department) %>
  <p><%= link_to "New Calendar", new_calendar_path %></p>
  <p><%= link_to "Wipe shifts and timeslots from a range of days", prepare_wipe_range_calendars_path %></p>

  <p id="new_time_slot_link"><%= link_to "New Time Slot", new_time_slot_path(date: params[:date]) %></p>

<% end %>

<div style="clear:both"></div>

<%= render partial: 'shifts/schedule/header' %>
<%= render partial: 'calendars/schedule/day', collection: @day_collection %>
<%= render partial: 'shifts/schedule/footer' %>

<%= javascript_tag do %>
  calendar = "<%= @calendar.nil? ? 'true' : @calendar.id %>";
  newTimeSlotPath = '<%= new_time_slot_path %>';
  newShiftPath = '<%= new_shift_path %>';
  timeSlotsPath = '<%= time_slots_path %>';
  shiftsPath = '<%= shifts_path %>';
<% end %>