YaleSTC/shifts

View on GitHub
app/views/stats/tooltips/_show.html.erb

Summary

Maintainability
Test Coverage
<div class="close_link">
  <a onclick="$(this).parent().parent().fadeOut(function (){ $(this).remove() }); return false;" href="#">[x]</a>
</div>

<% if (current_user.is_admin_of?(current_department) or ( current_user == @shift.user and @shift.calendar.public? and !@shift.calendar.active? )) and @shift.scheduled? %>
  <% if params[:delete_options] and @shift.repeating_event %>
    <div id="repeating_event_delete_options">
      <p>This shift is part of a repeating event.<br>What do you wish to destroy?</p>
      <%= button_to_remote "Just this shift", {url: {controller: 'shifts', action: 'destroy', id: @shift.id, calendar: params[:calendar]}, confirm: 'Are you sure?', method: :delete} %><br />
      <%= button_to_remote "This and all future shifts", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], delete_after_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %><br />
      <%= button_to_remote "All events in this series", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], rerender_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %>
    </div>
  <% else%>
    <% if @shift.report %>
      <%= render partial: 'reports/report', object: @shift.report, locals: {html_id: "shift_report_view"}%>
      <p>
        <% if @shift.signed_in? && (current_user == @shift.user || current_user.is_admin_of?(@shift.location)) %>
          <%= button_to "Submit shift report", {controller: 'reports', action: :update, id: @report, sign_out: true, method: :put}, confirm: 'Are you sure you wish to sign out of this shift?' %>
        <% end %>
        <% if !@shift.has_passed? and @shift.has_sub? and current_user != @shift.user %>
          <% @shift.sub_requests.each do |sub| %>
            <%= (button_to "Take sub", sub_request_path(sub), method: :get) if sub.user_is_eligible?(current_user) %>
          <% end %>
        <% elsif current_user == @shift.user %>
          <% unless @shift.has_passed? or @shift.submitted? %>
            <%= link_to "Request a sub for this shift", new_shift_sub_request_path(@shift) %>
          <% end %>
        <% end %>
      </p>

      <% if @shift.submitted? %>
        <% unless @shift.repeating_event %>
          <%= link_to "Destroy this shift", {url: {controller: 'shifts', action: 'destroy', id: @shift.id, calendar: params[:calendar]}, remote: true, confirm: 'Are you sure?', method: :delete} %>
        <% else %>
          <%= link_to_function "Destroy this shift", "$('#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_remote "Just this shift", {url: {controller: 'shifts', action: 'destroy', id: @shift.id, calendar: params[:calendar]}, confirm: 'Are you sure?', method: :delete} %><br />
            <%= button_to_remote "This and all future shifts", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], delete_after_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %><br />
            <%= button_to_remote "All events in this series", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], rerender_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %>
          </div>
        <% end %>
      <% end %>

    <% else %>
      <h2>Edit Shift</h2>

      <% if @shift.repeating_event %>
        <p>
          <%= check_box_tag :repeating_event, false, false, onclick: "$('.toggle_me').toggle()" %> Edit repeating event
        </p>
      <% end %>

      <div class="toggle_me">
        <%= form_for @shift, remote: true do |f| %>
          <p>
            <%= f.label :start %><br />
            <%= f.time_select :start, twelve_hour: true, minute_step: current_department.department_config.time_increment %>
          </p>
          <p>
            <%= f.label :end %><br />
            <%= f.time_select :end, twelve_hour: true, minute_step: current_department.department_config.time_increment %>
          </p>
          <p>
            <%= f.label :location %><br />
            <%= select_tag 'shift[location_id]', option_groups_from_collection_for_select(current_department.loc_groups, :locations, :name, :id, :name, @shift.location_id)%><br />
          </p>

          <% if current_user.is_admin_of?(@department) %>
            <p>
              <%= f.label :calendar %><br />
              <%= f.collection_select(:calendar_id, current_department.calendars, :id, :name) %>
            </p>
            <p>
              <%= f.label :user %><br />
              <%= f.collection_select(:user_id, current_department.active_users, :id, :name, {prompt: "Select a user"}) %>
            </p>
            <p>
              <%= f.check_box :power_signed_up %> Power signup
            </p>
          <% end %>
          <p><%= submit_to_remote "edit_button", "Save Changes", url: { controller: 'shifts', action: 'update', calendar: params[:calendar] } %></p>
        <% end %>

        <% if current_user == @shift.user and !@shift.has_passed? %>
          <%= button_to "Sign in", shift_report_path(@shift), method: :post, onclick: "if(ie){window.location.href='#{escape_javascript(shift_path(@shift))}'}" %>
        <% end %>
        <% if !@shift.has_passed? and !@shift.submitted? %>
          <% if @shift.has_sub? %>
            <%= link_to "Manage sub requests for this shift", shift_sub_requests_path(@shift) %><br>
            <% @shift.sub_requests.each do |sub| %>
              <%= (button_to "Take sub", sub_request_path(sub), method: :get) if sub.user_is_eligible?(current_user)  %>
            <% end %>
          <% else %>
            <%= link_to "Create a sub request for this shift", new_shift_sub_request_path(@shift) %><br>
          <% end %>
        <% end %>

        <% unless @shift.repeating_event %>
          <%= link_to "Destroy this shift", {url: {controller: 'shifts', action: 'destroy', id: @shift.id, calendar: params[:calendar]}, remote: true, confirm: 'Are you sure?', method: :delete} %>
        <% else %>
          <%= link_to_function "Destroy this shift", "$('#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_remote "Just this shift", {url: {controller: 'shifts', action: 'destroy', id: @shift.id, calendar: params[:calendar]}, confirm: 'Are you sure?', method: :delete} %><br />
            <%= button_to_remote "This and all future shifts", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], delete_after_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %><br />
            <%= button_to_remote "All events in this series", {url: {controller: 'repeating_events', action: 'destroy', id: @shift.repeating_event.id, calendar: params[:calendar], rerender_date: @shift.start}, confirm: 'Are you sure?', method: :delete} %>
          </div>
        <% end %>
      </div>
      <% if current_user.is_admin_of?(@department) and @shift.repeating_event %>
        <div class="toggle_me" style="display:none">
          <%= form_for (@repeating_event = @shift.repeating_event), remote: true do |f| %>
            <%= render partial: 'shifts/form_repeating', locals: {f: f} %>
            <%= hidden_field_tag 'rerender_date', @shift.start.to_date.to_s %>
            <p style="clear:both"><%= submit_to_remote "add_button", "Update Repeating Event", url: { controller: 'repeating_events', action: 'update', id: @repeating_event.id, calendar: params[:calendar] } %></p>
          <% end %>
        </div>
      <% end %>
    <% end %>
  <% end %>

