kono_utils 0.15.15 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +17 -78
  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/initializers/mysql.rb +2 -2
  8. data/config/locales/it.yml +3 -1
  9. data/lib/generators/kono_utils/install/install_generator.rb +44 -0
  10. data/lib/generators/templates/base_editing_controller.template +3 -0
  11. data/lib/generators/templates/base_editing_helper.template +3 -0
  12. data/lib/generators/templates/base_editing_policy.template +4 -0
  13. data/lib/generators/templates/initializer.rb +3 -1
  14. data/lib/kono_utils.rb +29 -18
  15. data/lib/kono_utils/application_core_helper.rb +524 -0
  16. data/lib/kono_utils/application_enum_helper.rb +53 -0
  17. data/lib/kono_utils/application_helper.rb +4 -578
  18. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  19. data/lib/kono_utils/base_editing_helper.rb +3 -186
  20. data/lib/kono_utils/base_search.rb +32 -19
  21. data/lib/kono_utils/concerns.rb +12 -10
  22. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  23. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  24. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  25. data/lib/kono_utils/configuration.rb +18 -0
  26. data/lib/kono_utils/engine.rb +15 -6
  27. data/lib/kono_utils/paginate_proxer.rb +17 -0
  28. data/lib/kono_utils/search_form_builder.rb +24 -0
  29. data/lib/kono_utils/version.rb +1 -1
  30. data/spec/dummy/.gitignore +2 -0
  31. data/spec/dummy/app/assets/config/manifest.js +2 -0
  32. data/spec/dummy/app/assets/javascripts/application.js +2 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  34. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  35. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  36. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  37. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  38. data/spec/dummy/app/models/application_record.rb +5 -0
  39. data/spec/dummy/app/models/user.rb +2 -0
  40. data/spec/dummy/app/policies/application_policy.rb +49 -0
  41. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  42. data/spec/dummy/app/policies/user_policy.rb +23 -0
  43. data/spec/dummy/bin/rails +1 -1
  44. data/spec/dummy/bin/setup +20 -13
  45. data/spec/dummy/bin/update +31 -0
  46. data/spec/dummy/bin/yarn +11 -0
  47. data/spec/dummy/config/application.rb +15 -17
  48. data/spec/dummy/config/environment.rb +1 -1
  49. data/spec/dummy/config/environments/development.rb +31 -11
  50. data/spec/dummy/config/environments/production.rb +26 -16
  51. data/spec/dummy/config/environments/test.rb +10 -6
  52. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  53. data/spec/dummy/config/initializers/assets.rb +6 -3
  54. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  55. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  56. data/spec/dummy/config/initializers/kono_utils.rb +5 -0
  57. data/spec/dummy/config/initializers/new_framework_defaults_5_2.rb +38 -0
  58. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  59. data/spec/dummy/config/locales/en.yml +10 -0
  60. data/spec/dummy/config/routes.rb +3 -52
  61. data/spec/dummy/config/storage.yml +34 -0
  62. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  63. data/spec/dummy/db/schema.rb +23 -0
  64. data/spec/dummy/package.json +5 -0
  65. data/spec/dummy/spec/models/user_spec.rb +5 -0
  66. data/spec/dummy/yarn.lock +21 -0
  67. metadata +83 -144
  68. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -481
  69. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  70. data/app/input/bs_aceeditor_input.rb +0 -53
  71. data/app/input/bs_autocomplete_input.rb +0 -60
  72. data/app/input/bs_datepicker_input.rb +0 -16
  73. data/app/input/bs_datetimepicker_input.rb +0 -80
  74. data/app/input/bs_file_download_input.rb +0 -35
  75. data/app/input/bs_image_input.rb +0 -35
  76. data/app/input/bs_label_with_container_input.rb +0 -22
  77. data/app/input/bs_location_picker_input.rb +0 -95
  78. data/app/input/bs_readonly_input.rb +0 -52
  79. data/app/input/bs_timepicker_input.rb +0 -14
  80. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  81. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  82. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  83. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  84. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  85. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  86. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  87. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  88. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  89. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  90. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  91. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  92. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  93. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  94. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  95. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  96. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  97. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  98. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  99. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  100. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  101. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  102. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  103. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  104. data/lib/kono_utils/encoder.rb +0 -47
  105. data/lib/kono_utils/fiscal_code.rb +0 -47
  106. data/lib/kono_utils/params_hash_array.rb +0 -37
  107. data/lib/kono_utils/percentage.rb +0 -60
  108. data/lib/kono_utils/tmp_file.rb +0 -81
  109. data/lib/kono_utils/virtual_model.rb +0 -22
  110. data/lib/tasks/kono_utils_tasks.rake +0 -4
  111. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  112. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -0,0 +1,53 @@
