Module: UsefullFilterHelper

Defined in:
app/helpers/usefull_filter_helper.rb

Overview

require “usefull_filter/filter_form_builder” L’helper si occupa di wrappare la classe MetaSearch permettendo l’utilizzo di Filtri selezionabili dall’utente

documents_controller

Vedi TableHelper

index.html.erb

<%=filter_for_new @search, :url => magazzino_documents_path do |f| %>

<%= f.text_field :data, :size => 10, :filters => ["equals", "less_than_or_equal_to", "greater_than_or_equal_to"] %>
<%= f.text_field :DoCNr, :filters_type => :number %>
<%= f.text_field :TbDoC, :filters_only => ["equals"] %>
<%= f.text_field :BollaXENrDoC, filters_except => ["equals", "does_not_equal"] %>
<%= f.text_field :DoCSit %>
<%= f.submit %>

<% end %> f

Instance Method Summary collapse

Instance Method Details

#filter_button_tag(name, url, method = :get) ⇒ Object

Contatta l’url passato ripassando i filtri attivi in @search



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/usefull_filter_helper.rb', line 19

def filter_button_tag(name, url, method = :get)
  if @search.kind_of?(MetaSearch::Builder)
    form_tag(url, :method => method) do
      @search.search_attributes.each  do |k,v|
        if v.kind_of?(Array)
          v.each{|vv| concat hidden_field_tag("search[#{k}][]", vv)} 
        else
          concat hidden_field_tag("search[#{k}]", v)
        end
      end
      concat submit_tag(name)
    end
  end
end

#filter_for(obj, *args, &proc) ⇒ Object

Cerca una serie di filtri utilizzando MetaSearch di cui fa il wrapper obj è una istanza metasearch



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
95
96
97
# File 'app/helpers/usefull_filter_helper.rb', line 60

def filter_for(obj, *args, &proc)
  unless obj.blank?
    options = args.extract_options!

    options[:html] ||= {}
    options[:html][:select] ||= {}
    options[:html][:input] ||= {}
    options[:html][:method] ||= :get
    options[:html][:class] ||= "usefull_filter_container"
    options[:html_1] = options.delete(:html)
    options.merge!(:builder => UsefullFilter::FilterFormBuilder)
   
    remove_filter_label = I18n.t("remove_filter", :scope => "meta_search.buttons")
    filter_title = I18n.t("filter_title", :scope => "meta_search.buttons")
    
    #Estraggo le options che mi interessano, perchè una volta passate al builder
    #per qualche arcano motivo vengono alterate....
    classe = options[:html_1].delete(:class)
    url = options[:url]
    # mylog("FilterHelper#filter_for_new: args=#{args.inspect}")
    # mylog("FilterHelper#filter_for_new: options=#{options.inspect}")
    # mylog("FilterHelper#filter_for_new: obj=#{obj.inspect}")
    (:div,
      javascript_include_tag("usefull_filter_date_select") +
      javascript_include_tag("usefull_helpers_toggle_area")+		
      stylesheet_link_tag("usefull_filter") +  
      stylesheet_link_tag("usefull_filter_date_select") +  
      (:h3, filter_title) +
      toggle_area("all_filters") +
      (:ul,
        form_for(obj, *(args << options), &proc) +
        form_tag(url_for(url), :method => :get) do
          obj.search_attributes.each_key {|k| concat hidden_field_tag("search[#{k}]") } 
          concat submit_tag(remove_filter_label, :class => "remove_filter_btn") 
        end, :class=> "all_filters", :style => "display: none;" ),
    :class => classe)
  end
end

#filter_for_new(obj, *args, &proc) ⇒ Object



34
35
36
# File 'app/helpers/usefull_filter_helper.rb', line 34

def filter_for_new(obj, *args, &proc)
  filter_for(obj, *args, &proc)
end

#parse_params(param) ⇒ Object

Parsa il params per accomodare il tipo di dato dei valori



39
40
41
42
43
44
45
# File 'app/helpers/usefull_filter_helper.rb', line 39

def parse_params(param)
  param.keys.each do |k|
    param[k]=param[k].split(' ') if '_in' == /_in$/.match(k).to_s
  end unless param.blank?
  #mylog("parse_params: #{param.inspect}")
  param
end

#parse_params_rev(param) ⇒ Object

Parsa il params per accomodare il tipo di dato dei valori



48
49
50
51
52
53
54
# File 'app/helpers/usefull_filter_helper.rb', line 48

def parse_params_rev(param)
  param.keys.each do |k|
    param[k]=param[k].join(' ') if '_in' == /_in$/.match(k).to_s
  end
  mylog("parse_params_rev: #{param.inspect}")
  param
end