ad_banner_pro/app/controllers/admin/ad_banners_controller.rb

80 lines
2.3 KiB
Ruby
Raw Permalink Normal View History

2014-11-25 10:34:14 +00:00
class Admin::AdBannersController < OrbitAdminController
before_action ->(module_app = @app_title) { set_variables module_app }
def index
2016-02-17 12:37:37 +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-11-25 10:34:14 +00:00
@banners = Banner.all
2016-02-17 12:37:37 +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-11-25 10:34:14 +00:00
end
def show
2016-02-17 12:37:37 +00:00
@banner = Banner.find(params[:id])
if params[:show] == "expired"
@images = @banner.ad_images.is_expired.asc(:sort_number).page(params[:page]).per(10)
else
@images = @banner.ad_images.not_expired.asc(:sort_number).page(params[:page]).per(10)
end
@table_fields = [:banner, :title, "ad_banner.duration", :link]
2014-11-25 10:34:14 +00:00
end
def new
2016-02-17 12:37:37 +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-11-25 10:34:14 +00:00
@ad_banner = Banner.new
2016-02-17 12:37:37 +00:00
render_401 if !user_has_rights
2014-11-25 10:34:14 +00:00
end
def create
2016-02-17 12:37:37 +00:00
ad_banner = Banner.new(banner_params)
ad_banner.save
redirect_to admin_ad_banners_url
2014-11-25 10:34:14 +00:00
end
def edit
2016-02-17 12:37:37 +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-11-25 10:34:14 +00:00
@ad_banner = Banner.find(params[:id])
2016-02-17 12:37:37 +00:00
render_401 if !user_has_rights
2014-11-25 10:34:14 +00:00
end
def update
2016-02-17 12:37:37 +00:00
ad_banner = Banner.find(params[:id])
ad_banner.update_attributes(banner_params)
redirect_to params[:referer_url]
2014-11-25 10:34:14 +00:00
end
def destroy
2016-02-17 12:37:37 +00:00
ad_banner = Banner.find(params[:id])
ad_banner.destroy
redirect_to admin_ad_banners_path(:page => params[:page])
end
def save_image_order
ids = params[:ids]
ids.each_with_index do |id,index|
image = AdImage.find(id) rescue nil
if !image.nil?
image.sort_number = index
image.save
end
end
render :json => {"success" => true}.to_json
2014-11-25 10:34:14 +00:00
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def banner_params
2016-02-17 12:37:37 +00:00
params.require(:banner).permit!
2014-11-25 10:34:14 +00:00
end
end