kono_utils 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +0 -76
  3. data/app/assets/javascripts/kono_utils/core.coffee +477 -0
  4. data/app/assets/stylesheets/kono_utils/{_kono_styles.css.scss → core.css.scss} +1 -16
  5. data/app/policies/kono_utils/base_editing_policy_concern.rb +52 -3
  6. data/app/policies/kono_utils/base_search_form_policy_concern.rb +25 -0
  7. data/config/locales/it.yml +3 -1
  8. data/lib/generators/kono_utils/install/install_generator.rb +40 -3
  9. data/lib/generators/templates/base_editing_controller.template +3 -0
  10. data/lib/generators/templates/base_editing_helper.template +3 -0
  11. data/lib/generators/templates/base_editing_policy.template +4 -0
  12. data/lib/generators/templates/initializer.rb +3 -1
  13. data/lib/kono_utils.rb +20 -22
  14. data/lib/kono_utils/application_core_helper.rb +524 -0
  15. data/lib/kono_utils/application_enum_helper.rb +53 -0
  16. data/lib/kono_utils/application_helper.rb +4 -578
  17. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  18. data/lib/kono_utils/base_editing_helper.rb +3 -186
  19. data/lib/kono_utils/base_search.rb +32 -19
  20. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  21. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  22. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  23. data/lib/kono_utils/configuration.rb +18 -0
  24. data/lib/kono_utils/engine.rb +15 -7
  25. data/lib/kono_utils/paginate_proxer.rb +17 -0
  26. data/lib/kono_utils/search_form_builder.rb +24 -0
  27. data/lib/kono_utils/version.rb +1 -1
  28. data/spec/dummy/app/assets/config/manifest.js +2 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  31. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  32. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  34. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  35. data/spec/dummy/app/models/application_record.rb +5 -0
  36. data/spec/dummy/app/models/user.rb +2 -0
  37. data/spec/dummy/app/policies/application_policy.rb +49 -0
  38. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  39. data/spec/dummy/app/policies/user_policy.rb +23 -0
  40. data/spec/dummy/config/application.rb +1 -1
  41. data/spec/dummy/config/initializers/kono_utils.rb +3 -1
  42. data/spec/dummy/config/routes.rb +4 -0
  43. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  44. data/spec/dummy/db/schema.rb +23 -0
  45. data/spec/dummy/spec/models/user_spec.rb +5 -0
  46. metadata +63 -131
  47. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -480
  48. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  49. data/app/input/bs_aceeditor_input.rb +0 -53
  50. data/app/input/bs_autocomplete_input.rb +0 -60
  51. data/app/input/bs_datepicker_input.rb +0 -16
  52. data/app/input/bs_datetimepicker_input.rb +0 -80
  53. data/app/input/bs_file_download_input.rb +0 -35
  54. data/app/input/bs_image_input.rb +0 -35
  55. data/app/input/bs_label_with_container_input.rb +0 -22
  56. data/app/input/bs_location_picker_input.rb +0 -95
  57. data/app/input/bs_readonly_input.rb +0 -52
  58. data/app/input/bs_timepicker_input.rb +0 -14
  59. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  60. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  61. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  62. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  63. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  64. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  65. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  66. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  67. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  68. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  69. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  70. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  71. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  72. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  73. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  74. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  75. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  76. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  77. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  78. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  79. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  80. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  81. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  82. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  83. data/lib/kono_utils/concerns.rb +0 -10
  84. data/lib/kono_utils/encoder.rb +0 -47
  85. data/lib/kono_utils/fiscal_code.rb +0 -47
  86. data/lib/kono_utils/params_hash_array.rb +0 -37
  87. data/lib/kono_utils/percentage.rb +0 -60
  88. data/lib/kono_utils/tmp_file.rb +0 -81
  89. data/lib/kono_utils/virtual_model.rb +0 -22
  90. data/lib/tasks/kono_utils_tasks.rake +0 -4
  91. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  92. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -0,0 +1,194 @@
