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