Class: AdminData::SearchController

Inherits:
ApplicationController show all
Includes:
Search
Defined in:
app/controllers/admin_data/search_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#klass

Instance Method Summary collapse

Methods included from Search

#build_advance_search_condition, #build_quick_search_condition

Instance Method Details

#advance_searchObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/admin_data/search_controller.rb', line 58

def advance_search
  @page_title = "Advance search #{@klass.name.underscore}"
  hash = build_advance_search_condition(@klass, params[:adv_search])
  relation = hash[:cond]
  errors = hash[:errors]
  order = default_order

  respond_to do |format|
    format.html { render }
    format.js {

      unless hash[:errors].blank?
        file = File.join(AdminData::LIBPATH, '..', 'app','views', 'admin_data', 'search', 'search', '_errors.html.erb')
        render :file =>  file, :locals => {:errors => errors}
        return
      end

      search_action = SearchAction.new(relation)

      case params[:admin_data_advance_search_action_type]
      when 'destroy'
        search_action.destroy
      when 'delete'
        search_action.delete
      else
        @records = relation.order(order).paginate(:page => params[:page], :per_page => per_page)
      end

      if search_action.success_message
        render :json => {:success => search_action.success_message }
      else
        file = "/admin_data/search/search/listing.html.erb"
        render :partial => file, :locals => {:klass => @klass}, :layout => false
      end
    }
  end
end

#quick_searchObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin_data/search_controller.rb', line 37

def quick_search
  @page_title = "Search #{@klass.name.underscore}"
  order = default_order

  if params[:base]
    klass = Util.camelize_constantize(params[:base])
    model = klass.find(params[:model_id])
    has_many_proxy = model.send(params[:children].intern)
    @total_num_of_children = has_many_proxy.send(:count)
    h = { :page => params[:page], :per_page => per_page, :order => order }
    @records = has_many_proxy.send(:paginate, h)
  else
    params[:query] = params[:query].strip unless params[:query].blank?
    cond = build_quick_search_condition(@klass, params[:query])
    h = { :page => params[:page], :per_page => per_page, :order => order, :conditions => cond }
    @records = @klass.unscoped.paginate(h)
  end
  respond_to {|format| format.html}
end