1
+ module KonoUtils
2
+ module BaseEditingCoreHelper
3
+
4
+ # def self.included(mod)
5
+ # if ::Rails.application.config.action_controller.include_all_helpers!=false
6
+ # raise "Devi definire in config/application.rb config.action_controller.include_all_helpers=false
7
+ # in modo da far funzionare correttamente l'override degli helper come per i controller"
8
+ # end
9
+ # end
10
+
11
+ ##
12
+ # Serie di metodi che identificano i titoli generati automaticamente
13
+ # Viene utilizzato i18n per identificare se un determinato modello è di tipo F o M
14
+ # é presente quindi una chiave in YML che identifica ogni modello(default M)
15
+ # def title_mod_g(model)
16
+ # "#{t("edit_title_#{model_gender(model)}", default: 'Modifica')} #{model.mn}"
17
+ # end
18
+ #
19
+ # def title_new_g(model)
20
+ # "#{t("new_title_#{model_gender(model)}", default: 'Nuovo')} #{model.mn}"
21
+ # end
22
+ #
23
+ # def title_del_g(model)
24
+ # "#{t("del_title_#{model_gender(model)}", default: 'Cancella')} #{model.mn}"
25
+ # end
26
+ #
27
+ # def model_gender(model)
28
+ # t("activerecord.modelgender.#{model.name.underscore.to_sym}", :default => :m).to_sym
29
+ # end
30
+
31
+ # def new_button(path, base_class=nil)
32
+ # options = {class: 'btn btn-success btn-xs'}
33
+ # options[:title] = title_new(base_class) unless base_class.nil?
34
+ #
35
+ # link_to fa_icon("plus fw"), path, options
36
+ # end
37
+ #
38
+ # def edit_button(path)
39
+ # link_to fa_icon("pencil fw"), path, class: 'btn btn-primary btn-xs'
40
+ # end
41
+ #
42
+ # def delete_button(path)
43
+ # link_to fa_icon("trash fw"), path, method: :delete, data: {confirm: t(:are_you_sure)}, class: 'btn btn-danger btn-xs'
44
+ # end
45
+
46
+ # def form_submit(f)
47
+ # f.actions do
48
+ # f.action :submit, :button_html => {:class => "btn btn-primary", :disable_with => t('wait', default: 'Wait...')}
49
+ # end
50
+ # end
51
+
52
+ ##
53
+ # Questa funzione serve per essere sovrascritta nell'helper specializzato del controller
54
+ # def index_print_column(record, field)
55
+ # record.send(field)
56
+ # end
57
+
58
+ ##
59
+ # Questa funzione serve per stampare il contenuto dell'header
60
+ # def index_print_column_head(field)
61
+ # block_given? ? yield(field) : base_class.han(field)
62
+ # end
63
+
64
+ ##
65
+ # Questa funzione serve per generare la colonna della tabella
66
+ #
67
+ # * *Attributes* :
68
+ # - colonna
69
+ # - tipo di colonna td|th
70
+ # - opzionali : hash{record} per fare altro
71
+ # def index_column_builder(field, column, record: nil)
72
+ # column_class = "column_#{field}"
73
+ # column_id=''
74
+ # if record
75
+ # column_id = "#{column_class}-#{dom_id(record)}"
76
+ # end
77
+ # content_tag column, class: column_class, id: column_id do
78
+ # yield column_class, column_id
79
+ # end
80
+ # end
81
+
82
+ # def list_button(path)
83
+ # link_to fa_icon("list fw"), path, class: 'btn btn-default btn-xs'
84
+ # end
85
+
86
+ ##
87
+ # Questa funzione serve per essere sovrascritta nell'helper specializzato del controller
88
+ # e quindi stampare un determinato campo in modo differente
89
+ # si occupa anche di gestire i campi provenienti dalla policy nel caso siano a più livelli con i nested
90
+ # prendiamo in considerazione la situazione con has_many :campo=>[] o con :campo=>[:ciao,:pippo,:pluto]
91
+ # def editing_form_print_field(form, field)
92
+ # if field.is_a?(Hash)
93
+ # #devo nestarlo
94
+ # bf = ActiveSupport::SafeBuffer.new
95
+ #
96
+ # field.each do |k, v|
97
+ # if v.length==0
98
+ # #caso in cui è un elemento normale, ma che ha una selezione multipla
99
+ # bf<< editing_form_print_field(form, k)
100
+ # else
101
+ # #caso in cui potremmo essere in un campo di multipli elementi con vari valori ognuno
102
+ # bf<< nest_editing_form_print_field(form, k, v)
103
+ # end
104
+ # end
105
+ # bf
106
+ # else
107
+ # form.input field
108
+ # end
109
+ # end
110
+
111
+ ##
112
+ # Questa funzione può essere sovrascritta per gestire in modo personale la renderizzazine dei nested attributes
113
+ # * *Attributes* :
114
+ # - form -> form di formtastic
115
+ # - contenitore -> campo principale
116
+ # - campi -> i campi interni
117
+ # def nest_editing_form_print_field(form, contenitore, campi)
118
+ # form.semantic_fields_for contenitore do |item|
119
+ # item.inputs :name => t(".#{form.object.mn}.#{contenitore}", :default => contenitore.to_s.camelcase) do
120
+ # bf = ActiveSupport::SafeBuffer.new
121
+ # campi.each do |c|
122
+ # bf<<editing_form_print_field(item, c)
123
+ # end
124
+ # bf
125
+ # end
126
+ # end
127
+ # end
128
+
129
+ ##
130
+ # Per divisione in celle della form
131
+ #
132
+ # def cell_column_class(field)
133
+ # "col-md-12"
134
+ # end
135
+
136
+
137
+ ##
138
+ # Funzione che visualizza il caricamento e l'immagine caricata precedente se presente
139
+ #
140
+ # * *Args* :
141
+ # - form
142
+ # - attribute
143
+ # * *Returns* :
144
+ # - ActiveSupport:SafeBuffer
145
+ #
146
+ # def image_show_upload(form, attribute)
147
+ #
148
+ # buff = ActiveSupport::SafeBuffer.new
149
+ #
150
+ # buff<<form.label(attribute)
151
+ #
152
+ # buff<<content_tag(:div, class: 'row') do
153
+ # tmp = ActiveSupport::SafeBuffer.new
154
+ #
155
+ #
156
+ # tmp << content_tag(:div, class: "col-md-5") do
157
+ # form.input attribute, :label => false
158
+ # end
159
+ #
160
+ # if form.object.send(attribute).exists?
161
+ # tmp << content_tag(:div, class: "col-md-2 col-lg-5") do
162
+ # link_to image_tag(form.object.send(attribute).url(:original), class: 'img-thumbnail logo-original'), form.object.send(attribute).url
163
+ # end
164
+ # end
165
+ #
166
+ # tmp
167
+ # end
168
+ #
169
+ #
170
+ # end
171
+
172
+
173
+ # def semantic_form_attributes(obj)
174
+ # obj
175
+ # end
176
+
177
+
178
+ ##
179
+ # Helper per visualizzare l'alert del destroy
180
+ # def destroy_link_to(path, options)
181
+ # link_to t('.destroy'), path,
182
+ # :method => :delete,
183
+ # :class => "btn",
184
+ # :confirm => t('.destroy_confirm.body', :item => options[:item]),
185
+ # "data-confirm-fade" => true,
186
+ # "data-confirm-title" => t('.destroy_confirm.title', :item => options[:item]),
187
+ # "data-confirm-cancel" => t('.destroy_confirm.cancel', :item => options[:item]),
188
+ # "data-confirm-cancel-class" => "btn-cancel",
189
+ # "data-confirm-proceed" => t('.destroy_confirm.proceed', :item => options[:item]),
190
+ # "data-confirm-proceed-class" => "btn-danger"
191
+ # end
192
+
193
+ end
194
+ end
@@ -1,194 +1,11 @@
1
1
  module KonoUtils
