adbanner-test/app/controllers/admin/ad_banners_controller.rb

80 lines
2.3 KiB
Ruby
Raw Normal View History

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)
2016-02-16 12:21:14 +00:00
if request.xhr?
2016-01-05 11:57:19 +00:00
render :partial => "index_table"
end
2014-05-05 04:50:33 +00:00
end
2014-04-11 07:47:33 +00:00
def show
2016-01-05 11:57:19 +00:00
@banner = Banner.find(params[:id])
2016-02-16 12:21:14 +00:00
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
2016-01-05 11:57:19 +00:00
@table_fields = [:banner, :title, "ad_banner.duration", :link]
2014-04-11 07:47:33 +00:00
end
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
@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-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
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
@ad_banner = Banner.find(params[:id])
2016-01-05 11:57:19 +00:00
render_401 if !user_has_rights
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
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])
end
2016-02-16 12:21:14 +00:00
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
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