2014-06-26 09:08:26 +02:00
|
|
|
module Admin
|
2014-08-13 14:37:05 +03:00
|
|
|
class CampaignsController < Admin::BaseController
|
2014-08-12 11:51:59 +03:00
|
|
|
load_and_authorize_resource :conference, find_by: :short_title
|
|
|
|
|
load_and_authorize_resource :campaign, through: :conference
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
def index
|
2014-08-13 22:46:41 +03:00
|
|
|
authorize! :index, Campaign.new(conference_id: @conference.id)
|
2014-06-26 09:08:26 +02:00
|
|
|
@campaigns = @conference.campaigns
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2014-08-12 11:51:59 +03:00
|
|
|
@campaign.attributes = params[:campaign]
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
if @conference.save
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Campaign successfully created.')
|
|
|
|
|
else
|
|
|
|
|
redirect_to(new_admin_conference_campaign_path(conference_id: @conference.short_title),
|
|
|
|
|
alert: "Creating of Campaign for #{@conference.short_title} failed." \
|
|
|
|
|
"#{@campaign.errors.full_messages.join('. ')}.")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def new; end
|
2014-06-26 09:08:26 +02:00
|
|
|
|
2014-08-12 22:27:02 +03:00
|
|
|
def edit; end
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
if @campaign.update_attributes(params[:campaign])
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(
|
|
|
|
|
conference_id: @conference.short_title),
|
|
|
|
|
notice: "Campaign '#{@campaign.name}' successfully updated.")
|
|
|
|
|
else
|
|
|
|
|
redirect_to(edit_admin_conference_campaign_path(
|
|
|
|
|
conference_id: @conference.short_title,
|
|
|
|
|
id: @campaign.id),
|
|
|
|
|
alert: "Update of Campaign for #{@conference.short_title} failed." \
|
|
|
|
|
"#{@campaign.errors.full_messages.join('. ')}.")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @campaign.destroy
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: "Campaign '#{@campaign.name}' successfully deleted.")
|
|
|
|
|
else
|
|
|
|
|
redirect_to(admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
alert: "Delete of Campaign for #{@conference.short_title} failed." \
|
|
|
|
|
"#{@campaign.errors.full_messages.join('. ')}.")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|