kono_utils 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.rdoc +0 -76
- 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/locales/it.yml +3 -1
- data/lib/generators/kono_utils/install/install_generator.rb +40 -3
- 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 +20 -22
- 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/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 -7
- 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/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +1 -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/config/application.rb +1 -1
- data/spec/dummy/config/initializers/kono_utils.rb +3 -1
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/spec/models/user_spec.rb +5 -0
- metadata +63 -131
- data/app/assets/javascripts/kono_utils/utilities.coffee +0 -480
- 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/concerns.rb +0 -10
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9a251cc3ff3552e9f8e3f969a609b48993bbb0a08c55f52738fb037b176bb1b2
|
|
4
|
+
data.tar.gz: 98e00db085c7d05efe4adc108fc3466ce685d9cf7e78c8a20228828ff38fc107
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b03d82397c5c8ab6adfa8be8c115fb8150319d3a0482c635183daa3c7a517b2565318c4b39a97c93c4501b8f12e571755c2644df37053c340183834428631ebf
|
|
7
|
+
data.tar.gz: 903ee0bd364036e50e58d1b72678b31357ed3351911ec6dada26e649483bdd300ba1d336fa001db8010e226f2a3535b76744b8df24c9eeb6b5788b274525daeb
|
data/README.rdoc
CHANGED
|
@@ -52,82 +52,6 @@ libreria di utilità per i vari progetti utilizzati da Archimedia.
|
|
|
52
52
|
- **Feature** lorem
|
|
53
53
|
</code>
|
|
54
54
|
|
|
55
|
-
== TmpFile
|
|
56
|
-
Classe Funzionante prettamente con RAILS
|
|
57
|
-
|
|
58
|
-
La classe si occupa dei files temporanei creando una cartella dentro a tmp del progetto,
|
|
59
|
-
per ovviare al problema di duplicazioni dei nomi, viene generata una nuova cartella con
|
|
60
|
-
timestamp univoco per ogni file.
|
|
61
|
-
|
|
62
|
-
Estende Tempfile,
|
|
63
|
-
la root della struttura è quella di Rails.root
|
|
64
|
-
e di default la classe scrive dentro a tmp della root di rails.
|
|
65
|
-
|
|
66
|
-
Non c'è bisogno di preoccuparsi di svuotare la cartella tmp contenente i file temporanei dato che la classe
|
|
67
|
-
avrà l'onere di controllare e ripulire eventuali files dopo 1.day di default.
|
|
68
|
-
|
|
69
|
-
=== Utilizzo:
|
|
70
|
-
tmp = KonoUtils::TmpFile.new('nomefile.ext')
|
|
71
|
-
tmp.path -> path completa
|
|
72
|
-
tmp.write(valore_da_scrivere_dentro_a_file)
|
|
73
|
-
tmp.original_filename -> restituisce il nome inizialmente passato alla classe
|
|
74
|
-
tmp.unique_filename -> restoituisce il nome univoco del file
|
|
75
|
-
tmp.path -> restituisce la path del file
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
== Encoder
|
|
80
|
-
Classe che si occupa di decodificare una qualsiasi stringa in formato utf8,
|
|
81
|
-
cercando di trovare l'encoding iniziale a tentativi.
|
|
82
|
-
Ha anche a disposizione una funzione per la rimozione dei caratteri BOM dalla stringa(http://en.wikipedia.org/wiki/Byte_order_mark)
|
|
83
|
-
|
|
84
|
-
=== Utilizzo
|
|
85
|
-
str="stringa di un encoding sconosciuto"
|
|
86
|
-
en = KonoUtils::Encoder.new(str)
|
|
87
|
-
en.string_encoder -> normale tentativo di encoding restituendo stringa in utf8
|
|
88
|
-
en.remove_bom -> rimozione del carattere BOM e encoding con la funzione precedente
|
|
89
|
-
|
|
90
|
-
== Percentage
|
|
91
|
-
Classe che si occupa di rappresentare un numero in percentuale.
|
|
92
|
-
Per maggiori info sulle funzionalità controllare la documentazione sulla classe
|
|
93
|
-
|
|
94
|
-
=== Utilizzo
|
|
95
|
-
p = KonoUtils::Percentage.new(100,20)
|
|
96
|
-
p.percentage -> ritorna il valore percentuale float
|
|
97
|
-
p.to_i -> ritorna percentuale intera con relativi arrotondamenti
|
|
98
|
-
p.to_percentage -> si comporta come l'helper number_to_percentage
|
|
99
|
-
|
|
100
|
-
== Params Hash Array
|
|
101
|
-
|
|
102
|
-
Si occupa di trasformare un hash con elementi che sono chiramente array in un hash con elementi array:
|
|
103
|
-
|
|
104
|
-
{"DatiOrdineAcquisto"=>{"0"=>{"RiferimentoNumeroLinea"=>{"0"=>""}, "IdDocumento"=>"", "Data"=>"", "NumItem"=>"", "CodiceCommessaConvenzione"=>"", "CodiceCUP"=>"", "CodiceCIG"=>""}}}
|
|
105
|
-
{"DatiOrdineAcquisto"=>[{"RiferimentoNumeroLinea"=>[""], "IdDocumento"=>"", "Data"=>"", "NumItem"=>"", "CodiceCommessaConvenzione"=>"", "CodiceCUP"=>"", "CodiceCIG"=>""}]}
|
|
106
|
-
|
|
107
|
-
=== Utilizzo
|
|
108
|
-
includere nel controller o dove si vuole utilizzare il concern
|
|
109
|
-
include KonoUtils::ParamsHashArray
|
|
110
|
-
|
|
111
|
-
e richiamare la funzione:
|
|
112
|
-
elaborate_params_to_hash_array(params)
|
|
113
|
-
|
|
114
|
-
== Virtual Model
|
|
115
|
-
Server per avere un modello virtuale in Rails
|
|
116
|
-
|
|
117
|
-
=== Utilizzo
|
|
118
|
-
Praticamente è come avere un active record ma senza avere una tabella
|
|
119
|
-
|
|
120
|
-
class Session < KonoUtils::VirtualModel
|
|
121
|
-
|
|
122
|
-
attr_accessor :username, :password, :token
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
validates :token,:presence=>true
|
|
126
|
-
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
Session.new(:username=>'ciao',:password=>'pippo').valid? => false
|
|
130
|
-
|
|
131
55
|
== BaseSearch
|
|
132
56
|
Classe per semplificare il sistema di organizzazione dei modelli di ricerca, unendo anche la
|
|
133
57
|
configurazione della form di ricerca utilizzando l'helper search_form
|
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
#= require underscore/underscore
|
|
2
|
+
##= require wolfy87-eventemitter/EventEmitter
|
|
3
|
+
|
|
4
|
+
@Kono = @Kono || {};
|
|
5
|
+
|
|
6
|
+
@Kn = @Kono
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# http://stackoverflow.com/questions/8730859/classes-within-coffeescript-namespace
|
|
10
|
+
# Funzione che si occupa di costruire il namespace se non presente e passarlo come risultato
|
|
11
|
+
# la funzione si aspetta una stringa divisa da punti che identificano i vari livelli di namespace
|
|
12
|
+
# Es: @Kn.ns 'Kn.admin.iseeprices', (exports)->
|
|
13
|
+
# exports.Form = Form
|
|
14
|
+
# exports.attributi_vari = 'ciao'
|
|
15
|
+
# ovviamente senza cancellare i precedenti livelli
|
|
16
|
+
|
|
17
|
+
@Kn.ns = (target, name, block) ->
|
|
18
|
+
if arguments.length < 3
|
|
19
|
+
tmp = (if typeof exports isnt 'undefined' then exports else window)
|
|
20
|
+
[target, name, block] = [tmp, arguments...]
|
|
21
|
+
top = target
|
|
22
|
+
target = target[item] or= {} for item in name.split '.'
|
|
23
|
+
block target, top
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
###
|
|
27
|
+
Si occupa di eseguire il blocco nel caso in cui siamo nel namespace di vista,
|
|
28
|
+
o che sia presente tale namespace.
|
|
29
|
+
eseguo ovviamente il tutto all'interno di un $-> per essere sicuro che la pagina sia caricata
|
|
30
|
+
Viene attaccanto anche un evento per ascoltare i possibili eventi di hashchange di jquery ui
|
|
31
|
+
per ascoltare se una nuova pagina viene inserita.
|
|
32
|
+
ES:
|
|
33
|
+
@Kn.view_ns '.Alim.Admin.IseepricesController.edit', (namespace)->
|
|
34
|
+
fai qualcosa solo se esiste tale namespace
|
|
35
|
+
|
|
36
|
+
###
|
|
37
|
+
@Kn.view_ns = (selector, block) ->
|
|
38
|
+
#funzione da lanciare per il reload della pagina
|
|
39
|
+
esecutore = _.debounce(->
|
|
40
|
+
#se abbiamo il selettore allora lancio il blocco
|
|
41
|
+
if $(selector).length > 0
|
|
42
|
+
block(selector)
|
|
43
|
+
, 10, true)
|
|
44
|
+
#on ready
|
|
45
|
+
$ ->
|
|
46
|
+
esecutore()
|
|
47
|
+
|
|
48
|
+
#attacco ascoltatore event haschanged
|
|
49
|
+
$(window).on 'hashchange', esecutore
|
|
50
|
+
|
|
51
|
+
#Attacco evento anche per turbolinks
|
|
52
|
+
document.addEventListener("turbolinks:load", esecutore)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
###
|
|
56
|
+
Singleton per avere una modal da utilizzare
|
|
57
|
+
funziona attraverso helper bootstrap_please_wait
|
|
58
|
+
###
|
|
59
|
+
#@Kn.show_wait = ->
|
|
60
|
+
# $('#processing_wait').modal()
|
|
61
|
+
#
|
|
62
|
+
#@Kn.hide_wait = ->
|
|
63
|
+
# $('#processing_wait').modal('hide')
|
|
64
|
+
# #forzo eliminazione di tutti i fade
|
|
65
|
+
# $('.modal-backdrop.fade.in').remove()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
##
|
|
69
|
+
# A tutte le form aggiungo l'autocomplete ad off
|
|
70
|
+
#$ ->
|
|
71
|
+
# $('form').prop('autocomplete', 'off')
|
|
72
|
+
#
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# picker = new Kn.utilities.DateTimePicker(
|
|
76
|
+
# selector: _.map(view_namespace, (cls)-> "#{cls} #date_time_picker_documents_search_data").join(",")
|
|
77
|
+
# server_format: "YYYY-MM-DDTHH:mm:ss+Z"
|
|
78
|
+
# )
|
|
79
|
+
# picker.initialize()
|
|
80
|
+
#
|
|
81
|
+
#class DateTimePicker
|
|
82
|
+
#
|
|
83
|
+
# defaults = server_format: "YYYY-MM-DD HH:mm:ss Z",
|
|
84
|
+
# format: 'DD/MM/YYYY',
|
|
85
|
+
# server_match: /^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} .$/,
|
|
86
|
+
# locale: 'it'
|
|
87
|
+
#
|
|
88
|
+
# constructor: (options = {}) ->
|
|
89
|
+
# {@selector, @server_format, @format, @server_match, @locale} = _.extend defaults, options
|
|
90
|
+
# @input_date = @parse_input_value()
|
|
91
|
+
#
|
|
92
|
+
# initialize: ->
|
|
93
|
+
# if @input_date
|
|
94
|
+
# val = @input_date
|
|
95
|
+
# val = @input_date.format(@format) if _.isFunction(@input_date.format)
|
|
96
|
+
# $(@selector).find("input").val(val)
|
|
97
|
+
#
|
|
98
|
+
# $(@selector).datetimepicker(@picker_configs())
|
|
99
|
+
#
|
|
100
|
+
# picker_configs: ->
|
|
101
|
+
# {
|
|
102
|
+
# format: @format,
|
|
103
|
+
# locale: @locale
|
|
104
|
+
# }
|
|
105
|
+
#
|
|
106
|
+
# parse_input_value: ->
|
|
107
|
+
# value = $(@selector).find("input").attr('value')
|
|
108
|
+
# unless value == '' or _.isUndefined(value)
|
|
109
|
+
# if @server_match.test(value)
|
|
110
|
+
# return moment(value, @server_format)
|
|
111
|
+
# else
|
|
112
|
+
# return value
|
|
113
|
+
# false
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
##
|
|
117
|
+
# Definisce l'elemento associato alla data finale di un range di date
|
|
118
|
+
# set_end: (@end_pick)->
|
|
119
|
+
# $(@selector).data("DateTimePicker").maxDate(@end_pick.input_date) if @end_pick.input_date
|
|
120
|
+
#
|
|
121
|
+
# $("#{@end_pick.selector}").on "dp.change", (e) =>
|
|
122
|
+
# $(@selector).data("DateTimePicker").maxDate(e.date)
|
|
123
|
+
#
|
|
124
|
+
## Definisce l'elemento associato alla data iniziale di un range di date
|
|
125
|
+
# set_start: (@start_pick)->
|
|
126
|
+
# $(@selector).data("DateTimePicker").minDate(@start_pick.input_date) if @start_pick.input_date
|
|
127
|
+
#
|
|
128
|
+
# $("#{@start_pick.selector}").on "dp.change", (e) =>
|
|
129
|
+
# $(@selector).data("DateTimePicker").minDate(e.date)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
135
|
+
# exports.DateTimePicker = DateTimePicker
|
|
136
|
+
|
|
137
|
+
#class TimePicker extends DateTimePicker
|
|
138
|
+
# defaults = server_format: "HH:mm",
|
|
139
|
+
# format: 'HH:mm',
|
|
140
|
+
# server_match: /[0-9]{2}:[0-9]{2} .$/
|
|
141
|
+
#
|
|
142
|
+
# picker_configs: ->
|
|
143
|
+
# _.extend super(), {format: 'HH:mm'}
|
|
144
|
+
#
|
|
145
|
+
#
|
|
146
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
147
|
+
# exports.TimePicker = TimePicker
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
##
|
|
151
|
+
# Eventi generali Jquery
|
|
152
|
+
#$ ->
|
|
153
|
+
# $('.collapse_search').click (e) ->
|
|
154
|
+
# e.preventDefault();
|
|
155
|
+
# $('.search_panel .collapsible_panel').slideToggle()
|
|
156
|
+
# $('.search_panel .collapsible_panel').slideUp() unless $('.search_panel .collapsible_panel.uncollapsed').length > 0
|
|
157
|
+
#
|
|
158
|
+
|
|
159
|
+
## Trasformare form bootstrap da label posizionate sopra a input a sinistra
|
|
160
|
+
# Default:
|
|
161
|
+
# label_cls: 'col-sm-2'
|
|
162
|
+
# wrapp_cls: 'col-sm-10'
|
|
163
|
+
#$.fn.extend
|
|
164
|
+
# bs3_form_inline: (options)->
|
|
165
|
+
# settings =
|
|
166
|
+
# label_cls: 'col-sm-2'
|
|
167
|
+
# wrapp_cls: 'col-sm-10'
|
|
168
|
+
#
|
|
169
|
+
# settings = $.extend settings, options
|
|
170
|
+
# return @each () ->
|
|
171
|
+
# $(this).find('.form-group .form-label').addClass settings.label_cls
|
|
172
|
+
# $(this).find('.form-group .form-wrapper').addClass settings.wrapp_cls
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
#duplicate_button_toggle = (btn)->
|
|
176
|
+
# if $(btn.parentNode).find('.remove_row,.add_one_more').length == 1
|
|
177
|
+
# if $(btn.parentNode).find('.remove_row').length == 0
|
|
178
|
+
# rem_class = 'add_one_more'
|
|
179
|
+
# add_class = 'remove_row'
|
|
180
|
+
# ico_rem_class = 'fa-plus'
|
|
181
|
+
# ico_add_class = 'fa-minus'
|
|
182
|
+
# if $(btn.parentNode).find('.add_one_more').length == 0
|
|
183
|
+
# rem_class = 'remove_row'
|
|
184
|
+
# add_class = 'add_one_more'
|
|
185
|
+
# ico_rem_class = 'fa-minus'
|
|
186
|
+
# ico_add_class = 'fa-plus'
|
|
187
|
+
#
|
|
188
|
+
# $(btn).clone().appendTo(btn.parentNode).
|
|
189
|
+
# removeClass(rem_class).
|
|
190
|
+
# addClass(add_class).
|
|
191
|
+
# find('.fa').
|
|
192
|
+
# removeClass(ico_rem_class).
|
|
193
|
+
# addClass(ico_add_class)
|
|
194
|
+
|
|
195
|
+
#elaborate_buttons = (tabella)->
|
|
196
|
+
## numero_elementi = $(tabella).find('.add_one_more').length
|
|
197
|
+
# $(tabella).find('.add_one_more').each (index, ele)->
|
|
198
|
+
# duplicate_button_toggle(ele)
|
|
199
|
+
# if $(tabella).find('tr:not(.multiple_table_remove_row) .remove_row').length == 1
|
|
200
|
+
# $(tabella).find('tr:not(.multiple_table_remove_row) .remove_row').first().remove()
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## Gestione elementi multipli
|
|
204
|
+
# Eventi sulla tabella:
|
|
205
|
+
# - row_append : lanciato quando viene appeso una nuova riga, parametri: tabella,riga appena aggiunta
|
|
206
|
+
# - row_removed : lanciato quando viene rimossa una nuova riga, parametri: tabella,riga appena rimossa
|
|
207
|
+
#$.fn.extend
|
|
208
|
+
# multiple_table: (options) ->
|
|
209
|
+
## settings =
|
|
210
|
+
## label: ".form-label"
|
|
211
|
+
## content: ".form-wrapper"
|
|
212
|
+
##
|
|
213
|
+
## settings = $.extend settings, options
|
|
214
|
+
# return @each () ->
|
|
215
|
+
# tabella = @
|
|
216
|
+
# elaborate_buttons(tabella)
|
|
217
|
+
#
|
|
218
|
+
#
|
|
219
|
+
# $(tabella).on 'click', '.remove_row', (e)->
|
|
220
|
+
# e.preventDefault()
|
|
221
|
+
# row = $(@).closest('tr')
|
|
222
|
+
# row.hide().addClass('multiple_table_remove_row')
|
|
223
|
+
# $(@).find('[type="hidden"]').val('true')
|
|
224
|
+
# elaborate_buttons(tabella)
|
|
225
|
+
# $(tabella).trigger("row_removed", [tabella, row]);
|
|
226
|
+
#
|
|
227
|
+
# $(tabella).on 'click', '.add_one_more', (e)->
|
|
228
|
+
# e.preventDefault()
|
|
229
|
+
# row = $(@).closest('tr').clone(false, true)
|
|
230
|
+
# uid = $(@).closest('tbody').find('tr').length
|
|
231
|
+
# $(row).find('input,select').val('').each ->
|
|
232
|
+
# name = $(@).attr('name').replace(/\[[0-9]+\]/, "[#{uid}]")
|
|
233
|
+
# $(@).attr('name', name)
|
|
234
|
+
# $(@).removeAttr('disabled')
|
|
235
|
+
#
|
|
236
|
+
# datapicker_containers= $(row).find(".tk_date_time_picker")
|
|
237
|
+
# $(datapicker_containers).each (index,val) =>
|
|
238
|
+
# new_id= $(val).attr("id").concat( new Date().getTime())
|
|
239
|
+
# $(val).attr("id",new_id)
|
|
240
|
+
#
|
|
241
|
+
# script = $(val).siblings("script")[0]
|
|
242
|
+
# script_text = $(script).text();
|
|
243
|
+
# new_script_text = script_text.replace(/'#.*'/,"'#"+new_id+"'")
|
|
244
|
+
# script_parent= $(script).parent()
|
|
245
|
+
# $(script).replaceWith('<script type=\'text/javascript\'>'+new_script_text+'</script>');
|
|
246
|
+
#
|
|
247
|
+
# row.appendTo($(@).closest('tbody'))
|
|
248
|
+
# elaborate_buttons(tabella)
|
|
249
|
+
# $(tabella).trigger("row_append", [tabella, row]);
|
|
250
|
+
|
|
251
|
+
##fine
|
|
252
|
+
|
|
253
|
+
## Gestione bottone di cancellazione
|
|
254
|
+
# Precedentemente alla rimozione dell'elemento viene
|
|
255
|
+
# lanciato un evento che notifica tale cancellazione "component_removed"
|
|
256
|
+
#$.fn.extend
|
|
257
|
+
# kono_delete_button: ()->
|
|
258
|
+
# return @each () ->
|
|
259
|
+
# $(this).on 'submit', (e) ->
|
|
260
|
+
# e.preventDefault()
|
|
261
|
+
# form = $(this)
|
|
262
|
+
# form.closest('.modal').modal('hide')
|
|
263
|
+
# $.ajax
|
|
264
|
+
# url: form.prop('action')
|
|
265
|
+
# data: form.serialize()
|
|
266
|
+
# method: 'DELETE'
|
|
267
|
+
# success: (data)->
|
|
268
|
+
# $('.modal-backdrop').remove() #rimuovo la modal
|
|
269
|
+
# $('body').removeClass('modal-open') #rimuovo la classe che blocca
|
|
270
|
+
# if data.success
|
|
271
|
+
# base_component = $(form.data('callbackRemove'))
|
|
272
|
+
# base_component.trigger('component_removed', [form.data('callbackRemove'), data]);
|
|
273
|
+
# base_component.hide('fast').remove()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
##
|
|
277
|
+
# Classe per la gestione delle form Modal
|
|
278
|
+
#
|
|
279
|
+
# Eventi:
|
|
280
|
+
# close_modal -> self
|
|
281
|
+
# rescue_invalid_content -> self,response,jquery(dom modal)
|
|
282
|
+
# success -> ajax_response
|
|
283
|
+
|
|
284
|
+
#class ModalForm extends EventEmitter
|
|
285
|
+
#
|
|
286
|
+
# defaults = {success: (->)}
|
|
287
|
+
#
|
|
288
|
+
# constructor: (@modal, options = {}) ->
|
|
289
|
+
# super
|
|
290
|
+
# {@success} = _.extend defaults, options
|
|
291
|
+
# @form = $(@modal).find('form').get(0)
|
|
292
|
+
# @modal_id = $(@modal).attr('id')
|
|
293
|
+
# @initialize_callbacks()
|
|
294
|
+
#
|
|
295
|
+
# inject_format: (format = 'json')->
|
|
296
|
+
# $(@form).append("<input type='hidden' value='#{format}' name='format'>")
|
|
297
|
+
#
|
|
298
|
+
# close_modal: ->
|
|
299
|
+
# $(@modal).modal('hide')
|
|
300
|
+
# $('.modal-backdrop').remove()
|
|
301
|
+
# $('body').removeClass('modal-open')
|
|
302
|
+
# $(@form).get(0).reset()
|
|
303
|
+
# @emitEvent('close_modal', [@]);
|
|
304
|
+
#
|
|
305
|
+
# rescue_invalid_content: (response)->
|
|
306
|
+
## ricevendo in risposta la modal sostituirò la modal attuale,
|
|
307
|
+
## attacco tutte le opzioni di questa classe.
|
|
308
|
+
# @close_modal()
|
|
309
|
+
# mod = $(response.partial).appendTo($('body'))
|
|
310
|
+
# id = Date.now()
|
|
311
|
+
# $(mod).prop('id', id).modal('show')
|
|
312
|
+
# modal = new @.__proto__.constructor(mod)
|
|
313
|
+
# @propagate_events_on_child(modal)
|
|
314
|
+
# @emitEvent('rescue_invalid_content', [@, response, modal])
|
|
315
|
+
# return {response: response, modal: modal}
|
|
316
|
+
#
|
|
317
|
+
#
|
|
318
|
+
## Si occupa di propagare gli eventi attaccati sul padre pannello sui vari figli
|
|
319
|
+
# propagate_events_on_child: (child)->
|
|
320
|
+
# events = @_getEvents()
|
|
321
|
+
# _.each events, (v, k) =>
|
|
322
|
+
# child.on k, =>
|
|
323
|
+
# @emitEvent(k, arguments)
|
|
324
|
+
#
|
|
325
|
+
#
|
|
326
|
+
# initialize_callbacks: ->
|
|
327
|
+
# @inject_format()
|
|
328
|
+
# $(@form).on 'submit', (e) =>
|
|
329
|
+
# Kn.show_wait()
|
|
330
|
+
# e.preventDefault()
|
|
331
|
+
# $.ajax
|
|
332
|
+
# url: $(@form).prop('action')
|
|
333
|
+
# method: $(@form).prop('method')
|
|
334
|
+
# data: $(@form).serialize()
|
|
335
|
+
# success: =>
|
|
336
|
+
# @_on_success(arguments)
|
|
337
|
+
# error: (xhr) =>
|
|
338
|
+
# @_on_error(xhr)
|
|
339
|
+
#
|
|
340
|
+
###
|
|
341
|
+
## funzione privata eseguita al success
|
|
342
|
+
# _on_success: (args)->
|
|
343
|
+
# @close_modal()
|
|
344
|
+
# Kn.hide_wait()
|
|
345
|
+
# @emitEvent('success', args);
|
|
346
|
+
#
|
|
347
|
+
# _on_error: (xhr)->
|
|
348
|
+
# Kn.hide_wait()
|
|
349
|
+
# switch parseInt(xhr.status/100)*100
|
|
350
|
+
# when 400 then @rescue_invalid_content(xhr.responseJSON)
|
|
351
|
+
# when 500 then alert("Attenzione, problemi nello svolgimento dell'operazione contattare amministratore")
|
|
352
|
+
#
|
|
353
|
+
#
|
|
354
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
355
|
+
# exports.ModalForm = ModalForm
|
|
356
|
+
#
|
|
357
|
+
#
|
|
358
|
+
#class ModalNewButton extends ModalForm
|
|
359
|
+
#
|
|
360
|
+
# ##
|
|
361
|
+
# # Funzione per ricaricare la modal
|
|
362
|
+
# # Esegue un'ajax alla pagina corrente, ricercando l'elemento con l'id uguale a quello di se stesso,
|
|
363
|
+
# # rimpiazza quindi la precedente modal di creazione e riattacca tutti gli eventi al modal appena creato.
|
|
364
|
+
# # sucessivamente rimuove l'elemento iniziale e lancia l'evento "self_reloaded" per poter far eventualemnte ulteriori
|
|
365
|
+
# # modifiche sul modal appena generato
|
|
366
|
+
# self_reload: ()->
|
|
367
|
+
# @_self_reload(@)
|
|
368
|
+
#
|
|
369
|
+
# _self_reload: ()->
|
|
370
|
+
# Kn.show_wait()
|
|
371
|
+
# id = "tmp#{(new Date()).getTime()}"
|
|
372
|
+
# $('body').append("<div id='#{id}'></div>")
|
|
373
|
+
# $("##{id}").load "#{window.location.href} ##{@modal_id}", ()=>
|
|
374
|
+
# ele = $("##{id}>*")
|
|
375
|
+
# $(ele).attr('generated_id', id)
|
|
376
|
+
# pre_modal = $("##{@modal_id}")
|
|
377
|
+
# pre_modal.after(ele)
|
|
378
|
+
# modal = new @__proto__.constructor(ele)
|
|
379
|
+
# @propagate_events_on_child(modal)
|
|
380
|
+
# @emitEvent('self_reloaded', [modal, @])
|
|
381
|
+
# pre_modal.remove()
|
|
382
|
+
# Kn.hide_wait()
|
|
383
|
+
#
|
|
384
|
+
#
|
|
385
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
386
|
+
# exports.ModalNewButton = ModalNewButton
|
|
387
|
+
#
|
|
388
|
+
#
|
|
389
|
+
####
|
|
390
|
+
#Classe che gestisce la UI per il bottone edit
|
|
391
|
+
#
|
|
392
|
+
####
|
|
393
|
+
#class ModalEditButton extends ModalForm
|
|
394
|
+
#
|
|
395
|
+
# constructor: (@btn_blk, options = {}) ->
|
|
396
|
+
# @updatable_content = $(@btn_blk).data('updatableContent')
|
|
397
|
+
# if $(@btn_blk).hasClass('kono_modal_form')
|
|
398
|
+
# super(@btn_blk, options)
|
|
399
|
+
# else
|
|
400
|
+
# super($(@btn_blk).find('.kono_modal_form').get(0), options)
|
|
401
|
+
#
|
|
402
|
+
# _on_success: (args)->
|
|
403
|
+
# super
|
|
404
|
+
# data = args[0]
|
|
405
|
+
# if @updatable_content
|
|
406
|
+
# $(@updatable_content).replaceWith(data.partial)
|
|
407
|
+
# #seleziono il nuovo pannello
|
|
408
|
+
# panel = $(@updatable_content)
|
|
409
|
+
# panel.find('.kono_edit_button').each (index,ele) =>
|
|
410
|
+
# new_panel = new @.__proto__.constructor(ele)
|
|
411
|
+
# new_panel.modal.updatable_content = @updatable_content
|
|
412
|
+
# #rillacciamo gli eventi del vecchio pannello su quello nuovo
|
|
413
|
+
# @propagate_events_on_child(new_panel)
|
|
414
|
+
# @emitEvent('rendered', [@, panel, new_panel])
|
|
415
|
+
#
|
|
416
|
+
# rescue_invalid_content: (response)->
|
|
417
|
+
# res = super
|
|
418
|
+
# res.modal.updatable_content = @updatable_content
|
|
419
|
+
#
|
|
420
|
+
#
|
|
421
|
+
# initial_classes: ->
|
|
422
|
+
# _.reduce _.compact($(@btn_blk).prop('class').split(' ')), (memo, str)->
|
|
423
|
+
# "#{memo}.#{str}"
|
|
424
|
+
# , ''
|
|
425
|
+
#
|
|
426
|
+
#
|
|
427
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
428
|
+
# exports.ModalEditButton = ModalEditButton
|
|
429
|
+
#
|
|
430
|
+
#
|
|
431
|
+
#class BasePannel
|
|
432
|
+
#
|
|
433
|
+
# form_inline_settings:
|
|
434
|
+
# label_cls: 'col-xs-12 col-sm-4',
|
|
435
|
+
# wrapp_cls: 'col-xs-12 col-sm-8'
|
|
436
|
+
#
|
|
437
|
+
# constructor: (@blk) ->
|
|
438
|
+
# $(@blk).bs3_form_inline @form_inline_settings
|
|
439
|
+
# @initialize_events()
|
|
440
|
+
#
|
|
441
|
+
# initialize_events: ->
|
|
442
|
+
# ele = $(@blk).find('.kono_edit_button').get(0)
|
|
443
|
+
# if(ele)
|
|
444
|
+
# panel = new Kn.utilities.ModalEditButton ele
|
|
445
|
+
# panel.on 'rendered', (button, panel)->
|
|
446
|
+
# $(panel).bs3_form_inline @form_inline_settings
|
|
447
|
+
# panel.on 'rescue_invalid_content', (a, b, c)->
|
|
448
|
+
# $(c.modal).bs3_form_inline @form_inline_settings
|
|
449
|
+
#
|
|
450
|
+
#@Kn.ns 'Kn.utilities', (exports)->
|
|
451
|
+
# exports.BasePannel = BasePannel
|
|
452
|
+
#
|
|
453
|
+
### Gestione Generazione Mappa google per Input LocationPicker
|
|
454
|
+
##
|
|
455
|
+
#$.fn.extend
|
|
456
|
+
# kono_util_location_picker: (options)->
|
|
457
|
+
# settings =
|
|
458
|
+
# center: {lat: 42.908, lng: 12.303}
|
|
459
|
+
# selector_field_lat: 'input[name="lat"]'
|
|
460
|
+
# selector_field_lng: 'input[name="lat"]'
|
|
461
|
+
# zoom_level: 5
|
|
462
|
+
#
|
|
463
|
+
# settings = $.extend settings, options
|
|
464
|
+
#
|
|
465
|
+
# return @each () ->
|
|
466
|
+
# map = new google.maps.Map(@, {
|
|
467
|
+
# zoom: settings.zoom_level,
|
|
468
|
+
# center: settings.center
|
|
469
|
+
# })
|
|
470
|
+
# marker = new google.maps.Marker({
|
|
471
|
+
# position: settings.center,
|
|
472
|
+
# draggable: true,
|
|
473
|
+
# map: map
|
|
474
|
+
# })
|
|
475
|
+
# marker.addListener 'drag', (data) ->
|
|
476
|
+
# $(settings.selector_field_lat).val(data.latLng.lat())
|
|
477
|
+
# $(settings.selector_field_lng).val(data.latLng.lng())
|