clarion/app/controllers/public/events_controller.rb

74 lines
2.4 KiB
Ruby
Raw Permalink Normal View History

2015-08-15 03:43:41 +03:00
module Public
class EventsController < Public::ApplicationController
2019-04-28 02:15:39 +03:00
before_action :authenticate_user!
2015-08-15 03:43:41 +03:00
def index
2019-04-28 21:10:54 +03:00
@events = Event.joins(:conference, :proposition, :participations).where(conference: current_conference).where("propositions.proposer_id = ? OR participations.participant_id = ?", current_user.id, current_user.id)
2015-08-15 08:52:41 +03:00
end
def edit
@event = Event.joins(:participations).find_by(id: params[:id], participations: {participant_id: current_user.id})
2015-08-15 03:43:41 +03:00
end
def new
event_type = current_conference.event_types.find(params[:type])
2015-08-21 20:05:00 +03:00
@event = Event.new event_type: event_type, language: current_user.language
2015-08-15 03:43:41 +03:00
end
def create
@event = Event.new event_params
@event.conference = current_conference
@event.build_proposition proposer: current_user, status: :undecided
2015-08-15 03:43:41 +03:00
@event.participations.build participant: current_user, approved: true
if @event.save
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("views.events.event_successfully_created", event_type: @event.event_type.name.mb_chars.downcase)
after_save_redirect
2015-08-15 03:43:41 +03:00
else
render action: :new
end
end
2015-08-15 08:52:41 +03:00
def update
@event = Event.joins(:participations).find_by(id: params[:id], participations: {participant_id: current_user.id})
2015-08-15 08:52:41 +03:00
if @event.update(event_params)
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("views.events.event_successfully_updated", event_type: @event.event_type.name.mb_chars.downcase)
2015-08-15 08:52:41 +03:00
after_save_redirect
else
render action: :edit
end
end
2015-10-19 00:47:39 +03:00
def confirm
@event = current_user.events.approved.find(params[:id])
if @event.confirm!
2019-04-28 21:10:54 +03:00
flash[:notice] = I18n.t("views.events.successfully_confirmed", event_type: @event.event_type.name.mb_chars.downcase)
2015-10-19 00:47:39 +03:00
else
2019-04-28 21:10:54 +03:00
flash[:alert] = I18n.t("views.events.error_on_confirmation", event_type: @event.event_type.name.mb_chars.downcase)
2015-10-19 00:47:39 +03:00
end
after_save_redirect
end
2015-08-15 03:43:41 +03:00
private
def event_params
params.require(:event).permit(
:title, :subtitle, :track_id, :length, :language,
:abstract, :description, :notes, :agreement,
:event_type_id
)
end
def after_save_redirect
if current_user.personal_profile(current_conference).present?
2015-08-15 08:52:41 +03:00
redirect_to events_path
else
redirect_to edit_personal_profile_path, alert: I18n.t(:please_fill_in_your_speaker_profile)
end
end
2015-08-15 03:43:41 +03:00
end
end