2
2
  module BaseEditingHelper
3
3
 
4
- def BaseEditingHelper.included(mod)
5
- if ::Rails.application.config.action_controller.include_all_helpers!=false
6
- raise "Devi definire in config/application.rb config.action_controller.include_all_helpers=false
7
- in modo da far funzionare correttamente l'override degli helper come per i controller"
4
+ def self.included(mod)
5
+ KonoUtils.configuration.base_editing_helper_includes.each do |m|
6
+ mod.send :include, m
8
7
  end
9
8
  end
10
9
 
11
- ##
12
- # Serie di metodi che identificano i titoli generati automaticamente
13
- # Viene utilizzato i18n per identificare se un determinato modello è di tipo F o M
14
- # é presente quindi una chiave in YML che identifica ogni modello(default M)
15
- def title_mod_g(model)
16
- "#{t("edit_title_#{model_gender(model)}", default: 'Modifica')} #{model.mn}"
17
- end
18
-
19
- def title_new_g(model)
20
- "#{t("new_title_#{model_gender(model)}", default: 'Nuovo')} #{model.mn}"
21
- end
22
-
23
- def title_del_g(model)
24
- "#{t("del_title_#{model_gender(model)}", default: 'Cancella')} #{model.mn}"
25
- end
26
-
27
- def model_gender(model)
28
- t("activerecord.modelgender.#{model.name.underscore.to_sym}", :default => :m).to_sym
29
- end
30
-
31
- def new_button(path, base_class=nil)
32
- options = {class: 'btn btn-success btn-xs'}
33
- options[:title] = title_new(base_class) unless base_class.nil?
34
-
35
- link_to fa_icon("plus fw"), path, options
36
- end
37
-
38
- def edit_button(path)
39
- link_to fa_icon("pencil fw"), path, class: 'btn btn-primary btn-xs'
40
- end
41
-
42
- def delete_button(path)
43
- link_to fa_icon("trash fw"), path, method: :delete, data: {confirm: t(:are_you_sure)}, class: 'btn btn-danger btn-xs'
44
- end
45
-
46
- def form_submit(f)
47
- f.actions do
48
- f.action :submit, :button_html => {:class => "btn btn-primary", :disable_with => t('wait', default: 'Wait...')}
49
- end
50
- end
51
-
52
- ##
53
- # Questa funzione serve per essere sovrascritta nell'helper specializzato del controller
54
- def index_print_column(record, field)
55
- record.send(field)
56
- end
57
-
58
- ##
59
- # Questa funzione serve per stampare il contenuto dell'header
60
- def index_print_column_head(field)
61
- block_given? ? yield(field) : base_class.han(field)
62
- end
63
-
64
- ##
65
- # Questa funzione serve per generare la colonna della tabella
66
- #
67
- # * *Attributes* :
68
- # - colonna
69
- # - tipo di colonna td|th
70
- # - opzionali : hash{record} per fare altro
71
- def index_column_builder(field, column, record: nil)
72
- column_class = "column_#{field}"
73
- column_id=''
74
- if record
75
- column_id = "#{column_class}-#{dom_id(record)}"
76
- end
77
- content_tag column, class: column_class, id: column_id do
78
- yield column_class, column_id
79
- end
80
- end
81
-
82
- def list_button(path)
83
- link_to fa_icon("list fw"), path, class: 'btn btn-default btn-xs'
84
- end
85
-
86
- ##
87
- # Questa funzione serve per essere sovrascritta nell'helper specializzato del controller
88
- # e quindi stampare un determinato campo in modo differente
89
- # si occupa anche di gestire i campi provenienti dalla policy nel caso siano a più livelli con i nested
90
- # prendiamo in considerazione la situazione con has_many :campo=>[] o con :campo=>[:ciao,:pippo,:pluto]
91
- def editing_form_print_field(form, field)
92
- if field.is_a?(Hash)
93
- #devo nestarlo
94
- bf = ActiveSupport::SafeBuffer.new
95
-
96
- field.each do |k, v|
97
- if v.length==0
98
- #caso in cui è un elemento normale, ma che ha una selezione multipla
99
- bf<< editing_form_print_field(form, k)
100
- else
101
- #caso in cui potremmo essere in un campo di multipli elementi con vari valori ognuno
102
- bf<< nest_editing_form_print_field(form, k, v)
103
- end
104
- end
105
- bf
106
- else
107
- form.input field
108
- end
109
- end
110
-
111
- ##
112
- # Questa funzione può essere sovrascritta per gestire in modo personale la renderizzazine dei nested attributes
113
- # * *Attributes* :
114
- # - form -> form di formtastic
115
- # - contenitore -> campo principale
116
- # - campi -> i campi interni
117
- def nest_editing_form_print_field(form, contenitore, campi)
118
- form.semantic_fields_for contenitore do |item|
119
- item.inputs :name => t(".#{form.object.mn}.#{contenitore}", :default => contenitore.to_s.camelcase) do
120
- bf = ActiveSupport::SafeBuffer.new
121
- campi.each do |c|
122
- bf<<editing_form_print_field(item, c)
123
- end
124
- bf
125
- end
126
- end
127
- end
128
-
129
- ##
130
- # Per divisione in celle della form
131
- #
132
- def cell_column_class(field)
133
- "col-md-12"
134
- end
135
-
136
-
137
- ##
138
- # Funzione che visualizza il caricamento e l'immagine caricata precedente se presente
139
- #
140
- # * *Args* :
141
- # - form
142
- # - attribute
143
- # * *Returns* :
144
- # - ActiveSupport:SafeBuffer
145
- #
146
- def image_show_upload(form, attribute)
147
-
148
- buff = ActiveSupport::SafeBuffer.new
149
-
150
- buff<<form.label(attribute)
151
-
152
- buff<<content_tag(:div, class: 'row') do
153
- tmp = ActiveSupport::SafeBuffer.new
154
-
155
-
156
- tmp << content_tag(:div, class: "col-md-5") do
157
- form.input attribute, :label => false
158
- end
159
-
160
- if form.object.send(attribute).exists?
161
- tmp << content_tag(:div, class: "col-md-2 col-lg-5") do
162
- link_to image_tag(form.object.send(attribute).url(:original), class: 'img-thumbnail logo-original'), form.object.send(attribute).url
163
- end
164
- end
165
-
166
- tmp
167
- end
168
-
169
-
170
- end
171
-
172
-
173
- def semantic_form_attributes(obj)
174
- obj
175
- end
176
-
177
-
178
- ##
179
- # Helper per visualizzare l'alert del destroy
180
- def destroy_link_to(path, options)
181
- link_to t('.destroy'), path,
182
- :method => :delete,
183
- :class => "btn",
184
- :confirm => t('.destroy_confirm.body', :item => options[:item]),
185
- "data-confirm-fade" => true,
186
- "data-confirm-title" => t('.destroy_confirm.title', :item => options[:item]),
187
- "data-confirm-cancel" => t('.destroy_confirm.cancel', :item => options[:item]),
188
- "data-confirm-cancel-class" => "btn-cancel",
189
- "data-confirm-proceed" => t('.destroy_confirm.proceed', :item => options[:item]),
190
- "data-confirm-proceed-class" => "btn-danger"
191
- end
192
-
193
10
  end
