kono_utils 0.15.5

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 +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +442 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/kono_utils/utilities.coffee +456 -0
  6. data/app/assets/stylesheets/kono_utils/utils.css.scss +43 -0
  7. data/app/controllers/kono_utils/change_log_controller.rb +6 -0
  8. data/app/input/bs_aceeditor_input.rb +53 -0
  9. data/app/input/bs_autocomplete_input.rb +60 -0
  10. data/app/input/bs_datepicker_input.rb +16 -0
  11. data/app/input/bs_datetimepicker_input.rb +80 -0
  12. data/app/input/bs_file_download_input.rb +35 -0
  13. data/app/input/bs_image_input.rb +35 -0
  14. data/app/input/bs_label_with_container_input.rb +22 -0
  15. data/app/input/bs_location_picker_input.rb +95 -0
  16. data/app/input/bs_readonly_input.rb +52 -0
  17. data/app/input/bs_timepicker_input.rb +14 -0
  18. data/app/policies/kono_utils/base_editing_policy_concern.rb +27 -0
  19. data/app/views/kono_utils/base_editing/_edit.html.erb +3 -0
  20. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +3 -0
  21. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +3 -0
  22. data/app/views/kono_utils/base_editing/_form.html.erb +15 -0
  23. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +2 -0
  24. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +3 -0
  25. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +3 -0
  26. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  27. data/app/views/kono_utils/base_editing/_new.html.erb +3 -0
  28. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +3 -0
  29. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +3 -0
  30. data/app/views/kono_utils/base_editing/_search_form.html.erb +1 -0
  31. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +1 -0
  32. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +1 -0
  33. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +1 -0
  34. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +1 -0
  35. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +1 -0
  36. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +1 -0
  37. data/app/views/kono_utils/base_editing/application/edit.html.erb +1 -0
  38. data/app/views/kono_utils/base_editing/application/new.html.erb +1 -0
  39. data/app/views/kono_utils/base_editing/edit.html.erb +1 -0
  40. data/app/views/kono_utils/base_editing/index.html.erb +36 -0
  41. data/app/views/kono_utils/base_editing/new.html.erb +1 -0
  42. data/app/views/kono_utils/change_log/index.html.erb +3 -0
  43. data/config/initializers/mysql.rb +12 -0
  44. data/config/initializers/time.rb +12 -0
  45. data/config/locales/it.yml +18 -0
  46. data/lib/generators/kono_utils/install/install_generator.rb +24 -0
  47. data/lib/generators/templates/initializer.rb +3 -0
  48. data/lib/kono_utils.rb +41 -0
  49. data/lib/kono_utils/application_helper.rb +625 -0
  50. data/lib/kono_utils/base_editing_helper.rb +194 -0
  51. data/lib/kono_utils/base_search.rb +173 -0
  52. data/lib/kono_utils/concerns.rb +10 -0
  53. data/lib/kono_utils/concerns/active_record_translation.rb +47 -0
  54. data/lib/kono_utils/concerns/base_editing.rb +195 -0
  55. data/lib/kono_utils/concerns/base_modals.rb +97 -0
  56. data/lib/kono_utils/concerns/success_message.rb +25 -0
  57. data/lib/kono_utils/encoder.rb +55 -0
  58. data/lib/kono_utils/engine.rb +13 -0
  59. data/lib/kono_utils/fiscal_code.rb +47 -0
  60. data/lib/kono_utils/params_hash_array.rb +37 -0
  61. data/lib/kono_utils/percentage.rb +60 -0
  62. data/lib/kono_utils/search_attribute.rb +57 -0
  63. data/lib/kono_utils/tmp_file.rb +81 -0
  64. data/lib/kono_utils/version.rb +3 -0
  65. data/lib/kono_utils/virtual_model.rb +22 -0
  66. data/lib/tasks/kono_utils_tasks.rake +4 -0
  67. data/spec/dummy/README.rdoc +28 -0
  68. data/spec/dummy/Rakefile +6 -0
  69. data/spec/dummy/app/assets/images/.keep +0 -0
  70. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  71. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  72. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  73. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  74. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  75. data/spec/dummy/app/mailers/.keep +0 -0
  76. data/spec/dummy/app/models/.keep +0 -0
  77. data/spec/dummy/app/models/concerns/.keep +0 -0
  78. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  79. data/spec/dummy/bin/bundle +3 -0
  80. data/spec/dummy/bin/rails +4 -0
  81. data/spec/dummy/bin/rake +4 -0
  82. data/spec/dummy/bin/setup +29 -0
  83. data/spec/dummy/config.ru +4 -0
  84. data/spec/dummy/config/application.rb +32 -0
  85. data/spec/dummy/config/boot.rb +5 -0
  86. data/spec/dummy/config/database.yml +25 -0
  87. data/spec/dummy/config/environment.rb +5 -0
  88. data/spec/dummy/config/environments/development.rb +41 -0
  89. data/spec/dummy/config/environments/production.rb +79 -0
  90. data/spec/dummy/config/environments/test.rb +42 -0
  91. data/spec/dummy/config/initializers/assets.rb +11 -0
  92. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  93. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  94. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  95. data/spec/dummy/config/initializers/inflections.rb +16 -0
  96. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  97. data/spec/dummy/config/initializers/session_store.rb +3 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +23 -0
  100. data/spec/dummy/config/routes.rb +56 -0
  101. data/spec/dummy/config/secrets.yml +22 -0
  102. data/spec/dummy/lib/assets/.keep +0 -0
  103. data/spec/dummy/log/.keep +0 -0
  104. data/spec/dummy/public/404.html +67 -0
  105. data/spec/dummy/public/422.html +67 -0
  106. data/spec/dummy/public/500.html +66 -0
  107. data/spec/dummy/public/favicon.ico +0 -0
  108. data/spec/lib/kono_utils/fiscal_code_spec.rb +56 -0
  109. data/spec/rails_helper.rb +53 -0
  110. data/spec/spec_helper.rb +92 -0
  111. data/vendor/assets/javascripts/EventEmitter.js +473 -0
  112. metadata +425 -0
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'KonoUtils'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,456 @@
1
+ #= require underscore
2
+ #= require EventEmitter
3
+ #= require moment
4
+ #= require bootstrap-datetimepicker
5
+ #= require moment/it
6
+ #= require bootstrap-treeview
7
+
8
+
9
+ @Kono = @Kono || {};
10
+
11
+ @Kn = @Kono
12
+
13
+ ##
14
+ # http://stackoverflow.com/questions/8730859/classes-within-coffeescript-namespace
15
+ # Funzione che si occupa di costruire il namespace se non presente e passarlo come risultato
16
+ # la funzione si aspetta una stringa divisa da punti che identificano i vari livelli di namespace
17
+ # Es: @Kn.ns 'Kn.admin.iseeprices', (exports)->
18
+ # exports.Form = Form
19
+ # exports.attributi_vari = 'ciao'
20
+ # ovviamente senza cancellare i precedenti livelli
21
+
22
+ @Kn.ns = (target, name, block) ->
23
+ if arguments.length < 3
24
+ tmp = (if typeof exports isnt 'undefined' then exports else window)
25
+ [target, name, block] = [tmp, arguments...]
26
+ top = target
27
+ target = target[item] or= {} for item in name.split '.'
28
+ block target, top
29
+
30
+
31
+ ###
32
+ Si occupa di eseguire il blocco nel caso in cui siamo nel namespace di vista,
33
+ o che sia presente tale namespace.
34
+ eseguo ovviamente il tutto all'interno di un $-> per essere sicuro che la pagina sia caricata
35
+ Viene attaccanto anche un evento per ascoltare i possibili eventi di hashchange di jquery ui
36
+ per ascoltare se una nuova pagina viene inserita.
37
+ ES:
38
+ @Kn.view_ns '.Alim.Admin.IseepricesController.edit', (namespace)->
39
+ fai qualcosa solo se esiste tale namespace
40
+
41
+ ###
42
+ @Kn.view_ns = (selector, block) ->
43
+ $ ->
44
+ if $(selector).length > 0
45
+ block(selector)
46
+ else
47
+ # attacco ascoltatore event haschanged
48
+ $(window).on 'hashchange', ->
49
+ block(selector)
50
+
51
+
52
+ ###
53
+ Singleton per avere una modal da utilizzare
54
+ funziona attraverso helper bootstrap_please_wait
55
+ ###
56
+ @Kn.show_wait = ->
57
+ $('#processing_wait').modal()
58
+
59
+ @Kn.hide_wait = ->
60
+ $('#processing_wait').modal('hide')
61
+ #forzo eliminazione di tutti i fade
62
+ $('.modal-backdrop.fade.in').remove()
63
+
64
+
65
+ ##
66
+ # A tutte le form aggiungo l'autocomplete ad off
67
+ $ ->
68
+ $('form').prop('autocomplete', 'off')
69
+
70
+
71
+ ##
72
+ # picker = new Kn.utilities.DateTimePicker(
73
+ # selector: _.map(view_namespace, (cls)-> "#{cls} #date_time_picker_documents_search_data").join(",")
74
+ # server_format: "YYYY-MM-DDTHH:mm:ss+Z"
75
+ # )
76
+ # picker.initialize()
77
+ #
78
+ class DateTimePicker
79
+
80
+ defaults = server_format: "YYYY-MM-DD HH:mm:ss Z",
81
+ format: 'DD/MM/YYYY',
82
+ server_match: /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} .$/,
83
+ locale: 'it'
84
+
85
+ constructor: (options = {}) ->
86
+ {@selector, @server_format, @format, @server_match, @locale} = _.extend defaults, options
87
+ @input_date = @parse_input_value()
88
+
89
+ initialize: ->
90
+ if @input_date
91
+ val = @input_date
92
+ val = @input_date.format(@format) if _.isFunction(@input_date.format)
93
+ $(@selector).find("input").val(val)
94
+
95
+ $(@selector).datetimepicker(@picker_configs())
96
+
97
+ picker_configs: ->
98
+ {
99
+ format: @format,
100
+ locale: @locale
101
+ }
102
+
103
+ parse_input_value: ->
104
+ value = $(@selector).find("input").attr('value')
105
+ unless value == '' or _.isUndefined(value)
106
+ if @server_match.test(value)
107
+ return moment(value, @server_format)
108
+ else
109
+ return value
110
+ false
111
+
112
+
113
+ ##
114
+ # Definisce l'elemento associato alla data finale di un range di date
115
+ set_end: (@end_pick)->
116
+ $(@selector).data("DateTimePicker").maxDate(@end_pick.input_date) if @end_pick.input_date
117
+
118
+ $("#{@end_pick.selector}").on "dp.change", (e) =>
119
+ $(@selector).data("DateTimePicker").maxDate(e.date)
120
+
121
+ ##
122
+ # Definisce l'elemento associato alla data iniziale di un range di date
123
+ set_start: (@start_pick)->
124
+ $(@selector).data("DateTimePicker").minDate(@start_pick.input_date) if @start_pick.input_date
125
+
126
+ $("#{@start_pick.selector}").on "dp.change", (e) =>
127
+ $(@selector).data("DateTimePicker").minDate(e.date)
128
+
129
+
130
+ @Kn.ns 'Kn.utilities', (exports)->
131
+ exports.DateTimePicker = DateTimePicker
132
+
133
+ class TimePicker extends DateTimePicker
134
+ defaults = server_format: "HH:mm",
135
+ format: 'HH:mm',
136
+ server_match: /[0-9]{2}:[0-9]{2} .$/
137
+
138
+ picker_configs: ->
139
+ _.extend super(), {format: 'HH:mm'}
140
+
141
+
142
+ @Kn.ns 'Kn.utilities', (exports)->
143
+ exports.TimePicker = TimePicker
144
+
145
+
146
+ ##
147
+ # Eventi generali Jquery
148
+ $ ->
149
+ $('.collapse_search').click (e) ->
150
+ e.preventDefault();
151
+ $('.search_panel .collapsible_panel').slideToggle()
152
+ $('.search_panel .collapsible_panel').slideUp() unless $('.search_panel .collapsible_panel.uncollapsed').length > 0
153
+
154
+
155
+ ## Trasformare form bootstrap da label posizionate sopra a input a sinistra
156
+ # Default:
157
+ # label_cls: 'col-sm-2'
158
+ # wrapp_cls: 'col-sm-10'
159
+ $.fn.extend
160
+ bs3_form_inline: (options)->
161
+ settings =
162
+ label_cls: 'col-sm-2'
163
+ wrapp_cls: 'col-sm-10'
164
+
165
+ settings = $.extend settings, options
166
+ return @each () ->
167
+ $(this).find('.form-group .form-label').addClass settings.label_cls
168
+ $(this).find('.form-group .form-wrapper').addClass settings.wrapp_cls
169
+
170
+
171
+ duplicate_button_toggle = (btn)->
172
+ if $(btn.parentNode).find('.remove_row,.add_one_more').length == 1
173
+ if $(btn.parentNode).find('.remove_row').length == 0
174
+ rem_class = 'add_one_more'
175
+ add_class = 'remove_row'
176
+ ico_rem_class = 'fa-plus'
177
+ ico_add_class = 'fa-minus'
178
+ if $(btn.parentNode).find('.add_one_more').length == 0
179
+ rem_class = 'remove_row'
180
+ add_class = 'add_one_more'
181
+ ico_rem_class = 'fa-minus'
182
+ ico_add_class = 'fa-plus'
183
+
184
+ $(btn).clone().appendTo(btn.parentNode).
185
+ removeClass(rem_class).
186
+ addClass(add_class).
187
+ find('.fa').
188
+ removeClass(ico_rem_class).
189
+ addClass(ico_add_class)
190
+
191
+ elaborate_buttons = (tabella)->
192
+ # numero_elementi = $(tabella).find('.add_one_more').length
193
+ $(tabella).find('.add_one_more').each (index, ele)->
194
+ duplicate_button_toggle(ele)
195
+ if $(tabella).find('tr:not(.multiple_table_remove_row) .remove_row').length == 1
196
+ $(tabella).find('tr:not(.multiple_table_remove_row) .remove_row').first().remove()
197
+
198
+
199
+ ## Gestione elementi multipli
200
+ $.fn.extend
201
+ multiple_table: (options) ->
202
+ # settings =
203
+ # label: ".form-label"
204
+ # content: ".form-wrapper"
205
+ #
206
+ # settings = $.extend settings, options
207
+ return @each () ->
208
+ tabella = @
209
+ elaborate_buttons(tabella)
210
+
211
+
212
+ $(tabella).on 'click', '.remove_row', (e)->
213
+ e.preventDefault()
214
+ $(@).closest('tr').hide().addClass('multiple_table_remove_row')
215
+ $(@).find('[type="hidden"]').val('true')
216
+ elaborate_buttons(tabella)
217
+
218
+ $(tabella).on 'click', '.add_one_more', (e)->
219
+ e.preventDefault()
220
+ row = $(@).closest('tr').clone(false, true)
221
+ uid = $(@).closest('tbody').find('tr').length
222
+ $(row).find('input,select').val('').each ->
223
+ name = $(@).attr('name').replace(/\[[0-9]+\]/, "[#{uid}]")
224
+ $(@).attr('name', name)
225
+ $(@).removeAttr('disabled')
226
+
227
+ row.appendTo($(@).closest('tbody'))
228
+ elaborate_buttons(tabella)
229
+
230
+ ##fine
231
+
232
+ ## Gestione bottone di cancellazione
233
+ # Precedentemente alla rimozione dell'elemento viene
234
+ # lanciato un evento che notifica tale cancellazione "component_removed"
235
+ $.fn.extend
236
+ kono_delete_button: ()->
237
+ return @each () ->
238
+ $(this).on 'submit', (e) ->
239
+ e.preventDefault()
240
+ form = $(this)
241
+ form.closest('.modal').modal('hide')
242
+ $.ajax
243
+ url: form.prop('action')
244
+ data: form.serialize()
245
+ method: 'DELETE'
246
+ success: (data)->
247
+ $('.modal-backdrop').remove() #rimuovo la modal
248
+ $('body').removeClass('modal-open') #rimuovo la classe che blocca
249
+ if data.success
250
+ base_component = $(form.data('callbackRemove'))
251
+ base_component.trigger('component_removed', [form.data('callbackRemove'), data]);
252
+ base_component.hide('fast').remove()
253
+
254
+
255
+ ##
256
+ # Classe per la gestione delle form Modal
257
+ #
258
+ # Eventi:
259
+ # close_modal -> self
260
+ # rescue_invalid_content -> self,response,jquery(dom modal)
261
+ # success -> ajax_response
262
+
263
+ class ModalForm extends EventEmitter
264
+
265
+ defaults = {success: (->)}
266
+
267
+ constructor: (@modal, options = {}) ->
268
+ super
269
+ {@success} = _.extend defaults, options
270
+ @form = $(@modal).find('form').get(0)
271
+ @modal_id = $(@modal).attr('id')
272
+ @initialize_callbacks()
273
+
274
+ inject_format: (format = 'json')->
275
+ $(@form).append("<input type='hidden' value='#{format}' name='format'>")
276
+
277
+ close_modal: ->
278
+ $(@modal).modal('hide')
279
+ $('.modal-backdrop').remove()
280
+ $('body').removeClass('modal-open')
281
+ $(@form).get(0).reset()
282
+ @emitEvent('close_modal', [@]);
283
+
284
+ rescue_invalid_content: (response)->
285
+ # ricevendo in risposta la modal sostituirò la modal attuale,
286
+ # attacco tutte le opzioni di questa classe.
287
+ @close_modal()
288
+ mod = $(response.partial).appendTo($('body'))
289
+ id = Date.now()
290
+ $(mod).prop('id', id).modal('show')
291
+ modal = new @.__proto__.constructor(mod)
292
+ @propagate_events_on_child(modal)
293
+ @emitEvent('rescue_invalid_content', [@, response, modal])
294
+ return {response: response, modal: modal}
295
+
296
+
297
+ # Si occupa di propagare gli eventi attaccati sul padre pannello sui vari figli
298
+ propagate_events_on_child: (child)->
299
+ events = @_getEvents()
300
+ _.each events, (v, k) =>
301
+ child.on k, =>
302
+ @emitEvent(k, arguments)
303
+
304
+
305
+ initialize_callbacks: ->
306
+ @inject_format()
307
+ $(@form).on 'submit', (e) =>
308
+ Kn.show_wait()
309
+ e.preventDefault()
310
+ $.ajax
311
+ url: $(@form).prop('action')
312
+ method: $(@form).prop('method')
313
+ data: $(@form).serialize()
314
+ success: =>
315
+ @_on_success(arguments)
316
+ error: (xhr) =>
317
+ @_on_error(xhr)
318
+
319
+ ##
320
+ # funzione privata eseguita al success
321
+ _on_success: (args)->
322
+ @close_modal()
323
+ Kn.hide_wait()
324
+ @emitEvent('success', args);
325
+
326
+ _on_error: (xhr)->
327
+ Kn.hide_wait()
328
+ switch parseInt(xhr.status/100)*100
329
+ when 400 then @rescue_invalid_content(xhr.responseJSON)
330
+ when 500 then alert("Attenzione, problemi nello svolgimento dell'operazione contattare amministratore")
331
+
332
+
333
+ @Kn.ns 'Kn.utilities', (exports)->
334
+ exports.ModalForm = ModalForm
335
+
336
+
337
+ class ModalNewButton extends ModalForm
338
+
339
+ ##
340
+ # Funzione per ricaricare la modal
341
+ # Esegue un'ajax alla pagina corrente, ricercando l'elemento con l'id uguale a quello di se stesso,
342
+ # rimpiazza quindi la precedente modal di creazione e riattacca tutti gli eventi al modal appena creato.
343
+ # sucessivamente rimuove l'elemento iniziale e lancia l'evento "self_reloaded" per poter far eventualemnte ulteriori
344
+ # modifiche sul modal appena generato
345
+ self_reload: ()->
346
+ @_self_reload(@)
347
+
348
+ _self_reload: ()->
349
+ Kn.show_wait()
350
+ id = "tmp#{(new Date()).getTime()}"
351
+ $('body').append("<div id='#{id}'></div>")
352
+ $("##{id}").load "#{window.location.href} ##{@modal_id}", ()=>
353
+ ele = $("##{id}>*")
354
+ $(ele).attr('generated_id', id)
355
+ pre_modal = $("##{@modal_id}")
356
+ pre_modal.after(ele)
357
+ modal = new @__proto__.constructor(ele)
358
+ @propagate_events_on_child(modal)
359
+ @emitEvent('self_reloaded', [modal, @])
360
+ pre_modal.remove()
361
+ Kn.hide_wait()
362
+
363
+
364
+ @Kn.ns 'Kn.utilities', (exports)->
365
+ exports.ModalNewButton = ModalNewButton
366
+
367
+
368
+ ###
369
+ Classe che gestisce la UI per il bottone edit
370
+
371
+ ###
372
+ class ModalEditButton extends ModalForm
373
+
374
+ constructor: (@btn_blk, options = {}) ->
375
+ @updatable_content = $(@btn_blk).data('updatableContent')
376
+ if $(@btn_blk).hasClass('kono_modal_form')
377
+ super(@btn_blk, options)
378
+ else
379
+ super($(@btn_blk).find('.kono_modal_form').get(0), options)
380
+
381
+ _on_success: (args)->
382
+ super
383
+ data = args[0]
384
+ if @updatable_content
385
+ $(@updatable_content).replaceWith(data.partial)
386
+ #seleziono il nuovo pannello
387
+ panel = $(@updatable_content)
388
+ panel.find('.kono_edit_button').each (index,ele) =>
389
+ new_panel = new @.__proto__.constructor(ele)
390
+ new_panel.modal.updatable_content = @updatable_content
391
+ #rillacciamo gli eventi del vecchio pannello su quello nuovo
392
+ @propagate_events_on_child(new_panel)
393
+ @emitEvent('rendered', [@, panel, new_panel])
394
+
395
+ rescue_invalid_content: (response)->
396
+ res = super
397
+ res.modal.updatable_content = @updatable_content
398
+
399
+
400
+ initial_classes: ->
401
+ _.reduce _.compact($(@btn_blk).prop('class').split(' ')), (memo, str)->
402
+ "#{memo}.#{str}"
403
+ , ''
404
+
405
+
406
+ @Kn.ns 'Kn.utilities', (exports)->
407
+ exports.ModalEditButton = ModalEditButton
408
+
409
+
410
+ class BasePannel
411
+
412
+ form_inline_settings:
413
+ label_cls: 'col-xs-12 col-sm-4',
414
+ wrapp_cls: 'col-xs-12 col-sm-8'
415
+
416
+ constructor: (@blk) ->
417
+ $(@blk).bs3_form_inline @form_inline_settings
418
+ @initialize_events()
419
+
420
+ initialize_events: ->
421
+ ele = $(@blk).find('.kono_edit_button').get(0)
422
+ if(ele)
423
+ panel = new Kn.utilities.ModalEditButton ele
424
+ panel.on 'rendered', (button, panel)->
425
+ $(panel).bs3_form_inline @form_inline_settings
426
+ panel.on 'rescue_invalid_content', (a, b, c)->
427
+ $(c.modal).bs3_form_inline @form_inline_settings
428
+
429
+ @Kn.ns 'Kn.utilities', (exports)->
430
+ exports.BasePannel = BasePannel
431
+
432
+ ## Gestione Generazione Mappa google per Input LocationPicker
433
+ #
434
+ $.fn.extend
435
+ kono_util_location_picker: (options)->
436
+ settings =
437
+ center: {lat: 42.908, lng: 12.303}
438
+ selector_field_lat: 'input[name="lat"]'
439
+ selector_field_lng: 'input[name="lat"]'
440
+ zoom_level: 5
441
+
442
+ settings = $.extend settings, options
443
+
444
+ return @each () ->
445
+ map = new google.maps.Map(@, {
446
+ zoom: settings.zoom_level,
447
+ center: settings.center
448
+ })
449
+ marker = new google.maps.Marker({
450
+ position: settings.center,
451
+ draggable: true,
452
+ map: map
453
+ })
454
+ marker.addListener 'drag', (data) ->
455
+ $(settings.selector_field_lat).val(data.latLng.lat())
456
+ $(settings.selector_field_lng).val(data.latLng.lng())