1
+ module KonoUtils
2
+
3
+ ##
4
+ # Racchiudo helpers per gestire gli enum
5
+ module ApplicationEnumHelper
6
+
7
+ ##
8
+ # Genera l'hash da passare come collection alle selectbox, esegue anche la traduzione con locale
9
+ #
10
+ # <%= f.input :usage, :as => :select,
11
+ # :collection => enum_collection(Logo, :usage), :input_html => {:include_blank => true} %>
12
+ #
13
+ # @param [ActiveRecord] model -> ActiveRecord model contenente l'enum
14
+ # @param [Symbol] attribute -> Symbol che identifica l'attributo dell'enum
15
+ # @param [nil,String] variant -> se c'è la variante questa viene inserite _#{variant} dopo il nome del valore
16
+ # @return [Hash]
17
+ def enum_collection(model, attribute, variant=nil)
18
+
19
+ model.send(attribute.to_s.pluralize(2).to_sym).collect {|key, val|
20
+ [enum_translation(model, attribute, key, variant), key]
21
+ }.to_h
22
+ end
23
+
24
+
25
+ ##
26
+ # Si occupa di tradurre un determinato valore di un enum
27
+ #
28
+ # Le traduzioni dentro al locale devono essere fatte in questo modo:
29
+ # it:
30
+ # activerecord:
31
+ # attributes:
32
+ # estimate_before/value:
33
+ # na: NA
34
+ # very_insufficient: 1
35
+ # insufficient: 2
36
+ # sufficient: 3
37
+ # excellent: 4
38
+ # dove in questo caso estimate_before è il modello e value è il nome del campo enum
39
+ #
40
+ # @param model [ActiveRecord::Base] class contenente l'enum
41
+ # @param attribute [Symbol] che identifica l'attributo dell'enum
42
+ # @param variant [nil,String] se c'è la variante questa viene inserite _#{variant} dopo il nome del valore
43
+ # @return [String]
44
+ # @param value [Object] valore
45
+ def enum_translation(model, attribute, value, variant=nil)
46
+ return '' if value.nil?
47
+ variant = "_#{variant}" unless variant.nil?
48
+ model.human_attribute_name("#{attribute}.#{value}#{variant}")
49
+ end
50
+
51
+
52
+ end
53
+ end
@@ -1,585 +1,11 @@
1
1
  module KonoUtils
2
2
  module ApplicationHelper
3
3
 
