openSUSE/osem

View on GitHub
app/views/admin/events/_voting.html.haml

Summary

Maintainability
Test Coverage
%table.table#myrating
  - if show_votes
    %tr
      %td.col-md-2
        %b Rating
      %td
        #{event.average_rating}/#{max_rating}
        = rating_stars(event.average_rating, max_rating, avgrate: true )
    %tr
      %td
        %b Voters
      %td
        = votes.length
        - unless votes.blank?
          (
          = votes.collect(&:name).to_sentence
          )
  %tr
    %td.col-md-2
      %b Your vote
    %td
      - if voting_period
        - max_rating.times do |counter|
          - if event.user_rating(current_user) > counter
            = link_to '',
              vote_admin_conference_program_event_path(conference_id,
                event, rating: counter + 1),
              remote: true,
              id:     "label#{counter + 1}",
              class:  'rating myrating bright',
              voted:  true
          - else
            = link_to '',
              vote_admin_conference_program_event_path(conference_id,
                event, rating: counter + 1),
              remote: true,
              id:     "label#{counter + 1}",
              class:  'rating myrating'
      - else
        = rating_stars(event.user_rating(current_user), max_rating, voted: true)
        (Voting period is closed)

  - if show_votes
    - unless votes.blank?
      - votes.each do |vote|
        - unless vote.user_id == current_user.id
          %tr
            %td
              = vote.name
            %td
              = rating_stars(vote.rating, max_rating )

:javascript
  $(".myrating").hover(
    function() {    // mouseover
        $(this).prevAll().andSelf().addClass('glow');
    },
    function() {  // mouseout
        $(this).siblings().andSelf().removeClass('glow');
    }
  );

  $(".myrating").click(function() {
    $(this).siblings().removeClass("bright");
    $(this).prevAll().andSelf().addClass("bright");
  });