2014-05-05 04:50:33 +00:00
|
|
|
class Admin::AdBannersController < OrbitAdminController
|
2014-08-15 03:22:02 +00:00
|
|
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
2014-05-05 04:50:33 +00:00
|
|
|
|
2014-08-14 11:54:21 +00:00
|
|
|
def index
|
2016-01-05 11:57:19 +00:00
|
|
|
@table_fields = ["ad_banner.banner", :title, :category]
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, [])
|
|
|
|
@filter_fields.delete(:status)
|
|
|
|
@filter_fields.delete(:tags)
|
2014-08-14 11:54:21 +00:00
|
|
|
@banners = Banner.all
|
2016-01-05 11:57:19 +00:00
|
|
|
.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
|
|
|
|
@banners = search_data(@banners,[:title]).page(params[:page]).per(6)
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "index_table"
|
|
|
|
end
|
2014-05-05 04:50:33 +00:00
|
|
|
end
|
2014-05-09 08:42:23 +00:00
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
def show
|
2016-01-05 11:57:19 +00:00
|
|
|
@banner = Banner.find(params[:id])
|
|
|
|
@images = @banner.ad_images.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
@table_fields = [:banner, :title, "ad_banner.duration", :link]
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
2014-05-09 08:42:23 +00:00
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
def new
|
2016-01-05 11:57:19 +00:00
|
|
|
user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false
|
2014-05-09 08:42:23 +00:00
|
|
|
@ad_banner = Banner.new
|
2016-01-05 11:57:19 +00:00
|
|
|
render_401 if !user_has_rights
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
2014-05-09 08:42:23 +00:00
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
def create
|
2016-01-05 11:57:19 +00:00
|
|
|
ad_banner = Banner.new(banner_params)
|
|
|
|
ad_banner.save
|
|
|
|
redirect_to admin_ad_banners_url
|
2014-05-09 08:42:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2016-01-05 11:57:19 +00:00
|
|
|
user_has_rights = (current_user.is_admin? ? true : (current_user.is_manager?(@module_app) ? true : current_user.is_manager_with_role?(@module_app) ? true : false)) rescue false
|
2014-05-09 08:42:23 +00:00
|
|
|
@ad_banner = Banner.find(params[:id])
|
2016-01-05 11:57:19 +00:00
|
|
|
render_401 if !user_has_rights
|
2014-05-09 08:42:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-01-05 11:57:19 +00:00
|
|
|
ad_banner = Banner.find(params[:id])
|
|
|
|
ad_banner.update_attributes(banner_params)
|
|
|
|
redirect_to params[:referer_url]
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
|
|
|
|
2014-05-09 08:42:23 +00:00
|
|
|
def destroy
|
2016-01-05 11:57:19 +00:00
|
|
|
ad_banner = Banner.find(params[:id])
|
|
|
|
ad_banner.destroy
|
|
|
|
redirect_to admin_ad_banners_path(:page => params[:page])
|
2014-05-09 08:42:23 +00:00
|
|
|
end
|
|
|
|
|
2014-04-11 07:47:33 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
# Never trust parameters from the scary internet, only allow the white list through.
|
|
|
|
def banner_params
|
2016-01-05 11:57:19 +00:00
|
|
|
params.require(:banner).permit!
|
2014-04-11 07:47:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|