kono_utils 1.0.1 → 1.1.0

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