class Admin::AdBannersController < OrbitAdminController before_action ->(module_app = @app_title) { set_variables module_app } def index @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) @banners = Banner.all .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 end def show @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] end def new 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 render_401 if !user_has_rights end def create ad_banner = Banner.new(banner_params) ad_banner.save redirect_to admin_ad_banners_url end def edit 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]) render_401 if !user_has_rights end def update ad_banner = Banner.find(params[:id]) ad_banner.update_attributes(banner_params) redirect_to params[:referer_url] end def destroy 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 end private # Never trust parameters from the scary internet, only allow the white list through. def banner_params params.require(:banner).permit! end end