4
-
5
- def will_paginate_bst(collection)
6
- will_paginate collection, renderer: BootstrapPagination::Rails
7
- end
8
-
9
-
10
- def namespace_content(&block)
11
- content_tag :div, class: "#{(controller.class.name.split("::") + [action_name]).join(" ")}" do
12
- yield
13
- end
14
-
15
- end
16
-
17
- def true_false_label(val)
18
-
19
- if val
20
- icon =fa_icon(:check)
21
- classe='success'
22
- else
23
- classe='danger'
24
- icon =fa_icon(:times)
25
- end
26
-
27
- content_tag(:span, icon, class: "label label-#{classe}")
28
-
29
- end
30
-
31
-
32
- ##
33
- # Genera una modal da riutilizzare per far aspettare determinate operazioni al client
34
- def bootstrap_please_wait
35
- content_tag(:div,
36
- class: 'modal fade',
37
- id: 'processing_wait',
38
- tabindex: "-1",
39
- role: "dialog",
40
- "aria-hidden".to_sym => "true") do
41
- content_tag :div, class: 'modal-dialog modal-sm' do
42
- content_tag :div, class: 'modal-content' do
43
-
44
- buff = ActiveSupport::SafeBuffer.new
45
-
46
- buff << content_tag(:div, class: 'modal-header') do
47
- content_tag(:h4, "Processing...", class: "modal-title")
48
- end
49
-
50
- buff << content_tag(:div, class: 'modal-body') do
51
- content_tag :div, class: "progress" do
52
- content_tag :div, ' ', class: "progress-bar progress-bar-striped active", role: "progressbar", style: "width: 100%"
53
- end
54
- end
55
-
56
- buff
57
- end
58
- end
59
- end
60
- end
61
-
62
-
63
- ##
64
- # Genera la form di ricerca
65
- # * *Args* :
66
- # - search_model -> KonoUtils::BaseSearch
67
- # - args -> Hash with configurations:
68
- # - attributes -> array of symbols for the search, if empty used from search_model
69
- # - reset_path -> path per cui resettare la ricerca, nil
70
- # - form_opts -> opzioni da aggiungere per la form
71
- # - buttons_editor -> Proc chiamata, con il passaggio dell'oggetto della form e
72
- # del ActiveSupport::SafeBuffer con all'interno dei bottoni
73
- # come parametro, deve ritornare
74
- # un ActiveSupport::SafeBuffer a sua volta
75
- # * *Returns* :
76
- # -
77
- #
78
- def search_form(search_model, args={})
79
-
80
- args = {
81
- :attributes => [],
82
- :reset_path => nil,
83
- :form_opts => {},
84
- :field_option => {:wrapper_html => {:class => "col-xs-12 col-sm-6 col-md-4 col-lg-3"}},
85
- :buttons_editor => Proc.new {|form_obj, sb| sb}
86
- }.merge(args)
87
-
88
- base_search_form_wrapper(search_model, {:attributes => args[:attributes], :form_opts => args[:form_opts]}) do |f|
89
-
90
- render :partial => '/application/search_panel.html', locals: {
91
- form: f,
92
- search_model: search_model
93
- }.merge(args)
94
-
95
- end
96
-
97
- end
98
-
99
- class BaseSearchFormWrapper < Struct.new(:formtastic_form, :attributes, :current_user)
100
-
101
- def fields_builder(cfgs={field_options: {}})
102
- form_buffer = ActiveSupport::SafeBuffer.new
103
-
104
- self.attributes.each do |field|
105
-
106
- form_options = field.form_options
107
- if form_options.is_a?(Proc)
108
- form_options = form_options.call(current_user, self.formtastic_form)
109
- end
110
-
111
- form_buffer << self.formtastic_form.input(field.field, cfgs[:field_options].merge(form_options))
112
- end
113
-
114
- form_buffer
115
- end
116
- end
117
-
118
- ##
119
- # Utility interna che si occupa della logica minima per generare la il form di ricerca
120
- def base_search_form_wrapper(search_model, args={:attributes => [], :form_opts => {}})
121
- attributes = args[:attributes] || {}
122
- form_opts = args[:form_opts] || {}
123
- if attributes.length==0
124
- attributes = search_model.search_attributes
125
- end
126
-
127
- form_opts = {method: :get, :html => {autocomplete: 'off'}}.merge(form_opts)
128
-
129
- semantic_form_for search_model, form_opts do |f|
130
- yield BaseSearchFormWrapper.new(f, attributes, @current_user)
131
- end
132
- end
133
-
134
-
135
- def title_mod(model)
136
- "#{t(:edit)} #{model.mn}"
137
- end
138
-
139
- def title_new(model)
140
- "#{t(:new)} #{model.mn}"
141
- end
142
-
143
- def title_newa(model)
144
- "#{t(:newa)} #{model.mn}"
145
- end
146
-
147
- def title_del(model)
148
- "#{t(:del)} #{model.mn}"
149
- end
150
-
151
-
152
- ##
153
- # Genera l'hash da passare come collection alle selectbox, esegue anche la traduzione con locale
154
- #
155
- # <%= f.input :usage, :as => :select,
156
- # :collection => enum_collection(Logo, :usage), :input_html => {:include_blank => true} %>
157
- #
158
- # * *Args* :
159
- # - model -> ActiveRecord model contenente l'enum
160
- # - attribute -> Symbol che identifica l'attributo dell'enum
161
- # - variant -> se c'è la variante questa viene inserite _#{variant} dopo il nome del valore
162
- # * *Returns* :
163
- # - Hash
164
- #
165
- def enum_collection(model, attribute, variant=nil)
166
-
167
- model.send(attribute.to_s.pluralize(2).to_sym).collect {|key, val|
168
- [enum_translation(model, attribute, key, variant), key]
169
- }.to_h
170
- end
171
-
172
-
173
- ##
174
- # Si occupa di tradurre un determinato valore di un enum
175
- # - model -> ActiveRecord model contenente l'enum
176
- # - attribute -> Symbol che identifica l'attributo dell'enum
177
- # - variant -> se c'è la variante questa viene inserite _#{variant} dopo il nome del valore
178
- #
179
- # * *Returns* :
180
- # - String
181
- #
182
- def enum_translation(model, attribute, value, variant=nil)
183
- ApplicationHelper.enum_translation(model, attribute, value, variant)
184
- end
185
-
186
-
187
- ##
188
- # Le traduzioni dentro al locale devono essere fatte in questo modo:
189
- # it:
190
- # activerecord:
191
- # attributes:
192
- # estimate_before/value:
193
- # na: NA
194
- # very_insufficient: 1
195
- # insufficient: 2
196
- # sufficient: 3
197
- # excellent: 4
198
- #
199
- # dove in questo caso estimate_before è il modello e value è il nome del campo enum
200
- #
201
- def self.enum_translation(model, attribute, value, variant=nil)
202
- return '' if value.nil?
203
- variant = "_#{variant}" unless variant.nil?
204
- model.human_attribute_name("#{attribute}.#{value}#{variant}")
205
- end
206
-
207
-
208
- ##
209
- # Helper per generare una modal con all'interno un form
210
- # Utilizzare passando un block il quale riceve come parametro la form di formtastic
211
- # possibile passare anche una proc in buttons_proc per scrivere in modo differente i bottoni nella modal,
212
- # alla proc viene passato il solito form di formtastic e il bottone standard di chiusura
213
- #
214
- def modal_form_generator(args = {})
215
-
216
- args = {
217
- id: 'modal',
218
- class: '',
219
- title: 'Titolo',
220
- form_cfgs: [],
221
- buttons_proc: Proc.new do |f, default_close_btn|
222
- default_close_btn +
223
- f.action(:submit, button_html: {class: 'btn btn-primary'}, :label => :save_and_close)
224
- end
225
- }.merge(args)
226
-
227
- raise 'Passare le configurazioni per la form' if args[:form_cfgs]==[]
228
-
229
- default_close_btn = content_tag(:button, 'Chiudi', type: 'button', class: 'btn btn-default', data: {dismiss: "modal"})
230
-
231
- content_tag(:div,
232
- class: "modal fade kono_modal_form",
233
- id: args[:id],
234
- tabindex: "-1",
235
- role: "dialog",
236
- "aria-hidden".to_sym => "true") do
237
- content_tag :div, class: 'modal-dialog' do
238
- semantic_form_for(*args[:form_cfgs]) do |f|
239
- content_tag :div, class: 'modal-content' do
240
-
241
- buff = ActiveSupport::SafeBuffer.new
242
-
243
- buff << content_tag(:div, class: 'modal-header') do
244
- content_tag(:button, raw("&times;"), type: "button", class: "close", data: {dismiss: 'modal'}, "aria-hidden".to_sym => "true") +
245
- content_tag(:h4, args[:title], class: "modal-title")
246
- end
247
-
248
- buff << content_tag(:div, class: 'modal-body') do
249
- yield f
250
- end
251
-
252
- buff << content_tag(:div, class: 'modal-footer') do
253
- args[:buttons_proc].call(f, default_close_btn)
254
- end
255
-
256
- buff
257
- end
258
- end
259
- end
260
- end
261
-
262
- end
263
-
264
-
265
- ##
266
- # Genera il bottone per editazione con una modal del contenuto,
267
- # gli viene passato un block contenente la modal da lanciare per l'editazione,
268
- # solitamente generata con modal_form_generator.
269
- # come parametri viene passato l'id del target che si aspetta di richiamare
270
- #
271
- # ES:
272
- # modal_edit_button do |id|
273
- # render 'tikal_core/people/person_contacts/modal_form', :contact => contact, :id => id %>
274
- # end
275
- #
276
- # Attributes:
277
- # align: left|rigth
278
- # updatable_content: elemento da rimpiazzare con il partial restituito
279
- # class: classi aggiuntive per selezionare meglio il bottone
280
- # btn_class: classi aggiuntive del bottone
281
- # bnt_icon: Symbol che identifica che icona utilizzare per il bottone
282
- #
283
- #
284
- def modal_edit_button(*args, &block)
285
-
286
- options = {
287
- align: 'left',
288
- updatable_content: '',
289
- class: '',
290
- btn_class: '',
291
- bnt_icon: :edit
292
- }.merge(args.extract_options!)
293
-
294
- id = "#{SecureRandom.hex}"
295
-
296
-
297
- content_tag :div, class: "kono_edit_button align-#{options[:align]} #{options[:class]}", :data => {updatable_content: options[:updatable_content]} do
298
- buffer = ActiveSupport::SafeBuffer.new
299
-
300
- buffer << button_tag(data: {toggle: 'modal', target: "##{id}"}, class: "btn btn-default btn-xs #{options[:btn_class]}") {fa_icon(options[:bnt_icon])}
301
-
302
- buffer << capture do
303
- block.call(id)
304
- end
305
-
306
- buffer
4
+ def self.included(base)
5
+ KonoUtils.configuration.application_helper_includes.each do |m|
6
+ base.send :include, m
307
7
  end
