Make it possible to select favourites events

Make it possible for users to select events which they want to see in the public schedule and in the All events section of the public schedule.
This commit is contained in:
Ana 2016-08-12 00:41:02 +02:00 committed by Ana María Martínez Gómez
parent 7f7375b7db
commit 9154f1883d
5 changed files with 74 additions and 10 deletions

View file

@ -1,3 +1,5 @@
// ADMIN SCHEDULE
var url; // Should be initialize in Schedule.initialize
var schedule_id; // Should be initialize in Schedule.initialize
@ -117,6 +119,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)

View file

@ -263,6 +263,15 @@ td.no-padding{
font-size: 7px;
}
#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{

View file

@ -63,6 +63,8 @@ class ProposalsController < ApplicationController
end
def update
respond_to do |format|
format.html do
@url = conference_program_proposal_path(@conference.short_title, params[:id])
if @event.update(event_params)
@ -73,6 +75,18 @@ class ProposalsController < ApplicationController
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
def withdraw
authorize! :update, @event

View file

@ -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

View file

@ -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,6 +9,13 @@
= 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 }
- if speaker = event.speakers.first
= image_tag speaker.gravatar_url, :class => "img-circle pull-right speaker-pic", |
:alt => speaker.name, |