<% else %>

  <% if @shift.report %>
    <%= render partial: 'reports/report', object: @shift.report,locals: {html_id: "shift_report_view"} %>
    <% if @shift.signed_in? && (current_user == @shift.user || current_user.is_admin_of?(@shift.location)) %>
      <%= button_to "Submit shift report", {controller: 'reports', action: :update, id: @report, sign_out: true, method: :put}, confirm: 'Are you sure you wish to sign out of this shift?' %>
    <% end %>
  <% else %>
    <h2><%= @shift.scheduled? ? "Shift" : "Unscheduled Shift" %></h2>
    <p>
      <strong>Start:</strong>
      <%= @shift.start.to_s(:short_name) %>
    </p>
    <p>
      <strong>End:</strong>
      <%= @shift.scheduled? ? @shift.end.to_s(:short_name) : "unscheduled" %>
    </p>
    <p>
      <strong>User:</strong>
      <%= @shift.user.name %>
    </p>
    <p>
      <strong>Location:</strong>
      <%= @shift.location.name %>
    </p>
  <% end %>

  <p>
    <% if current_user == @shift.user and !@shift.has_passed? and @shift.report.nil? %>
      <%= button_to "Sign in", shift_report_path(@shift), method: :post, onclick: "if(ie){window.location.href='#{escape_javascript(shift_path(@shift))}'}" %>
    <% end %>

    <% if !@shift.has_passed? and @shift.has_sub? and current_user != @shift.user %>
      <% @shift.sub_requests.each do |sub| %>
        <%= (button_to "Take sub", sub_request_path(sub), method: :get) if sub.user_is_eligible?(current_user)  %>
      <% end %>
    <% elsif current_user == @shift.user %>
      <% unless @shift.has_passed? or @shift.submitted? %>
        <%= link_to "Request a sub for this shift", new_shift_sub_request_path(@shift) %>
      <% end %>
    <% end %>
  </p>
<% end %>