2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-06-05 20:05:20 +05:30
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class SponsorsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
2014-11-25 10:47:18 +01:00
|
|
|
load_and_authorize_resource :sponsor, through: :conference
|
2016-05-16 01:08:06 +05:30
|
|
|
before_action :sponsorship_level_required, only: [:index, :new]
|
2014-08-12 11:51:59 +03:00
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
authorize! :index, Sponsor.new(conference_id: @conference.id)
|
|
|
|
|
end
|
2014-06-05 20:05:20 +05:30
|
|
|
|
2014-11-25 10:47:18 +01:00
|
|
|
def edit; end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
@sponsor = @conference.sponsors.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@sponsor = @conference.sponsors.new(sponsor_params)
|
|
|
|
|
if @sponsor.save
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_sponsors_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Sponsor successfully created.'
|
2014-11-25 10:47:18 +01:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Creating sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."
|
2014-11-25 10:47:18 +01:00
|
|
|
render :new
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-05 20:05:20 +05:30
|
|
|
def update
|
2014-11-25 10:47:18 +01:00
|
|
|
if @sponsor.update_attributes(sponsor_params)
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_sponsors_path(
|
2014-06-05 20:05:20 +05:30
|
|
|
conference_id: @conference.short_title),
|
2016-03-11 02:08:00 +05:30
|
|
|
notice: 'Sponsor successfully updated.'
|
2014-06-05 20:05:20 +05:30
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."
|
2014-11-25 10:47:18 +01:00
|
|
|
render :edit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @sponsor.destroy
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_sponsors_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Sponsor successfully deleted.'
|
2014-11-25 10:47:18 +01:00
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_sponsors_path(conference_id: @conference.short_title),
|
2014-11-25 10:47:18 +01:00
|
|
|
error: 'Deleting sponsor failed! ' \
|
2016-03-11 02:08:00 +05:30
|
|
|
"#{@sponsor.errors.full_messages.join('. ')}."
|
2014-06-05 20:05:20 +05:30
|
|
|
end
|
|
|
|
|
end
|
2014-11-25 10:47:18 +01:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def sponsor_params
|
2016-04-27 15:55:39 +02:00
|
|
|
params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id)
|
2014-11-25 10:47:18 +01:00
|
|
|
end
|
2016-05-16 01:08:06 +05:30
|
|
|
|
|
|
|
|
def sponsorship_level_required
|
|
|
|
|
return unless @conference.sponsorship_levels.empty?
|
2018-11-13 18:01:49 -08:00
|
|
|
|
2016-05-16 01:08:06 +05:30
|
|
|
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title),
|
|
|
|
|
alert: 'You need to create atleast one sponsorship level to add a sponsor'
|
|
|
|
|
end
|
2014-06-05 20:05:20 +05:30
|
|
|
end
|
|
|
|
|
end
|