orbit4-5/app/controllers/orbit_admin_controller.rb

93 lines
3.1 KiB
Ruby
Raw Normal View History

class OrbitAdminController < ApplicationController
include OrbitCoreLib::Authorize
include Authorize
2014-05-01 08:44:01 +00:00
include OrbitBackendHelper
before_action :authenticate_user, :log_user_action, :load_authorized_categories
2014-12-09 13:25:51 +00:00
before_action :check_for_nil_categories, :only => [:new, :edit]
layout "back_end"
def sort
unless params[:sort].blank?
case params[:sort]
when "status"
@sort = [[:is_top, params[:order]],
2014-07-16 07:14:13 +00:00
[:is_hot, params[:order]],
[:is_hidden,params[:order]]]
when "category"
@sort = {:category_id=>params[:order]}
when "start_date"
@sort = {:postdate=>params[:order]}
when "end_date"
@sort = {:deadline=>params[:order]}
when "last_modified"
@sort = {:update_user_id=>params[:order]}
2014-07-16 07:14:13 +00:00
when "banner"
@sort = {'banner_id'=>params[:order]}
when "banner_name"
@sort = {:title=>params[:order]}
when "effect"
@sort = {:ad_fx=>params[:order]}
when "transition_interval"
@sort = {:timeout=>params[:order]}
when "transition_speed"
@sort = {:speed=>params[:order]}
when "size"
@sort = {:height=>params[:order]}
when "link"
@sort = {:out_link=>params[:order]}
2014-08-07 10:44:23 +00:00
else
s = Sanitize.clean(params[:sort]).to_sym
@sort = {s=>params[:order]}
end
else
@sort = {:created_at=>'desc'}
end
@sort
end
def filter_fields(categories, tags)
{
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
2014-06-18 06:49:19 +00:00
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}},
:tags=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}}
}
end
def filters(type)
case type
when "status"
params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
when "category"
params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
when "tag"
params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
end
end
2014-08-07 10:44:23 +00:00
def search_data(data, fields)
if params[:keywords].present?
key_string = params[:keywords]
key_string = key_string.strip.nil? ? key_string : key_string.strip
keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
data = data.any_of(fields.map{|f| {f.to_sym => regex} })
end
data
end
def load_authorized_categories
@user_authenticated_categories = current_user.is_admin? ? ["all"] : current_user.approved_categories.collect{|c| c.id} rescue []
2014-11-13 13:50:08 +00:00
@current_user_is_sub_manager = current_user.is_sub_manager?(@module_app) rescue false
end
2014-12-09 13:25:51 +00:00
def check_for_nil_categories
@user_authorized_categories = @module_app.categories.enabled.authorized(current_user)
if @current_user_is_sub_manager && @user_authorized_categories.blank?
render_403
end
end
end