194
11
  end
@@ -1,8 +1,9 @@
1
- require 'kono_utils/search_attribute'
1
+ require 'active_type'
2
+
2
3
  module KonoUtils
3
4
  ##
4
5
  # Classe base per i form di ricerca nel sistema
5
- class BaseSearch < VirtualModel
6
+ class BaseSearch < ::ActiveType::Object
6
7
 
7
8
  class UndefinedSearchModel < StandardError
8
9
  def initialize(msg = 'Definire nella classe, attraverso set_search_model, il modello da utilizzare come base per la ricerca')
@@ -10,9 +11,20 @@ module KonoUtils
10
11
  end
11
12
  end
12
13
 
14
+ class UndefinedSearchModelScope < StandardError
15
+ def initialize(model)
16
+ super("La classe #{model.name} non ha definito lo scope search")
17
+ end
18
+ end
19
+
13
20
  class_attribute :_search_model, :_search_attributes, instance_writer: false
14
21
  attr_accessor :scope
15
22
 
23
+ class_attribute :search_form_builder_class, default: nil
24
+
25
+ #@return [KonoUtils::SearchFormBuilder] istanziato
26
+ attr_reader :search_form_builder
27
+
16
28
  define_model_callbacks :set_scope, :make_query
17
29
 
18
30
  ##
