osbridge/openconferenceware

View on GitHub
app/views/open_conference_ware/proposals/_list.html.erb

Summary

Maintainability
Test Coverage
<%
# Display a detailed list of Proposal records.
#
# Variables:
# * records => Array of Proposal records to display. REQUIRED.
# * kind => Treat these records as :sessions or :proposals. REQUIRED.
# * sorter => Display the sort toolbar? Defaults to false.

records = OpenConferenceWare::Proposal.sort(records, params[:sort] || "title", params[:dir] != "desc", current_user && current_user.id)
%>

<% if proposal_excerpts? %>
  <% if sorter %>
    <div>
      <% sort_links = [sort_link_for("Title", 'title', kind)]
         sort_links << sort_link_for("Track", 'track', kind) if event_tracks?
         sort_links << sort_link_for("Submission date", 'submitted_at', kind) if kind == :proposals
         sort_links << sort_link_for("Scheduled time", 'start_time', kind) if schedule_visible? && kind == :sessions
         sort_links << sort_link_for("Status", 'status', kind) if proposal_statuses? && admin?
         sort_links << sort_link_for("Random for content selection", 'random', kind) if selector?
      %>
      Sort by:
      <%= sort_links.join(', ').html_safe %>
    </div>
  <% end %>

  <% if records.blank? %>
    <h4>&mdash; No <%= kind %> submitted yet &mdash;</h4>
  <% else %>
    <table class='proposals kind_<%= kind %>' cellspacing='0'>
      <% previous_start_time = false %>
      <% for record in records %>
        <%
        # Use prefetched values
        track = record.respond_to?(:track_id) ? (@tracks_hash.try(:fetch, record.track_id, nil) || record.track) : nil
        %>
        <% if schedule_visible? && kind == :sessions && params[:sort]=='start_time' && (record.start_time != previous_start_time) %>
          <tr>
            <td colspan='3' class='schedule_header'>
              <%= record.start_time.nil? ? 'Unscheduled' : record.start_time.strftime("%A, %B %d - %I:%M %p") %>
            </td>
          </tr>
        <% end %>
        <% previous_start_time = record.start_time %>
        <% voted = selector? && @event.accept_selector_votes? && record.selector_votes.where(user_id: current_user.id).count > 0 %>
      <tr class='proposal_row<%= " voted" if voted %>' id='proposal_row_<%= record.id %>'>
        <td rowspan='2' class='description'>
          <h3>
            <%= user_favorite_control_for record %>
            <% if multiple_presenters? %>
              <%= link_to(h(record.title), record_path(record, kind), :class => "title") %>
            <% else %>
              <%= link_to(h(record.presenter)+" &mdash; "+h(record.title), record_path(record, kind), :class => "title") %>
            <% end %>
            <% if kind == :proposals && voted %>
              <span class='vote-status'>(Voted)</span>
            <% end %>
            <% if kind == :proposals && proposal_statuses? && (admin? || (@event.proposal_status_published? && record.confirmed?)) %>
              <span class='proposal-status <%= record.status %>'>(<%= record.status.titleize %>)</span>
            <% end %>
          </h3>

          <div class="excerpt">
            <%= h record.excerpt if proposal_excerpts? %>
          </div>
        </td>

        <% if event_tracks? %>
        <td class='track block <%= track_css_class(track) if track %>'>
          <%= track.present? ? link_to(h(track.title), event_track_path(@event, track)) : "- N/A -" %>
        </td>
        <% end %>

        <% if kind == :proposals %>
          <td class='date'>
            <%= record.submitted_at.localtime.to_s if record.submitted_at.present? %>
          </td>
        <% end %>
      </tr>
      <tr>
        <td class="speakers" colspan='<%= event_tracks? ? 2 : 1 %>'>
          <% if multiple_presenters? %>
            <% users = record.respond_to?(:users) ? (@users_for_proposal_hash.try(:fetch, record.id, nil) || record.users) : [] %>
          <% end %>
          <% unless users.empty? %>
            <%= users.map{|user| link_to(h(user.fullname), user_path(user))}.join(', ').html_safe %>
          <% end %>
        </td>
      </tr>
      <% end %>
    </table>
  <% end %>
<% else %>
  <table id="proposal-listing">
    <% if records.blank? %>
      <tr>
        <td colspan="2">
          <p class="empty-text">&mdash; No <%= kind %> submitted yet &mdash;</p>
        </td>
      </td>
    <% else %>
      <thead>
        <tr>
          <th width="100%">
            <% if multiple_presenters? %>
              Title
            <% else %>
              Speaker and title
            <% end %>
          </th>
<% if event_tracks? %>
          <th>
            Track
          </th>
<% end %>
<% if kind == :proposals %>
          <th width="0">Submitted</th>
<% end %>
        </tr>
      </thead>
      <% date_cache = {} %>
      <% for record in records %>
        <tr class="<%= cycle("even", "odd") %>" valign="top">
          <td width="100%">
            <p class="proposal">
              <% styling = proposal_excerpts? ? 'display: inline-block' : 'inline' %>
              <% if multiple_presenters? %>
                <%= link_to(record.title, record, :class => "title", :style => styling) %>
              <% else %>
                <%= link_to("#{record.presenter} &mdash; #{record.title}".html_safe, record, :class => "title", :style => styling) %>
              <% end %>

              <span class="excerpt">
                <%= h record.excerpt if proposal_excerpts? %>
              </span>

              <p class="speakers">
                <% if multiple_presenters? %>
                  <%= record.users.map{|user| link_to(h(user.fullname), user_path(user), :style => "display: inline")}.join(', ') %>
                <% end %>
              </p>
            </p>
          </td>
<% if event_tracks? %>
          <td>
            <p>
              <%= track.try(:title) || "- N/A -" %>
            </p>
          </td>
<% end %>
          <td width="0" class="unbreakable">
            <p>
              <% date = record.submitted_at.localtime.strftime("%m/%d/%Y") if record.submitted_at.present? %>
              <% if date_cache[date] %>
                <!--
                <span class="date-seen"><%= date %></span>
                -->
              <% else %>
                <% date_cache[date] = true %>
                <span class="date-unseen"><%= date %></span>
              <% end %>
            </p>
          </td>
        </tr>
      <% end %>
    <% end %>
  </table>
<% end %>