2014-05-05 04:50:33 +00:00
|
|
|
class Admin::AdImagesController < Admin::AdBannersController
|
2014-05-09 08:42:23 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "ad_banner"
|
|
|
|
end
|
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
def index
|
2014-07-16 07:20:25 +00:00
|
|
|
@ad_images = AdImage.order_by(sort).page(params[:page]).per(10)
|
|
|
|
@table_fields = ["preview","ad_banner.banner","title","start_date","end_date", "link"]
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
|
|
|
|
2014-05-09 08:42:23 +00:00
|
|
|
def edit
|
|
|
|
@ad_image = AdImage.find(params[:id])
|
2014-07-31 09:42:11 +00:00
|
|
|
if can_edit_or_delete?(@ad_image)
|
2014-05-09 08:42:23 +00:00
|
|
|
@ad_banners = Banner.all
|
2014-07-31 09:42:11 +00:00
|
|
|
@tags = @module_app.tags || []
|
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
2014-05-09 08:42:23 +00:00
|
|
|
|
|
|
|
def update
|
|
|
|
@ad_image = AdImage.find(params[:id])
|
|
|
|
if @ad_image.update_attributes(ad_image_params)
|
|
|
|
redirect_to admin_ad_images_url
|
|
|
|
else
|
|
|
|
@ad_banners = Banner.all
|
|
|
|
@tags = @module_app.tags || []
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@ad_image = AdImage.new
|
|
|
|
@ad_banners = Banner.all
|
|
|
|
@tags = @module_app.tags || []
|
2014-04-11 07:47:33 +00:00
|
|
|
|
2014-05-09 08:42:23 +00:00
|
|
|
@ad_image.postdate = Date.today
|
|
|
|
@ad_image.deadline = Date.today + 30
|
|
|
|
end
|
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
def create
|
2014-05-09 08:42:23 +00:00
|
|
|
@ad_image = AdImage.new(ad_image_params)
|
|
|
|
if @ad_image.save
|
|
|
|
redirect_to admin_ad_images_url
|
|
|
|
else
|
|
|
|
@ad_banners = Banner.all
|
|
|
|
@tags = @module_app.tags || []
|
|
|
|
@ad_image = AdImage.new(ad_image_params)
|
|
|
|
render action: :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@ad_image = AdImage.find params[:id]
|
|
|
|
if @ad_image.destroy
|
|
|
|
redirect_to admin_ad_images_url
|
|
|
|
end
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def ad_image_params
|
2014-05-09 08:42:23 +00:00
|
|
|
params.require(:ad_image).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_vars
|
|
|
|
@module_app = ModuleApp.where(:key => "ad_banner").first
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
|
|
|
end
|