2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-08-18 14:33:02 +02:00
|
|
|
module Admin
|
2017-06-24 05:03:24 +05:30
|
|
|
class RegistrationPeriodsController < Admin::BaseController
|
2014-08-18 14:33:02 +02:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource through: :conference, singleton: true
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@registration_period = @conference.build_registration_period
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2015-10-28 18:05:15 +02:00
|
|
|
@registration_period = @conference.build_registration_period(registration_period_params)
|
2014-08-18 14:33:02 +02:00
|
|
|
send_mail_on_reg_update = @conference.notify_on_registration_dates_changed?
|
|
|
|
|
|
|
|
|
|
if @registration_period.save
|
2016-04-21 15:38:44 +02:00
|
|
|
ConferenceRegistrationDateUpdateMailJob.perform_later(@conference) if send_mail_on_reg_update
|
2014-08-18 14:33:02 +02:00
|
|
|
redirect_to admin_conference_registration_period_path(@conference.short_title),
|
|
|
|
|
notice: 'Registration Period successfully updated.'
|
|
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "An error prohibited the Registration Period from being saved: #{@registration_period.errors.full_messages.join('. ')}."
|
2014-08-18 14:33:02 +02:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2015-10-28 18:05:15 +02:00
|
|
|
@registration_period.assign_attributes(registration_period_params)
|
2014-08-18 14:33:02 +02:00
|
|
|
send_mail_on_reg_update = @conference.notify_on_registration_dates_changed?
|
|
|
|
|
|
2015-10-28 18:05:15 +02:00
|
|
|
if @registration_period.update(registration_period_params)
|
2016-04-21 15:38:44 +02:00
|
|
|
ConferenceRegistrationDateUpdateMailJob.perform_later(@conference) if send_mail_on_reg_update
|
2014-08-18 14:33:02 +02:00
|
|
|
redirect_to admin_conference_registration_period_path(@conference.short_title),
|
|
|
|
|
notice: 'Registration Period successfully updated.'
|
|
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = 'An error prohibited the Registration Period from being saved: ' \
|
2014-08-18 14:33:02 +02:00
|
|
|
"#{@registration_period.errors.full_messages.join('. ')}."
|
|
|
|
|
render :edit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
@registration_period.destroy
|
|
|
|
|
redirect_to admin_conference_registration_period_path,
|
|
|
|
|
notice: 'Registration Period was successfully destroyed.'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2015-10-28 18:05:15 +02:00
|
|
|
def registration_period_params
|
|
|
|
|
params.require(:registration_period).permit(:start_date, :end_date)
|
2014-08-18 14:33:02 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|