2014-08-06 21:14:00 +03:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class TracksController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2015-10-25 13:29:02 +02:00
|
|
|
load_and_authorize_resource :program, through: :conference, singleton: true
|
2017-06-29 23:39:56 +03:00
|
|
|
load_and_authorize_resource through: :program, find_by: :short_name
|
2014-08-12 11:51:59 +03:00
|
|
|
|
2017-08-08 12:41:37 +03:00
|
|
|
# Show flash message with ajax calls
|
|
|
|
|
after_action :prepare_unobtrusive_flash, only: :toggle_cfp_inclusion
|
|
|
|
|
|
2014-11-25 10:47:18 +01:00
|
|
|
def index; end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def show
|
|
|
|
|
respond_to do |format|
|
2014-11-25 10:47:18 +01:00
|
|
|
format.html { render }
|
2014-08-06 21:14:00 +03:00
|
|
|
format.json { render json: @conference.tracks.to_json }
|
|
|
|
|
end
|
2013-01-11 15:00:54 +01:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-11-25 10:47:18 +01:00
|
|
|
def new
|
2016-07-02 21:37:16 +02:00
|
|
|
@track = @program.tracks.new(color: @conference.next_color_for_collection(:tracks))
|
2014-11-25 10:47:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2015-10-25 13:29:02 +02:00
|
|
|
@track = @program.tracks.new(track_params)
|
2017-07-15 19:55:45 +03:00
|
|
|
@track.state = 'confirmed'
|
2017-07-14 15:57:34 +03:00
|
|
|
@track.cfp_active = true
|
2014-11-25 10:47:18 +01:00
|
|
|
if @track.save
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Track successfully created.'
|
2014-11-25 10:47:18 +01:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Creating Track failed: #{@track.errors.full_messages.join('. ')}."
|
2014-11-25 10:47:18 +01:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit; end
|
|
|
|
|
|
2014-08-06 21:14:00 +03:00
|
|
|
def update
|
2014-11-25 10:47:18 +01:00
|
|
|
if @track.update_attributes(track_params)
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Track successfully updated.'
|
2014-08-06 21:14:00 +03:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Track update failed: #{@track.errors.full_messages.join('. ')}."
|
2014-11-25 10:47:18 +01:00
|
|
|
render :edit
|
2014-08-06 21:14:00 +03:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
2014-11-25 10:47:18 +01:00
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @track.destroy
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Track successfully deleted.'
|
2014-11-25 10:47:18 +01:00
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_program_tracks_path(conference_id: @conference.short_title),
|
|
|
|
|
error: "Track couldn't be deleted. #{@track.errors.full_messages.join('. ')}."
|
2014-11-25 10:47:18 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-08 12:25:33 +03:00
|
|
|
def toggle_cfp_inclusion
|
|
|
|
|
@track.cfp_active = !@track.cfp_active
|
|
|
|
|
if @track.save
|
2017-08-08 12:41:37 +03:00
|
|
|
flash[:notice] = "Successfully changed cfp inclusion of #{@track.name} to #{@track.cfp_active}"
|
2017-06-08 12:25:33 +03:00
|
|
|
else
|
2017-08-08 12:41:37 +03:00
|
|
|
flash[:error] = "Failed to toggle cfp inclusion of #{@track.name} to #{@track.cfp_active}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.js
|
2017-06-08 12:25:33 +03:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-14 15:57:34 +03:00
|
|
|
def restart
|
|
|
|
|
update_state(:restart, "Review for #{@track.name} started!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def to_accept
|
|
|
|
|
update_state(:to_accept, "Track #{@track.name} marked as a possible acceptance!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def accept
|
|
|
|
|
if @track.room && @track.start_date && @track.end_date
|
|
|
|
|
update_state(:accept, "Track #{@track.name} accepted!")
|
|
|
|
|
else
|
|
|
|
|
flash[:alert] = 'Please make sure that the track has a room and start/end dates before accepting it'
|
|
|
|
|
redirect_to edit_admin_conference_program_track_path(@conference.short_title, @track)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def confirm
|
|
|
|
|
update_state(:confirm, "Track #{@track.name} confirmed!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def to_reject
|
|
|
|
|
update_state(:to_reject, "Track #{@track.name} marked as a possible rejection!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def reject
|
|
|
|
|
update_state(:reject, "Track #{@track.name} rejected!")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
|
update_state(:cancel, "Track #{@track.name} canceled!")
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-25 10:47:18 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def track_params
|
2017-07-12 15:56:07 +03:00
|
|
|
params.require(:track).permit(:name, :description, :color, :short_name, :cfp_active, :start_date, :end_date, :room_id)
|
2014-11-25 10:47:18 +01:00
|
|
|
end
|
2017-07-14 15:57:34 +03:00
|
|
|
|
|
|
|
|
def update_state(transition, notice)
|
|
|
|
|
errors = @track.update_state(transition)
|
|
|
|
|
|
|
|
|
|
if errors.blank?
|
|
|
|
|
flash[:notice] = notice
|
|
|
|
|
else
|
|
|
|
|
flash[:error] = errors
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
redirect_back_or_to(admin_conference_program_tracks_path(conference_id: @conference.short_title))
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
end
|