2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
module Admin
|
|
|
|
|
class CfpsController < Admin::BaseController
|
|
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource :program, through: :conference, singleton: true
|
2017-05-30 20:54:48 +03:00
|
|
|
load_and_authorize_resource through: :program
|
2015-10-25 13:29:02 +02:00
|
|
|
|
2017-05-31 21:03:15 +03:00
|
|
|
def index; end
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
def show; end
|
|
|
|
|
|
|
|
|
|
def new
|
2018-10-18 12:00:20 -07:00
|
|
|
@cfp = @program.cfps.new(cfp_params_or_first_remaining_type)
|
2015-10-25 13:29:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit; end
|
|
|
|
|
|
|
|
|
|
def create
|
2017-05-31 21:03:15 +03:00
|
|
|
@cfp = @program.cfps.new(cfp_params)
|
2016-04-21 16:26:37 +02:00
|
|
|
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
|
2015-10-25 13:29:02 +02:00
|
|
|
|
|
|
|
|
if @cfp.save
|
2016-04-21 16:26:37 +02:00
|
|
|
ConferenceCfpUpdateMailJob.perform_later(@conference) if send_mail_on_cfp_dates_updates
|
2017-05-31 21:03:15 +03:00
|
|
|
redirect_to admin_conference_program_cfps_path,
|
2015-10-25 13:29:02 +02:00
|
|
|
notice: 'Call for papers successfully created.'
|
|
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Creating the call for papers failed. #{@cfp.errors.full_messages.join('. ')}."
|
2015-10-25 13:29:02 +02:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2016-01-13 14:15:12 +02:00
|
|
|
@cfp.assign_attributes(cfp_params)
|
2015-10-25 13:29:02 +02:00
|
|
|
|
|
|
|
|
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
|
|
|
|
|
|
2022-02-14 17:53:58 +01:00
|
|
|
if @cfp.update(cfp_params)
|
2016-04-21 16:26:37 +02:00
|
|
|
ConferenceCfpUpdateMailJob.perform_later(@conference) if send_mail_on_cfp_dates_updates
|
2017-05-31 21:03:15 +03:00
|
|
|
redirect_to admin_conference_program_cfps_path(@conference.short_title),
|
2016-03-11 02:08:00 +05:30
|
|
|
notice: 'Call for papers successfully updated.'
|
2015-10-25 13:29:02 +02:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Updating call for papers failed. #{@cfp.errors.to_a.join('. ')}."
|
2015-10-25 13:29:02 +02:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @cfp.destroy
|
2017-05-31 21:03:15 +03:00
|
|
|
redirect_to admin_conference_program_cfps_path, notice: 'Call for Papers was successfully deleted.'
|
2015-10-25 13:29:02 +02:00
|
|
|
else
|
2017-05-31 21:03:15 +03:00
|
|
|
redirect_to admin_conference_program_cfps_path, error: 'An error prohibited this Call for Papers from being destroyed: '\
|
2015-10-25 13:29:02 +02:00
|
|
|
"#{@cfp.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def cfp_params
|
2018-10-18 12:01:42 -07:00
|
|
|
params.require(:cfp).permit(
|
|
|
|
|
:start_date, :end_date,
|
|
|
|
|
:description, :cfp_type,
|
|
|
|
|
:enable_registrations
|
|
|
|
|
)
|
2015-10-25 13:29:02 +02:00
|
|
|
end
|
2018-10-18 12:00:20 -07:00
|
|
|
|
|
|
|
|
def cfp_params_or_first_remaining_type
|
|
|
|
|
cfp_params
|
|
|
|
|
rescue ActionController::ParameterMissing
|
|
|
|
|
{ 'cfp_type' => @program.remaining_cfp_types.first }
|
|
|
|
|
end
|
2015-10-25 13:29:02 +02:00
|
|
|
end
|
|
|
|
|
end
|