.row
  .col-md-12
    .page-header
      %h1
        Events
        - if @events.any?
          = "(#{@events.length})"
      %p.text-muted
        All the submissions of your speakers
.row
  .col-md-12
    %table.table.table-striped.table-bordered.table-hover.datatable
      %thead
        %th
          %b ID
        %th
          %b Title
        - if @conference.call_for_paper && @conference.call_for_paper.rating && @conference.call_for_paper.rating > 0
          %th
            %b Rating
        %th
          %b Submitter
        %th
          %b Speaker
        %th
          %b Type
        %th
          %b Track
        %th
          %b Difficulty
        %th
          %b State
      - @events.each do |event|
        %tr
          %td
            = event.id
          %td
            =link_to event.title, admin_conference_event_path(@conference.short_title, event)

          - if @conference.call_for_paper && @conference.call_for_paper.rating && @conference.call_for_paper.rating > 0
            %td{:style => "width:96px"}
              - if event.average_rating.to_f > 0
                #{event.average_rating}/#{@conference.call_for_paper.rating}
                %br
                #{pluralize(event.voters.length, 'voter')}
                %br
                - @conference.call_for_paper.rating.times do |counter|
                  - if event.average_rating.to_f.round == counter+1
                    = label_tag "label_rating", "", :class => "avgrating", :avgrate => true
                    = javascript_tag "$('label[avgrate=true]').prevAll().andSelf().addClass('bright');"
                  - else
                    = label_tag "label_rating", "", :class => "avgrating"
              - else
                0/#{@conference.call_for_paper.rating}
              %br

          - if event.submitter && event.submitter.registrations && event.submitter.registrations.count < 1
            - bgcolor="#F7819F"
          - else
            - bgcolor=""
          %td{:style=>"background-color: #{bgcolor}"}
            - if !event.submitter.nil?
              =link_to event.submitter.name, admin_user_path(event.submitter)
              - if event.submitter.registrations.count < 1
                (Unregistered!)
            - else
              Unknown submitter
          %td
            - if speaker = event.speakers.first
              = link_to speaker.name, admin_user_path(speaker)
            - else
              Unknown speaker
            - l = link_to "Change", edit_admin_conference_event_speaker_path(@conference.short_title, event), :remote => true
            = "(#{l})".html_safe
          %td
            .btn-group
              %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"}
                - if event.event_type.nil?
                  Event Type
                - else
                  = event.event_type.title
                %span.caret
              %ul.dropdown-menu
                - @event_types.each do |type|
                  %li= link_to type.title, admin_conference_event_path(@conference.short_title, event, :event_type_id => type.id) ,
                    :method => :put, :event_type_id => type.id
          %td
            .btn-group
              %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"}
                - if event.track.nil?
                  Track
                - else
                  = event.track.name
                %span.caret
              %ul.dropdown-menu
                - @tracks.each do |track|
                  %li= link_to track.name, admin_conference_event_path(@conference.short_title, event, :track_id => track.id) ,
                    :method => :put, :track_id => track.id
          %td
            = event.difficulty_level.title if event.difficulty_level
          %td
            - if event.state == "withdrawn"
              Withdrawn
            - else
              .btn-group
                %button{:type=>"button", :class=>"btn btn-link dropdown-toggle", "data-toggle"=>"dropdown"}
                  = event.state.humanize
                  %span.caret
                %ul.dropdown-menu{:role=>"menu"}
                  = render 'change_state_dropdown', event: event
