class EventsController

Public Instance Methods

accept() click to toggle source

To accept the event and build confirmation for the event with accept

# File app/controllers/events_controller.rb, line 82
def accept
  @confirmation = @event.confirmations.build(user: current_user)
  @confirmation.accept
  if @confirmation.save
    EventMailer.delay(queue: :mailer).notify_owner_for_event_acceptance(@event.id, current_user.id, 'accepted')
  end
  respond_to do |format|
    format.js {render 'confirmation'}
  end
end
create() click to toggle source

Method to create event and send invitation of event to the selected group member.

# File app/controllers/events_controller.rb, line 48
def create
  @event = current_user.owned_events.build(event_params)
  if !event_params["user_emails"].blank?
    users = User.where(email: event_params["user_emails"].split(','))
    invitee_emails = event_params["user_emails"].split(',') - users.map(&:email)
    users.each do |user|
      @event.shares.build(user_id: current_user.id, shared_to: user)
    end
  end
  if @event.save
    Invite.invite_users(invitee_emails, @event) if invitee_emails.present?
    respond_to do |format|
      format.js {render 'save'}
    end
  end
end
destroy() click to toggle source

Destroy the event.

# File app/controllers/events_controller.rb, line 74
def destroy
  @event.destroy
  respond_to do |format|
    format.js {render 'remove'}
  end
end
edit() click to toggle source

Opens the edit form without rendering layout.

# File app/controllers/events_controller.rb, line 12
def edit
  render layout: false
end
index() click to toggle source

Retrieves all event.

# File app/controllers/events_controller.rb, line 7
def index
  @events = Event.all
end
new() click to toggle source

Method to intialize object for event and tutoring session.

# File app/controllers/events_controller.rb, line 35
def new
  @event = Event.new(start_time: params[:start_time], end_time: params[:end_time])
  @tutoring_session = TutoringSession.new(start_time: params[:start_time], end_time: params[:end_time], date: params[:start_time].to_date)
  if params[:user_id]
    @tutor = User.find(params[:user_id])
    if @tutor.tutor?
      @tutoring_session.tutor = @tutor
    end
  end
  render layout: false
end
reject() click to toggle source

To reject the event and build confirmation for the event with reject

# File app/controllers/events_controller.rb, line 94
def reject
  @confirmation = @event.confirmations.build(user: current_user)
  @confirmation.reject
  if @confirmation.save
    EventMailer.delay(queue: :mailer).notify_owner_for_event_acceptance(@event.id, current_user.id, 'rejected')
  end
  respond_to do |format|
    format.js {render 'confirmation'}
  end
end
show() click to toggle source

Displays the event information.

# File app/controllers/events_controller.rb, line 66
def show
  if @event && @event.grouped?
    @group = @event.shares.last.shared_to
  end
  render layout: false
end
update() click to toggle source

Update the event.

# File app/controllers/events_controller.rb, line 17
def update
  if @event.update_attributes(event_params)
    if !event_params["user_emails"].blank?
      @event.share_with!(event_params["user_emails"].split(','))
    end
    respond_to do |format|
      format.js {render 'save'}
      format.json {render json: {}}
    end
  else
    respond_to do |format|
      format.js {render 'save'}
      format.json {render json: {error: @event.errors.full_messages}, status: 403}
    end
  end
end