Class: UsefullFilter::FilterFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/usefull_filter/filter_form_builder.rb

Constant Summary collapse

DEFAULT_TYPES =
["equals", "does_not_equal", "in", "not_in", "is_blank", "is_not_null"]
STRING_TYPES =
["contains", "does_not_contain", "starts_with", "does_not_start_with", "ends_with", "does_not_end_with"]
NUMBER_TYPES =
["greater_than", "greater_than_or_equal_to", "less_than", "less_than_or_equal_to"]
BOOLEAN_TYPES =
["is_true", "is_false"]
OTHER_TYPES =
["is_present", "is_blank"]

Instance Method Summary collapse

Instance Method Details

#between_dates(object_name, *args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/usefull_filter/filter_form_builder.rb', line 31

def between_dates(object_name, *args)
  opt = args.extract_options!
  name = object_name.to_s.gsub(/\./, "_") + "_my_between_dates"
  opt.merge!(@options[:html_1][:input])
  opt.merge!({:field_type => :text_field})
  opt[:class].blank? ? opt[:class]="btw_date auto-kal" : opt[:class] << " btw_date auto-kal"   
  if opt[:format].blank?
    opt['data-kal']="format: '" + I18n.t("date.formats.between_dates_default_js") + "'"
  else
    _format = opt.delete(:format)
    opt['data-kal']="format: '#{_format}'"
  end
  @template.(:li) do
    @template.concat I18n.t(:my_between_dates, :scope =>"meta_search.predicates", :attribute => human(object_name))
    @template.concat multiparameter_field(name, opt.dup, opt.dup, :size => 10)
  end
end

#date_select(object_name, *args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/usefull_filter/filter_form_builder.rb', line 49

def date_select(object_name, *args)
     # Richiamo il metodo "text_field" facendogli utilizzare la classe "auto-kal" utilizzata da un JS per mostrare il calendario.
     options = args.extract_options!
     options[:class].blank? ? options[:class]="auto-kal" : options[:class] << " auto-kal"
     options['data-kal'] = "format: '" + I18n.t("date.formats.date_select_default_js") + "'"  
     text_field(object_name, options)
end

#select(object_name, array, *args) ⇒ Object

Utilizza come filtro una combo, con i valori passati nell’array



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/usefull_filter/filter_form_builder.rb', line 58

def select(object_name, array, *args)
  opt = define_args(args, object_name)
  name = object_name.to_s.gsub(/\./, "_")
  opt.merge!(@options[:html_1][:input])
  @template.(:li) do
    @template.concat filter_list(name, opt[:default_filter], opt)
    @template.concat " "
    #@template.concat select("search", default(name, opt[:default_filter]), array.collect {|p| [p,p]}, opt)
    @template.concat super(default(name, opt[:default_filter]), array, opt)
    ##UserSession.log("FilterHelper#text_field:object_name=#{object_name.inspect}")
  end
end

#submitObject

Utilizza come filtro un elenco di valori rappresentati da una check_box che vengono gestiti come OR def checks(object_name, array, *args, &block)

super.to_s.html_safe

end



77
78
79
80
# File 'lib/usefull_filter/filter_form_builder.rb', line 77

def submit
	applay_filter_label = I18n.t(:applay_filter, :scope => "meta_search.buttons")
  super(applay_filter_label, :class => "apply_filter_btn")
end

#text_field(object_name, *args) ⇒ Object

Ridefinisco il metodo per wrapparlo all’interno di una lista Accetta i seguenti parametri:

  • :default_filter => “equals”

  • :filters => [“equals”, .…]

Il nome sarà del tipo

  • :ART

  • “document.activity.id” (come per la tabelle)



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/usefull_filter/filter_form_builder.rb', line 18

def text_field(object_name, *args)
  opt = define_args(args, object_name)
  name = object_name.to_s.gsub(/\./, "_")
  opt.merge!(@options[:html_1][:input])
  @template.(:li) do
    #@template.concat filter_list(name, opt[:default_filter], opt)
    @template.concat filter_list(object_name, opt[:default_filter], opt)
    @template.concat " "
    @template.concat super(default(name, opt[:default_filter]), opt)
    #@template.concat attribute_type(object_name) == :Date ? @template.link_to(@template.image_tag('calendar16.png'), '#', :onclick => "show_calendar('search_data_prevista_equals')") : ''
  end
end