308
8
  end
309
9
 
310
-
311
- ##
312
- # Genera il bottone per la cancellazione di un elemento
313
- #
314
- # modal_delete_button(path, [options])
315
- # path -> resource to delete
316
- # options:
317
- # * confirm : Text to display in modal
318
- # * align : left|right
319
- # * callback_remove : id dell'elemento da rimuove una volta avuto successo il javascript di cancellazione
320
- # * bnt_icon : Symbol che identifica che icona utilizzare per il bottone
321
- def modal_delete_button(*args)
322
- options = {
323
- confirm: 'Sicuri di voler eliminare il record? L\'azione non è annullabile.',
324
- align: 'left',
325
- callback_remove: nil,
326
- bnt_icon: :times
327
- }.merge(args.extract_options!)
328
- path = args[0]
329
-
330
- id = "#{SecureRandom.hex}"
331
-
332
- content_tag :div, class: "tk_delete_button align-#{options[:align]}" do
333
-
334
- buffer = ActiveSupport::SafeBuffer.new
335
-
336
- buffer<<button_tag(data: {toggle: 'modal', target: "##{id}"}, class: 'btn btn-danger btn-xs') {fa_icon(options[:bnt_icon])}
337
-
338
- buffer<< content_tag(:div,
339
- class: 'modal fade',
340
- id: id,
341
- tabindex: "-1",
342
- role: "dialog",
343
- "aria-hidden".to_sym => "true") do
344
- form_tag(path, method: :delete, data: {callback_remove: options[:callback_remove]}) do
345
- content_tag :div, class: 'modal-dialog' do
346
- content_tag :div, class: 'modal-content' do
347
-
348
- buff = ActiveSupport::SafeBuffer.new
349
-
350
- buff << content_tag(:div, class: 'modal-header') do
351
- tmp_buff = ActiveSupport::SafeBuffer.new
352
- tmp_buff<<button_tag(fa_icon(:times), type: "button", class: "close", data: {dismiss: "modal"}, "aria-hidden".to_sym => true)
353
- tmp_buff<<content_tag(:h4, "Attenzione", class: "modal-title")
354
- tmp_buff
355
- end
356
-
357
- buff << content_tag(:div, options[:confirm], class: 'modal-body text-danger')
358
-
359
- buff << content_tag(:div, class: 'modal-footer') do
360
- button_tag('Annulla', type: "button", class: "btn btn-default", data: {dismiss: "modal"})+
361
- button_tag('Conferma', type: 'submit', class: "btn btn-danger")
362
- end
363
-
364
- buff
365
- end
366
-
367
- end
368
- end
369
- end
370
-
371
- buffer << content_tag(:script, raw("$('##{id} form').kono_delete_button();"), :type => 'text/javascript')
372
-
373
- buffer
374
- end
375
- end
376
-
377
- ##
378
- # Colleziona i mesi per la select box
379
- def month_collection
380
- (1..12).collect {|m| [t('date.month_names')[m].capitalize, m]}
381
- end
382
-
383
-
384
- ##
385
- # Genera una collection degli anni per la select box
386
- # parte da -8 a +1
387
- #
388
- def year_collection(start=-8, last=1)
389
- ((Time.now.year+start)..(Time.now.year+last)).to_a.reverse
390
- end
391
-
392
- module_function :year_collection
393
-
394
-
395
- ##
396
- # Si occupa di generare la visualizzazione dell'exception passata, con informazioni
397
- # aggiuntive se utente è super admin
398
- # * *Args* :
399
- # - exception -> Exception
400
- def bs_rescue_printer(exception)
401
- bff = ActiveSupport::SafeBuffer.new
402
-
403
- bff<< content_tag(:div, class: "alert alert-warning") do
404
- button_tag(raw("&times;"), data: {dismiss: "alert", hidden: "true"}, class: 'close') +
405
- content_tag(:strong, 'Errore') +
406
- " Attenzione, il codice eseguito non è valido, contattare l'amministratore."
407
- end
408
-
409
- if @current_user.is_super_admin?
410
-
411
- bff<<content_tag(:div, class: "panel panel-info") do
412
- tmp = ActiveSupport::SafeBuffer.new
413
- tmp<<content_tag(:div, class: "panel-heading") do
414
- content_tag :h3, "Messagio di Errore: #{exception.message} "
415
- end
416
- tmp<<content_tag(:div, class: "panel-body") do
417
- content_tag :pre, exception.backtrace.join("\n")
418
- end
419
-
420
- tmp
421
- end
422
- end
423
-
424
- bff
425
- end
426
-
427
- ##
428
- #
429
- # * *Args* :
430
- # - int -> Valore intero per definire
431
- # - class -> optional classi aggiuntive
432
- # * *Returns* :
433
- # - content
434
- #
435
- def bs_spacer(space, classe='')
436
- content_tag :div, nil, class: "v-spacer space-x#{space} #{classe}"
437
- end
438
-
439
-
440
- ##
441
- # Costruisce una tabella con i campi utili alla creazione di elementi multipli
442
- #
443
- # Attributes:
444
- # form -> la form proveniente da formtastic
445
- # field -> il campo referente dell'associazione
446
- # fields -> elenco di campi su cui costruire le varie colonne
447
- # options -> Hash di opzioni:
448
- # :disable_duplication => [false] : server per disabilitare il bottone della duplicazione
449
- #
450
- # se gli si passa un blocco allora possiamo elaborare la costruzione dei differenti campi in modo personale
451
- # al blocco viene passato la classe di formtastic della form, il campo, e un blocco contenente la proc per
452
- # elaborare i campi in modo standard
453
- #
454
- # multiple_elements_table(form, :campo_has_many, [:label, :string_value, :number_value]) do |field, form|
455
- # case field
456
- # when :string_value, :number_value
457
- # form.input field, label: false, input_html: {:autocomplete => 'off', class: 'toggle_value'}
458
- # else
459
- # form.input field, label: false, input_html: {:autocomplete => 'off'}
460
- # end
461
- # end
462
- #
463
- # Traduzioni delle colonne:
464
- #
465
- # modello_iniziale/campo_has_many:
466
- # campo_del_has_many
467
- #
468
- #
469
- def multiple_elements_table(*params)
470
- options = params.extract_options!
471
-
472
- options = {:disable_duplication => false}.merge(options)
473
-
474
- form = params[0]
475
- field = params[1]
476
- fields = params[2]
477
-
478
- semantic_form_nested=[field]
479
-
480
- #inserimento logiche per scope su elenco elementi multipli
481
- unless options[:scope].nil?
482
- semantic_form_nested<<options[:scope]
483
- end
484
-
485
- content_tag :table, class: "table table-bordered" do
486
-
487
- b = ActiveSupport::SafeBuffer.new
488
-
489
- b<< content_tag(:thead) do
490
- content_tag :tr do
491
- c = ActiveSupport::SafeBuffer.new
492
-
493
- fields.each do |f|
494
- ::Rails.logger.debug {form.object.class.inspect}
495
- ::Rails.logger.debug {field}
496
- ::Rails.logger.debug {f.inspect}
497
- c<<content_tag(:th, form.object.class.human_attribute_name("#{field}.#{f}"), class: "multi_tab_#{f}")
498
- end
499
- unless options[:disable_duplication]
500
- c<<content_tag(:td, nil)
501
- end
502
-
503
- c
504
- end
505
- end
506
-
507
- b<<content_tag(:tbody) do
508
- form.semantic_fields_for(*semantic_form_nested) do |measure|
509
-
510
- default_execution = Proc.new {|field| measure.input field, :label => false}
511
-
512
- content_tag :tr, class: "form-inline list riga_misura" do
513
-
514
- d = ActiveSupport::SafeBuffer.new
515
-
516
- fields.each do |f|
517
- d<<content_tag(:td, class: "multi_tab_#{f}") do
518
-
519
- if block_given?
520
- yield(f, measure, default_execution)
521
- else
522
- default_execution.call(f)
523
- end
524
-
525
- end
526
- end
527
-
528
- unless options[:disable_duplication]
529
- d << content_tag(:td) do
530
-
531
- link_to "#", class: 'btn btn-xs btn-default add_one_more' do
532
-
533
- h = ActiveSupport::SafeBuffer.new
534
- h<< fa_icon(:plus)
535
- h<< measure.input(:_destroy, as: :hidden)
536
-
537
- h
538
- end
539
-
540
- end
541
- end
542
-
543
- d
544
- end
545
- end
546
- end
547
-
548
- b
549
- end
550
- end
551
-
552
-
553
- ##
554
- # Genera un'albero con bootstrap-tree
555
- # deve ricevere un array di dati da trasformare in json.
556
- # per come scrivere il parametro data vedi
557
- # https://github.com/jonmiles/bootstrap-treeview
558
- #
559
- def bs_tree(data)
560
-
561
- id_div = SecureRandom.hex(10)
562
-
563
- tmp = ActiveSupport::SafeBuffer.new
564
-
565
- tmp<< content_tag(:div, nil, id: id_div, class: 'bs_tree_list')
566
-
567
- tmp<< javascript_tag do
568
- raw "$('##{id_div}').treeview({data: #{data.to_json}});"
569
- end
570
-
571
- end
572
-
573
- ##
574
- # Stampa una data con il default delle date se questa non è nil
575
- #
576
- def print_rescue_date(date)
577
- unless date.nil?
578
- return l date.to_date
579
- end
580
- ''
581
- end
582
-
583
-
584
10
  end
585
- end
11
+ end