@@ -22,6 +34,18 @@ module KonoUtils
22
34
  self._search_model = model
23
35
  end
24
36
 
37
+ ##
38
+ # Restituisce il modello di ricerca
39
+ def search_model
40
+ self.class._search_model
41
+ end
42
+
43
+ ##
44
+ # alias method di classe
45
+ def self.search_model
46
+ self._search_model
47
+ end
48
+
25
49
  ##
26
50
  # Definisce gli attributi da utilizzare per la ricerca
27
51
  # passandogli un hash finale si possono passare parametri di default
@@ -69,39 +93,25 @@ module KonoUtils
69
93
 
70
94
  attr_accessor(a.to_sym)
71
95
 
72
- # instance_variable_set "@#{a}".to_sym, nil
73
- #
74
- # unless method_defined? a.to_sym
75
96
  define_method(a.to_sym) do
76
97
  run_callbacks "search_attr_#{a}" do
77
- # logger.debug { "Chiamata a metodo virtuale #{a} " }
78
98
  instance_variable_get "@#{a}".to_sym
79
99
  end
80
100
  end
81
- # end
82
- #
83
- # unless method_defined? "#{a}=".to_sym
84
101
  define_method("#{a}=".to_sym) do |*args|
85
102
  run_callbacks "search_attr_#{a}_set" do
