kono_utils 0.15.5
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +442 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/kono_utils/utilities.coffee +456 -0
- data/app/assets/stylesheets/kono_utils/utils.css.scss +43 -0
- data/app/controllers/kono_utils/change_log_controller.rb +6 -0
- data/app/input/bs_aceeditor_input.rb +53 -0
- data/app/input/bs_autocomplete_input.rb +60 -0
- data/app/input/bs_datepicker_input.rb +16 -0
- data/app/input/bs_datetimepicker_input.rb +80 -0
- data/app/input/bs_file_download_input.rb +35 -0
- data/app/input/bs_image_input.rb +35 -0
- data/app/input/bs_label_with_container_input.rb +22 -0
- data/app/input/bs_location_picker_input.rb +95 -0
- data/app/input/bs_readonly_input.rb +52 -0
- data/app/input/bs_timepicker_input.rb +14 -0
- data/app/policies/kono_utils/base_editing_policy_concern.rb +27 -0
- data/app/views/kono_utils/base_editing/_edit.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_form.html.erb +15 -0
- data/app/views/kono_utils/base_editing/_index_buttons.html.erb +2 -0
- data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
- data/app/views/kono_utils/base_editing/_new.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +3 -0
- data/app/views/kono_utils/base_editing/_search_form.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/edit.html.erb +1 -0
- data/app/views/kono_utils/base_editing/application/new.html.erb +1 -0
- data/app/views/kono_utils/base_editing/edit.html.erb +1 -0
- data/app/views/kono_utils/base_editing/index.html.erb +36 -0
- data/app/views/kono_utils/base_editing/new.html.erb +1 -0
- data/app/views/kono_utils/change_log/index.html.erb +3 -0
- data/config/initializers/mysql.rb +12 -0
- data/config/initializers/time.rb +12 -0
- data/config/locales/it.yml +18 -0
- data/lib/generators/kono_utils/install/install_generator.rb +24 -0
- data/lib/generators/templates/initializer.rb +3 -0
- data/lib/kono_utils.rb +41 -0
- data/lib/kono_utils/application_helper.rb +625 -0
- data/lib/kono_utils/base_editing_helper.rb +194 -0
- data/lib/kono_utils/base_search.rb +173 -0
- data/lib/kono_utils/concerns.rb +10 -0
- data/lib/kono_utils/concerns/active_record_translation.rb +47 -0
- data/lib/kono_utils/concerns/base_editing.rb +195 -0
- data/lib/kono_utils/concerns/base_modals.rb +97 -0
- data/lib/kono_utils/concerns/success_message.rb +25 -0
- data/lib/kono_utils/encoder.rb +55 -0
- data/lib/kono_utils/engine.rb +13 -0
- data/lib/kono_utils/fiscal_code.rb +47 -0
- data/lib/kono_utils/params_hash_array.rb +37 -0
- data/lib/kono_utils/percentage.rb +60 -0
- data/lib/kono_utils/search_attribute.rb +57 -0
- data/lib/kono_utils/tmp_file.rb +81 -0
- data/lib/kono_utils/version.rb +3 -0
- data/lib/kono_utils/virtual_model.rb +22 -0
- data/lib/tasks/kono_utils_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/lib/kono_utils/fiscal_code_spec.rb +56 -0
- data/spec/rails_helper.rb +53 -0
- data/spec/spec_helper.rb +92 -0
- data/vendor/assets/javascripts/EventEmitter.js +473 -0
- metadata +425 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 047e731a944ae05843b8ec285d37c1eb3adfcf67
|
|
4
|
+
data.tar.gz: 6b4e99d1e398c46037b07a1718aa571241973762
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 645734d84212743b6bf0d58e6cd6ed7a061bd9b07544a083cbfd17908d356dbdea876d12688dd44d0adf51c53625ef132a406738d87bb55d04bdd599a3cb450c
|
|
7
|
+
data.tar.gz: 0411a05091d447ec7a5d56db081b7e77fb4f79a48e08362a7af0f3e511ebf0039cf2e0521025a620d5ab443cc86b806d7e310d1ed63cea14e301ae93ae426f90
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 Marino
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
= KonoUtils
|
|
2
|
+
|
|
3
|
+
Progetto contenente una serie di classi, debitamente documentata che debbono servire da
|
|
4
|
+
libreria di utilità per i vari progetti utilizzati da Archimedia.
|
|
5
|
+
|
|
6
|
+
== Installazione
|
|
7
|
+
aggiungere nel proprio gemfile
|
|
8
|
+
source 'https://rails-assets.org'
|
|
9
|
+
|
|
10
|
+
gem 'kono_utils'
|
|
11
|
+
|
|
12
|
+
per avere anche le utilities in javascript:
|
|
13
|
+
require kono_utils/utilities
|
|
14
|
+
|
|
15
|
+
== Controllers/Views
|
|
16
|
+
|
|
17
|
+
=== ChangeLog
|
|
18
|
+
Aggungere una rotta all'applicativo
|
|
19
|
+
get '/changelog', to: 'kono_utils/change_log#index', as: :changelog
|
|
20
|
+
|
|
21
|
+
Aggiungere un file nella root del progetto:
|
|
22
|
+
CHANGELOG.md
|
|
23
|
+
|
|
24
|
+
contenuto esempio:
|
|
25
|
+
<code>
|
|
26
|
+
##Legenda:
|
|
27
|
+
- Feature -> Novità
|
|
28
|
+
- Bug -> Risoluzione problema
|
|
29
|
+
- Improvement -> Migliorira
|
|
30
|
+
|
|
31
|
+
##Versioni
|
|
32
|
+
### XX.XX.XX
|
|
33
|
+
- **Bug** lorem
|
|
34
|
+
- **Improvement** lorem
|
|
35
|
+
- **Feature** lorem
|
|
36
|
+
</code>
|
|
37
|
+
|
|
38
|
+
== TmpFile
|
|
39
|
+
Classe Funzionante prettamente con RAILS
|
|
40
|
+
|
|
41
|
+
La classe si occupa dei files temporanei creando una cartella dentro a tmp del progetto,
|
|
42
|
+
per ovviare al problema di duplicazioni dei nomi, viene generata una nuova cartella con
|
|
43
|
+
timestamp univoco per ogni file.
|
|
44
|
+
|
|
45
|
+
Estende Tempfile,
|
|
46
|
+
la root della struttura è quella di Rails.root
|
|
47
|
+
e di default la classe scrive dentro a tmp della root di rails.
|
|
48
|
+
|
|
49
|
+
Non c'è bisogno di preoccuparsi di svuotare la cartella tmp contenente i file temporanei dato che la classe
|
|
50
|
+
avrà l'onere di controllare e ripulire eventuali files dopo 1.day di default.
|
|
51
|
+
|
|
52
|
+
=== Utilizzo:
|
|
53
|
+
tmp = KonoUtils::TmpFile.new('nomefile.ext')
|
|
54
|
+
tmp.path -> path completa
|
|
55
|
+
tmp.write(valore_da_scrivere_dentro_a_file)
|
|
56
|
+
tmp.original_filename -> restituisce il nome inizialmente passato alla classe
|
|
57
|
+
tmp.unique_filename -> restoituisce il nome univoco del file
|
|
58
|
+
tmp.path -> restituisce la path del file
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
== Encoder
|
|
63
|
+
Classe che si occupa di decodificare una qualsiasi stringa in formato utf8,
|
|
64
|
+
cercando di trovare l'encoding iniziale a tentativi.
|
|
65
|
+
Ha anche a disposizione una funzione per la rimozione dei caratteri BOM dalla stringa(http://en.wikipedia.org/wiki/Byte_order_mark)
|
|
66
|
+
|
|
67
|
+
=== Utilizzo
|
|
68
|
+
str="stringa di un encoding sconosciuto"
|
|
69
|
+
en = KonoUtils::Encoder.new(str)
|
|
70
|
+
en.string_encoder -> normale tentativo di encoding restituendo stringa in utf8
|
|
71
|
+
en.remove_bom -> rimozione del carattere BOM e encoding con la funzione precedente
|
|
72
|
+
|
|
73
|
+
== Percentage
|
|
74
|
+
Classe che si occupa di rappresentare un numero in percentuale.
|
|
75
|
+
Per maggiori info sulle funzionalità controllare la documentazione sulla classe
|
|
76
|
+
|
|
77
|
+
=== Utilizzo
|
|
78
|
+
p = KonoUtils::Percentage.new(100,20)
|
|
79
|
+
p.percentage -> ritorna il valore percentuale float
|
|
80
|
+
p.to_i -> ritorna percentuale intera con relativi arrotondamenti
|
|
81
|
+
p.to_percentage -> si comporta come l'helper number_to_percentage
|
|
82
|
+
|
|
83
|
+
== Params Hash Array
|
|
84
|
+
|
|
85
|
+
Si occupa di trasformare un hash con elementi che sono chiramente array in un hash con elementi array:
|
|
86
|
+
|
|
87
|
+
{"DatiOrdineAcquisto"=>{"0"=>{"RiferimentoNumeroLinea"=>{"0"=>""}, "IdDocumento"=>"", "Data"=>"", "NumItem"=>"", "CodiceCommessaConvenzione"=>"", "CodiceCUP"=>"", "CodiceCIG"=>""}}}
|
|
88
|
+
{"DatiOrdineAcquisto"=>[{"RiferimentoNumeroLinea"=>[""], "IdDocumento"=>"", "Data"=>"", "NumItem"=>"", "CodiceCommessaConvenzione"=>"", "CodiceCUP"=>"", "CodiceCIG"=>""}]}
|
|
89
|
+
|
|
90
|
+
=== Utilizzo
|
|
91
|
+
includere nel controller o dove si vuole utilizzare il concern
|
|
92
|
+
include KonoUtils::ParamsHashArray
|
|
93
|
+
|
|
94
|
+
e richiamare la funzione:
|
|
95
|
+
elaborate_params_to_hash_array(params)
|
|
96
|
+
|
|
97
|
+
== Virtual Model
|
|
98
|
+
Server per avere un modello virtuale in Rails
|
|
99
|
+
|
|
100
|
+
=== Utilizzo
|
|
101
|
+
Praticamente è come avere un active record ma senza avere una tabella
|
|
102
|
+
|
|
103
|
+
class Session < KonoUtils::VirtualModel
|
|
104
|
+
|
|
105
|
+
attr_accessor :username, :password, :token
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
validates :token,:presence=>true
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
Session.new(:username=>'ciao',:password=>'pippo').valid? => false
|
|
113
|
+
|
|
114
|
+
== BaseSearch
|
|
115
|
+
Classe per semplificare il sistema di organizzazione dei modelli di ricerca, unendo anche la
|
|
116
|
+
configurazione della form di ricerca utilizzando l'helper search_form
|
|
117
|
+
|
|
118
|
+
=== Utilizzo
|
|
119
|
+
|
|
120
|
+
TODO completare spiegazione utilizzo(vedi commenti classe)
|
|
121
|
+
|
|
122
|
+
Creare una classe modello per gestire la ricerca partendo da BaseSearch
|
|
123
|
+
|
|
124
|
+
module Admin::PariteticEntities
|
|
125
|
+
class Search < KonoUtils::BaseSearch
|
|
126
|
+
|
|
127
|
+
set_search_model Admin::PariteticEntity -> settare il modello a cui si vuole eseguire effettivamente la ricerca
|
|
128
|
+
dovrà contenete uno scope: search che può ricevere un hash di campi da ricercare,
|
|
129
|
+
questo hash conterrà tutti i campi sotto definiti, volendo anche con casting passato
|
|
130
|
+
attraverso il set_search_attributes
|
|
131
|
+
|
|
132
|
+
set_search_attributes :name -> in questo modo settiamo i campi da ricercare, per maggiori
|
|
133
|
+
informazioni guardare i commenti di questo metodo
|
|
134
|
+
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
è possibile poi, una volta creata l'istanza della ricerca definirle uno scope preciso:
|
|
139
|
+
@search = PariteticEntities::Search.new
|
|
140
|
+
|
|
141
|
+
@search.scope = policy_scope(PariteticEntity)
|
|
142
|
+
o
|
|
143
|
+
@search.scope = PariteticEntity.where(:name=>10)
|
|
144
|
+
|
|
145
|
+
quando si devono settare i parametri provenienti dalla form li carichiamo in questo modo:
|
|
146
|
+
@search.update_attributes(params.require(:campo_della_ricerca).permit(:name))
|
|
147
|
+
|
|
148
|
+
Esempio di scope nel modello Admin::PariteticEntity
|
|
149
|
+
##
|
|
150
|
+
# Ricerca
|
|
151
|
+
#
|
|
152
|
+
# * *Args* :
|
|
153
|
+
# - search_query -> Hash of:
|
|
154
|
+
# name: ricerca libera sul nome %nome%
|
|
155
|
+
scope :search, ->(search_query) {
|
|
156
|
+
|
|
157
|
+
unless search_query[:name].blank?
|
|
158
|
+
where(self.arel_table[:name].matches("%#{search_query[:name]}%"))
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
== Concerns
|
|
164
|
+
|
|
165
|
+
=== ActiveRecordTranslation
|
|
166
|
+
Serve per aggiungere ad Active Record funzioni corte per la traduzione, includere in un'inizializzatore
|
|
167
|
+
|
|
168
|
+
ActiveRecord::Base.include KonoUtils::Concerns::ActiveRecordTranslation
|
|
169
|
+
|
|
170
|
+
=== SuccessMessage
|
|
171
|
+
Include 3 funzioni da poter utilizzare per stampare il messaggio di default di conferma
|
|
172
|
+
salvataggio,cancellazione,aggiornamento di un modello come notice in un controller:
|
|
173
|
+
|
|
174
|
+
.., :notice=>success_create_message(model)
|
|
175
|
+
.., :notice=>success_update_message(model)
|
|
176
|
+
.., :notice=>success_destroy_message(model)
|
|
177
|
+
|
|
178
|
+
=== Base Modals
|
|
179
|
+
Un Concern per poter semplificare la vita al controller di salvataggio dati da modals
|
|
180
|
+
|
|
181
|
+
==== Utilizzo
|
|
182
|
+
class Buildings::FloorsController < ApplicationController
|
|
183
|
+
include KonoUtils::Concerns::BaseModals
|
|
184
|
+
|
|
185
|
+
def create
|
|
186
|
+
@obj = @parent_model.floors.build(update_params)
|
|
187
|
+
super
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private
|
|
191
|
+
|
|
192
|
+
def load_obj
|
|
193
|
+
@obj = @parent_model.floors.find(params[:id])
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def update_params
|
|
197
|
+
params.require(:floor).permit(:name)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def save_response
|
|
201
|
+
respond_to do |f|
|
|
202
|
+
if @obj.valid?
|
|
203
|
+
@obj.save
|
|
204
|
+
f.json do
|
|
205
|
+
render_part_to_json('buildings/floors/panel.html', {:piano => @obj})
|
|
206
|
+
end
|
|
207
|
+
else
|
|
208
|
+
f.json do
|
|
209
|
+
render_part_to_json('buildings/floors/modal_form.html', {:piano => @obj, :id => ''}, 400)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def load_parent_assoc
|
|
216
|
+
@parent_model = Building.find(params[:building_id])
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
#TODO inserire documentazione o generatori per creare codice velocemente, con javascript (Kn.utilities.BasePannel)
|
|
222
|
+
# e viste con row modal ecc
|
|
223
|
+
|
|
224
|
+
=== Base Editing
|
|
225
|
+
Un Concern che racchiude tutte le funzionalità base generalizzate per la gestione di un modello
|
|
226
|
+
|
|
227
|
+
==== Utilizzo
|
|
228
|
+
Includere in un controller da cui derivare tutti i controller dei modelli da editare questo concern chiamandolo BaseEditingController
|
|
229
|
+
include KonoUtils::Concerns::BaseEditing
|
|
230
|
+
creare un helper per questo controller e inserirci il modulo degli helper
|
|
231
|
+
include KonoUtils::BaseEditingHelper
|
|
232
|
+
nelle policies poi creare una policy che includa KonoUtils::BaseEditingPolicyConcern
|
|
233
|
+
da cui poi derivare tutte le altre
|
|
234
|
+
|
|
235
|
+
== Application Helper
|
|
236
|
+
Modulo che include varie utilities da poter utilizzare:
|
|
237
|
+
=== Utilizzo
|
|
238
|
+
|
|
239
|
+
==== will_paginate_bst
|
|
240
|
+
esegue will_paginate con il renderer per bootstrap
|
|
241
|
+
<%=will_paginate_bst(collection)%>
|
|
242
|
+
|
|
243
|
+
==== namespace_content
|
|
244
|
+
genera un div contenitore con la classi derivate da controller e azione
|
|
245
|
+
<%= namespace_content do %>
|
|
246
|
+
<%= yield %>
|
|
247
|
+
<% end %>
|
|
248
|
+
==== true_false_label
|
|
249
|
+
stampa un label per bootstrap con true o false rispetto al valore passato
|
|
250
|
+
<%= true_false_label(true) %> =>
|
|
251
|
+
|
|
252
|
+
==== bootstrap_please_wait
|
|
253
|
+
Genera una modal da riutilizzare per far aspettare determinate operazioni al client
|
|
254
|
+
<%= bootstrap_please_wait %>
|
|
255
|
+
Ricordarsi di aggiungere nel JS:
|
|
256
|
+
$('#processing_wait').modal() -> per visualizzarlo
|
|
257
|
+
$('#processing_wait').modal('hide') -> per nasconderlo
|
|
258
|
+
|
|
259
|
+
==== search_form
|
|
260
|
+
Genera una form di ricerca con bootstrap, utilizzando la classe BaseSearch.
|
|
261
|
+
|
|
262
|
+
TODO completare spiegazione utilizzo(vedi commenti classe)
|
|
263
|
+
|
|
264
|
+
==== print_rescue_date
|
|
265
|
+
Stampa la data standard se questa non è nil
|
|
266
|
+
|
|
267
|
+
==== title_mod(model)
|
|
268
|
+
Scrive il titolo per modifica del modello
|
|
269
|
+
==== title_new(model)
|
|
270
|
+
Scrive il titolo per new del modello
|
|
271
|
+
==== title_newa(model)
|
|
272
|
+
Scrive il titolo per il modello al femminile
|
|
273
|
+
==== enum_collection
|
|
274
|
+
Genera l'hash da passare come collection alle selectbox, esegue anche la traduzione con locale
|
|
275
|
+
==== enum_translation
|
|
276
|
+
Si occupa di tradurre un determinato valore di un enum
|
|
277
|
+
Le traduzioni dentro al locale devono essere fatte in questo modo:
|
|
278
|
+
|
|
279
|
+
it:
|
|
280
|
+
activerecord:
|
|
281
|
+
attributes:
|
|
282
|
+
estimate_before/value:
|
|
283
|
+
na: NA
|
|
284
|
+
very_insufficient: 1
|
|
285
|
+
insufficient: 2
|
|
286
|
+
sufficient: 3
|
|
287
|
+
excellent: 4
|
|
288
|
+
|
|
289
|
+
dove in questo caso estimate_before è il modello e value è il nome del campo enum
|
|
290
|
+
|
|
291
|
+
==== modal_form_generator
|
|
292
|
+
Si occupa di gnerare una modal di bootstrap con all'interno una form
|
|
293
|
+
|
|
294
|
+
ES:
|
|
295
|
+
<%= modal_form_generator(id: id, title: student.mn, form_cfgs: [[school_turn, student]]) do |f| %>
|
|
296
|
+
<%= f.input :person, as: :select, collection: school_turn.possible_students.collect { |p| [p.nominativo, p.id] } %>
|
|
297
|
+
<%= f.input :year, as: :bs_readonly, :display_field => :nome %>
|
|
298
|
+
|
|
299
|
+
<%= render 'tikal_dish_core/school_turns/turns_row.html', f: f %>
|
|
300
|
+
<% end %>
|
|
301
|
+
|
|
302
|
+
possibile anche passare una proc per generare i bottoni della modal in modo differente dallo standard, vedere documentazione
|
|
303
|
+
|
|
304
|
+
==== modal_edit_button
|
|
305
|
+
Genera il bottone per editazione con una modal del contenuto,
|
|
306
|
+
gli viene passato un block contenente la modal da lanciare per l'editazione,
|
|
307
|
+
solitamente generata con modal_form_generator.
|
|
308
|
+
come parametri viene passato l'id del target che si aspetta di richiamare
|
|
309
|
+
<code>
|
|
310
|
+
ES:
|
|
311
|
+
modal_edit_button do |id|
|
|
312
|
+
render 'tikal_core/people/person_contacts/modal_form', :contact => contact, :id => id %>
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
Options:
|
|
316
|
+
|
|
317
|
+
- align: left|rigth
|
|
318
|
+
- updatable_content: elemento da rimpiazzare con il partial restituito
|
|
319
|
+
- class: classi aggiuntive per selezionare meglio il bottone
|
|
320
|
+
- bnt_icon: Symbol che identifica che icona utilizzare per il bottone
|
|
321
|
+
</code>
|
|
322
|
+
|
|
323
|
+
==== modal_delete_button
|
|
324
|
+
Genera il bottone per la cancellazione di un record, viene creata una relativa modal
|
|
325
|
+
per la conferma
|
|
326
|
+
<code>
|
|
327
|
+
ES:
|
|
328
|
+
<%= modal_delete_button(cliente_referente_path(referente.cliente, referente, :json),
|
|
329
|
+
callback_remove: "##{id}",
|
|
330
|
+
:bnt_icon => 'times fw') %>
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
modal_delete_button(path, [options])
|
|
334
|
+
path -> resource to delete
|
|
335
|
+
options:
|
|
336
|
+
* confirm : Text to display in modal
|
|
337
|
+
* align : left|right
|
|
338
|
+
* callback_remove : id dell'elemento da rimuove una volta avuto successo il javascript di cancellazione
|
|
339
|
+
* bnt_icon : Symbol che identifica che icona utilizzare per il bottone [:times]
|
|
340
|
+
</code>
|
|
341
|
+
|
|
342
|
+
==== multiple_elements_table
|
|
343
|
+
Genera la struttura di una tabella per la gestione dei campi nested multipli.
|
|
344
|
+
multiple_elements_table( "form di formtastic","relazione nel modello nested","elenco campi da visualizzare")
|
|
345
|
+
possibile blocco: vedi docs
|
|
346
|
+
<code>
|
|
347
|
+
<%= f.inputs :name => PriceRange.mnp, class: 'form-inline CLASSE_CONTAINER' do %>
|
|
348
|
+
<%= multiple_elements_table(f, :price_ranges, [:from_val, :to_val, :price]) %>
|
|
349
|
+
<% end %>
|
|
350
|
+
</code>
|
|
351
|
+
Ricordarsi poi di aggiungere negli assets anche la funzione per duplicare le righe e per cancellarle
|
|
352
|
+
<code>
|
|
353
|
+
$('.CLASSE_CONTAINER').multiple_table()
|
|
354
|
+
</code>
|
|
355
|
+
Nel modello dobbiamo inserire i comandi per il nested:
|
|
356
|
+
<code>
|
|
357
|
+
has_many :price_ranges, :dependent => :destroy
|
|
358
|
+
accepts_nested_attributes_for :price_ranges, allow_destroy: true
|
|
359
|
+
validates_associated :price_ranges
|
|
360
|
+
</code>
|
|
361
|
+
Nella policy/controller dobbiamo preoccuparci di avere anche i permitted attributes corretti
|
|
362
|
+
<code>
|
|
363
|
+
:price_ranges_attributes => [:from_val, :to_val, :price, :id, :_destroy]
|
|
364
|
+
</code>
|
|
365
|
+
|
|
366
|
+
=== bs_tree
|
|
367
|
+
Genera un'albero con bootstrap-tree
|
|
368
|
+
deve ricevere un array di dati da trasformare in json.
|
|
369
|
+
per come scrivere il parametro data vedi
|
|
370
|
+
https://github.com/jonmiles/bootstrap-treeview
|
|
371
|
+
<code>
|
|
372
|
+
bs_tree(
|
|
373
|
+
[
|
|
374
|
+
{
|
|
375
|
+
:text => 'ciao',
|
|
376
|
+
state:
|
|
377
|
+
{
|
|
378
|
+
expanded: false
|
|
379
|
+
},
|
|
380
|
+
nodes:
|
|
381
|
+
[
|
|
382
|
+
{
|
|
383
|
+
text: 'pipo'
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
:text => 'marino'
|
|
389
|
+
}
|
|
390
|
+
]
|
|
391
|
+
)
|
|
392
|
+
</code>
|
|
393
|
+
|
|
394
|
+
== Inputs Formtastic per bootstrap
|
|
395
|
+
Una serie di inputs per formtastic con bootstrap
|
|
396
|
+
===Utilizzo
|
|
397
|
+
Ricordiamo di mettere kono_utils come gemma sucessivamente a formtastic.
|
|
398
|
+
se si vogliono anche gli input :
|
|
399
|
+
bs_aceeditor
|
|
400
|
+
bs_datetimepicker inject_js => True|False|Hash per ozioni js
|
|
401
|
+
- server_format: 'YYYY-MM-DD',
|
|
402
|
+
- server_match: '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',
|
|
403
|
+
- format: 'DD/MM/YYYY HH:mm'
|
|
404
|
+
bs_datepicker Come il bs_datetimepicker_input ma con già presenti i settaggi corretti
|
|
405
|
+
bs_readonly
|
|
406
|
+
bs_file_download visualizza un campo per il caricamento dei files e il relativo bottone di download
|
|
407
|
+
bs_image visualizza campo caricamento e in parte l'immagine caricata se caricata
|
|
408
|
+
bs_label_with_container Rende possibile inserire dentro al contenitore della input un qualsiasi
|
|
409
|
+
contenuto tramite una proc passata come opzione :content
|
|
410
|
+
<code>
|
|
411
|
+
content: Proc.new {
|
|
412
|
+
bf = ActiveSupport::SafeBuffer.new
|
|
413
|
+
|
|
414
|
+
bf<< f.file_field(:convenz_document)
|
|
415
|
+
|
|
416
|
+
bf
|
|
417
|
+
}
|
|
418
|
+
</code>
|
|
419
|
+
bs_timepicker
|
|
420
|
+
serve includere anche la gemma:
|
|
421
|
+
gem 'font-awesome-rails', '~> 4.3.0' #https://github.com/bokmann/font-awesome-rails
|
|
422
|
+
|
|
423
|
+
= Utilities Style CSS
|
|
424
|
+
|
|
425
|
+
== Spacer
|
|
426
|
+
classi per una spaziatura verticale , utilizzare
|
|
427
|
+
passando la classe generale v-space e poi il valore scelto: space-x1
|
|
428
|
+
ogni valore dello spacer rappresente 0.2em
|
|
429
|
+
da 1 a 20 come valore di moltiplicatore
|
|
430
|
+
|
|
431
|
+
=== Utilizzo
|
|
432
|
+
<div class="kono-v-spacer space-x2"></div> => 0.4em
|
|
433
|
+
|
|
434
|
+
== Fiscal code
|
|
435
|
+
Classe KonoUtils::FiscalCode per verificare validità codice fiscale e partita iva dai rispettivi caratteri fi controllo
|
|
436
|
+
|
|
437
|
+
=== Utilizzo
|
|
438
|
+
KonoUtils::FiscalCode::ControllaCF(codice_fiscale, strict = false) Controllo dell'esattezza del codice fiscale
|
|
439
|
+
verificando il carattere di controllo
|
|
440
|
+
KonoUtils::FiscalCode::ControllaPI(partita_iva) Controllo dell'esattezza della partita iva dal carattere di controllo
|
|
441
|
+
Inoltre rispetto a questo argomento è stata aggiunta anche la gemma codice-fiscale https://github.com/topac/codice_fiscale
|
|
442
|
+
Che permette di calcolare il codice fiscale partendo dai dati anagrafici di una persona.
|