diff --git a/app/assets/javascripts/osem-schedule.js b/app/assets/javascripts/osem-schedule.js index 5f1e7728..1582ba1b 100644 --- a/app/assets/javascripts/osem-schedule.js +++ b/app/assets/javascripts/osem-schedule.js @@ -1,3 +1,5 @@ +// ADMIN SCHEDULE + var url; // Should be initialize in Schedule.initialize var schedule_id; // Should be initialize in Schedule.initialize @@ -114,6 +116,34 @@ $(document).ready( function() { }); }); + +// PUBLIC SCHEDULE + +function starClicked(e){ + // stops the click from propagating + if (!e) var e = window.event; + e.preventDefault(); + e.cancelBubble = true; + if (e.stopPropagation) e.stopPropagation(); + + var callback = function(data) { + $(e.target).toggleClass('fa-star fa-star-o'); + } + + var params = { favourite_user_id: $(e.target).data('user') }; + if($(e.target).hasClass('fa-star-o')){ + params['add'] = true; + } + + $.ajax({ + url: $(e.target).data('url'), + type: 'PATCH', + data: params, + success: callback, + dataType : 'json' + }); +} + function eventClicked(e, element){ var url = $(element).data('url'); if(e.ctrlKey) diff --git a/app/assets/stylesheets/osem-schedule.scss b/app/assets/stylesheets/osem-schedule.scss index 1cf1efec..3c4bb4b2 100644 --- a/app/assets/stylesheets/osem-schedule.scss +++ b/app/assets/stylesheets/osem-schedule.scss @@ -254,6 +254,15 @@ td.no-padding{ opacity: 0.5; } +#star{ + margin-top: 8px; +} + +#star-events{ + margin-right: 5px; + vertical-align: text-top; +} + /* Small devices (tablets, 768px and up) */ @media (min-width: 768px) { .room, .event-title{ diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 54ca58c9..efdfa887 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -68,21 +68,35 @@ class ProposalsController < ApplicationController end def update - @url = conference_program_proposal_path(@conference.short_title, params[:id]) + respond_to do |format| + format.html do + @url = conference_program_proposal_path(@conference.short_title, params[:id]) - track = Track.find_by(id: params[:event][:track_id]) - if track && !track.cfp_active - flash.now[:error] = 'You have selected a track that doesn\'t accept proposals' - render action: 'edit' - return - end + track = Track.find_by(id: params[:event][:track_id]) + if track && !track.cfp_active + flash.now[:error] = 'You have selected a track that doesn\'t accept proposals' + render action: 'edit' + return + end - if @event.update(event_params) - redirect_to conference_program_proposals_path(conference_id: @conference.short_title), - notice: 'Proposal was successfully updated.' - else - flash.now[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}" - render action: 'edit' + if @event.update(event_params) + redirect_to conference_program_proposals_path(conference_id: @conference.short_title), + notice: 'Proposal was successfully updated.' + else + flash[:error] = "Could not update proposal: #{@event.errors.full_messages.join(', ')}" + render action: 'edit' + end + end + format.json do + user = User.find(params[:favourite_user_id]) + users = @event.favourite_users + if users.include? user + @event.favourite_users.delete(user) + else + @event.favourite_users << User.find(params[:favourite_user_id]) + end + render json: {} + end end end diff --git a/app/views/schedules/_event.html.haml b/app/views/schedules/_event.html.haml index 25f4e1a0..41eca5b8 100644 --- a/app/views/schedules/_event.html.haml +++ b/app/views/schedules/_event.html.haml @@ -4,11 +4,15 @@ = image_tag speaker.gravatar_url, :class => "img-circle pull-right all-speaker-pic", | :alt => speaker.name, | :title => speaker.name | - %p = canceled_replacement_event_label(event, event_schedule) = replacement_event_notice(event_schedule) - + - if current_user + = link_to('#', onClick: 'starClicked();') do + %span#star-events{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", | + "aria-hidden" => "true", | + "data-url" => conference_program_proposal_path(@conference.short_title, event.id), | + "data-user" => current_user.id } %span.h3 = event.title %br diff --git a/app/views/schedules/_schedule_item.html.haml b/app/views/schedules/_schedule_item.html.haml index b6d8708e..9e9d855f 100644 --- a/app/views/schedules/_schedule_item.html.haml +++ b/app/views/schedules/_schedule_item.html.haml @@ -1,7 +1,7 @@ %td.event{ width: "#{ width * span }%" , | colspan: span, | role: "button" } - %a.unstyled-link{href: url_for(conference_program_proposal_path(@conference.short_title, event.id))} + %div{ onClick: 'eventClicked(event, this);', "data-url" => "#{url_for(conference_program_proposal_path(@conference.short_title, event.id))}" } %div{ class: "elipsis break-words event-title", | style: "-webkit-line-clamp: #{ event_lines(@rooms) }; height: #{ event_height(@rooms) }px;"} | @@ -9,9 +9,15 @@ = event.title + - if current_user + = link_to('#', onClick: 'starClicked();') do + %span#star{ class: "fa fa-lg #{ event.favourite_users.exists?(current_user.id) ? 'fa-star' : 'fa-star-o' }", | + "aria-hidden" =>"true", | + "data-url" => conference_program_proposal_path(@conference.short_title, event.id), | + "data-user" => current_user.id } + - event.speakers_ordered.each do |speaker| = image_tag speaker.gravatar_url, :class => "img-circle pull-right speaker-pic", | :alt => speaker.name, | :title => speaker.name, | :style => "height: #{ speaker_height(@rooms) }px; width: #{ speaker_width(@rooms) }px;" -