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
|
2015-10-28 18:05:15 +02:00
|
|
|
@campaign.attributes = campaign_params
|
2014-06-26 09:08:26 +02:00
|
|
|
|
|
|
|
|
if @conference.save
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: 'Campaign successfully created.'
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = 'Campaign creation failed. ' + @campaign.errors.full_messages.to_sentence
|
2014-12-18 13:38:40 +01:00
|
|
|
render action: 'new'
|
2014-06-26 09:08:26 +02:00
|
|
|
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
|
2015-10-28 18:05:15 +02:00
|
|
|
if @campaign.update_attributes(campaign_params)
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: "Campaign '#{@campaign.name}' successfully updated."
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2017-04-03 18:34:37 +03:00
|
|
|
flash.now[:error] = "Campaign update failed. #{@campaign.errors.full_messages.to_sentence}"
|
2014-12-18 13:38:40 +01:00
|
|
|
render action: 'edit'
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
if @campaign.destroy
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
|
|
|
|
|
notice: "Campaign '#{@campaign.name}' successfully deleted."
|
2014-06-26 09:08:26 +02:00
|
|
|
else
|
2016-03-11 02:08:00 +05:30
|
|
|
redirect_to admin_conference_campaigns_path(conference_id: @conference.short_title),
|
2016-03-10 14:25:38 +05:30
|
|
|
error: "Delete of Campaign for #{@conference.short_title} failed."\
|
2016-03-11 02:08:00 +05:30
|
|
|
"#{@campaign.errors.full_messages.join('. ')}."
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|
2015-10-28 18:05:15 +02:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def campaign_params
|
|
|
|
|
params.require(:campaign).permit(:name, :utm_source, :utm_medium, :utm_term, :utm_content, :utm_campaign, :target_ids, :conference_id)
|
|
|
|
|
end
|
2014-06-26 09:08:26 +02:00
|
|
|
end
|
|
|
|
|
end
|