YaleSTC/shifts

View on GitHub
app/views/time_slots/edit.html.erb

Summary

Maintainability
Test Coverage
<% title "Edit Time Slot for " + @time_slot.start.to_date.to_s(:just_date_long) %>

<% if current_user.is_admin_of?(@department) %>
  <% if params[:delete_options] and @time_slot.repeating_event %>
    <div id="repeating_event_delete_options">
      <p>This time slot is part of a repeating event.<br>What do you wish to destroy?</p>
          <%= button_to "Just this time slot",  {controller: 'time_slots', action: 'destroy', id: @time_slot.id, calendar: (params[:calendar] || true)}, data:{confirm: 'Are you sure?'}, method: :delete %><br />
          <%= button_to "This and all future time slots", {controller: 'repeating_events', action: 'destroy', id: @time_slot.repeating_event.id, calendar: (params[:calendar] || true), delete_after_date: @time_slot.start}, data:{confirm: 'Are you sure?'}, method: :delete %><br />
          <%= button_to "All events in this series", {controller: 'repeating_events', action: 'destroy', id: @time_slot.repeating_event.id, calendar: (params[:calendar] || true), rerender_date: @time_slot.start}, data:{confirm: 'Are you sure?'}, method: :delete %>
    </div>
  <% else %>
    <h2>Edit Timeslot</h2>
    <%= form_for @time_slot do |f| %>
      <%= render partial: 'time_slots/form', locals: {f: f}  %>
      <p><%= submit_tag "Save Changes", url: { controller: 'time_slots', action: 'update', calendar: (params[:calendar] || true) } %></p>
    <% end %>
    <p>
      <% unless @time_slot.repeating_event %>
        <%= link_to "Destroy this time slot", time_slot_path(@time_slot, calendar: (params[:calendar] || true)), data:{confirm: 'Are you sure?'}, method: :delete %>
      <% else %>
        <%= link_to_function "Destroy this time slot", "$('#repeating_event_delete_options').toggle()" %>
        <div id="repeating_event_delete_options" style="display:none">
          <p>This shift is part of a repeating event.<br>What do you wish to destroy?</p>
          <%= button_to "Just this time slot",  {controller: 'time_slots', action: 'destroy', id: @time_slot.id, calendar: (params[:calendar] || true)}, data:{confirm: 'Are you sure?'}, method: :delete %><br />
          <%= button_to "This and all future time slots", {controller: 'repeating_events', action: 'destroy', id: @time_slot.repeating_event.id, calendar: (params[:calendar] || true), delete_after_date: @time_slot.start}, data:{confirm: 'Are you sure?'}, method: :delete %><br />
          <%= button_to "All events in this series", {controller: 'repeating_events', action: 'destroy', id: @time_slot.repeating_event.id, calendar: (params[:calendar] || true), rerender_date: @time_slot.start}, data:{confirm: 'Are you sure?'}, method: :delete %>
        </div>
      <% end %>
    </p>
  <% end %>
<% else %>
  <h2>Timeslot</h2>
  <p>
    <%= f.label :start %>: <%= @time_slot.start.to_s(:short_name) %>
  </p>
  <p>
    <%= f.label :end %>: <%= @time_slot.end.to_s(:short_name) %>
  </p>
  <p>
    <%= f.label :location %>: <%= @time_slot.location.name %>
  </p>
<% end %>

<p>
  <%= link_to "Show", @time_slot %> |
  <%= link_to "View All", time_slots_path %>
</p>