86
- # logger.debug { "Chiamata a metodo virtuale #{a}= -> #{args.inspect}" }
87
103
  instance_variable_set "@#{a}".to_sym, *args
88
104
  end
89
105
  end
90
- # end
91
106
 
92
107
 
93
108
  #Definisco delle callbacks per ogni attributo
94
109
  define_model_callbacks "search_attr_#{a}".to_sym, "search_attr_#{a}_set".to_sym
95
- self._search_attributes += [KonoUtils::SearchAttribute.new(a, options)]
110
+ self._search_attributes += [SearchAttribute.new(a, options)]
96
111
  end
97
112
  self._search_attributes.uniq!
98
113
  end
99
114
 
100
- ##
101
- # Restituisce il modello di ricerca
102
- def search_model
103
- self.class._search_model
104
- end
105
115
 
106
116
  ##
107
117
  # Attributi di ricerca
@@ -111,15 +121,18 @@ module KonoUtils
111
121
 
112
122
  def initialize(attributes = nil)
113
123
  raise UndefinedSearchModel if search_model.nil?
124
+ raise UndefinedSearchModelScope.new(search_model) unless search_model.respond_to? :search
114
125
  super
115
126
  self.scope = self.class._search_model
127
+ search_builder_class = search_form_builder_class || KonoUtils.configuration.search_form_builder
128
+ @search_form_builder = search_builder_class.new(self)
116
129
  end
117
130
 
118
131
 
119
132
  ##
120
133
  # deve indicarmi se i dati della ricerca sono stati inseriti
121
134
  def data_loaded?
122
- get_query_params.length>0
135
+ get_query_params.length > 0
123
136
  end
124
137
 
125
138
  ##
@@ -147,7 +160,7 @@ module KonoUtils
147
160
  def get_query_params
148
161
  out = {}
149
162
  search_attributes.each do |val|
150
- out[val.field]=self.send(val.field) unless self.send(val.field).blank?
163
+ out[val.field] = self.send(val.field) unless self.send(val.field).blank?
151
164
  end
152
165
 
153
166
  out