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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
@import 'bootstrap-sprockets';
|
|
2
|
+
@import 'bootstrap';
|
|
3
|
+
@import 'bootstrap-datetimepicker';
|
|
4
|
+
|
|
5
|
+
.kono_delete_button, .kono_edit_button {
|
|
6
|
+
margin: 1px;
|
|
7
|
+
&.align-right {
|
|
8
|
+
float: right;
|
|
9
|
+
}
|
|
10
|
+
&.align-left {
|
|
11
|
+
float: left;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.search_panel {
|
|
16
|
+
.panel-title {
|
|
17
|
+
.icon-search {
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.bs_file_download {
|
|
24
|
+
.form-wrapper {
|
|
25
|
+
display: block;
|
|
26
|
+
.input-group{
|
|
27
|
+
width:100%;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//classi per una spaziatura verticale , utilizzare
|
|
33
|
+
// passando la classe generale v-space e poi il valore scelto: space-x1
|
|
34
|
+
// ogni valore dello spacer rappresente 0.2em
|
|
35
|
+
//ES:
|
|
36
|
+
// <div class="kono-v-spacer space-x2"></div> => 0.4em
|
|
37
|
+
.kono-v-spacer {
|
|
38
|
+
@for $i from 1 through 20 {
|
|
39
|
+
&.space-x#{$i} {
|
|
40
|
+
height: 0.2em * $i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class BsAceeditorInput < Formtastic::Inputs::StringInput
|
|
2
|
+
include FormtasticBootstrap::Inputs::Base
|
|
3
|
+
include FormtasticBootstrap::Inputs::Base::Collections
|
|
4
|
+
include ActionView::Helpers::TagHelper
|
|
5
|
+
include ActionView::Context
|
|
6
|
+
include FontAwesome::Rails::IconHelper
|
|
7
|
+
include ActionView::Helpers::JavaScriptHelper
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# Nel caso di collection si può definire con
|
|
12
|
+
# :show_hidden => [true] per stampare il campo hidden o meno con il vero valore
|
|
13
|
+
# :display_field come options quale campo usare per stampare
|
|
14
|
+
#
|
|
15
|
+
def to_html
|
|
16
|
+
|
|
17
|
+
theme = options[:theme] || 'twilight'
|
|
18
|
+
mode = options[:mode] || 'ruby'
|
|
19
|
+
height = options[:height] || '300px'
|
|
20
|
+
|
|
21
|
+
bootstrap_wrapping do
|
|
22
|
+
content_tag(:div) do
|
|
23
|
+
|
|
24
|
+
id = SecureRandom.hex
|
|
25
|
+
|
|
26
|
+
buff = ActiveSupport::SafeBuffer.new
|
|
27
|
+
|
|
28
|
+
buff<< content_tag(:div, :class => "container_editor clearfix", :style => 'width:100%;') do
|
|
29
|
+
content_tag(:div, object.send(method), id: id, style: "height:#{height};width:100px;")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
id_hidden = SecureRandom.hex
|
|
33
|
+
buff<< builder.hidden_field(method, form_control_input_html_options.merge(:id => id_hidden))
|
|
34
|
+
|
|
35
|
+
buff<< content_tag(:script, :type => "text/javascript") do
|
|
36
|
+
raw "var editor = ace.edit('#{id}');\n
|
|
37
|
+
editor.setTheme('ace/theme/#{theme}');\n
|
|
38
|
+
editor.getSession().setMode('ace/mode/#{mode}');\n
|
|
39
|
+
$('##{id}').width($('##{id}').closest('.container_editor').width());\n
|
|
40
|
+
editor.resize();\n
|
|
41
|
+
editor.getSession().on('change', function(e) {
|
|
42
|
+
$('##{id_hidden}').val(editor.getValue());
|
|
43
|
+
});
|
|
44
|
+
"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
buff
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
##
|
|
2
|
+
# <%= f.input :city,
|
|
3
|
+
# :as => :bs_autocomplete,
|
|
4
|
+
# :url => tikal_core.autocomplete_city_nome_autoclts_cities,
|
|
5
|
+
# :display_field => :nome,
|
|
6
|
+
# :value_field => :city_id %>
|
|
7
|
+
#
|
|
8
|
+
#
|
|
9
|
+
# -- display_field
|
|
10
|
+
# serve per indicare quale campo utilizzare come metodo per estrapolare i dati dal record associato
|
|
11
|
+
# può anche essere una proc a cui passiamo l'oggetto
|
|
12
|
+
# -- value_field
|
|
13
|
+
# indica quale campo utilizzare per estrapolare il dato del valore del record associato
|
|
14
|
+
# e quale nome dare al campo per creare una form corretta
|
|
15
|
+
#
|
|
16
|
+
#se è presente il Formtastic::Inputs::AutocompleteInput
|
|
17
|
+
begin
|
|
18
|
+
class BsAutocompleteInput < Formtastic::Inputs::AutocompleteInput
|
|
19
|
+
|
|
20
|
+
include FormtasticBootstrap::Inputs::Base
|
|
21
|
+
|
|
22
|
+
def input_html_options
|
|
23
|
+
id = super[:id]
|
|
24
|
+
|
|
25
|
+
opts = {class: "form-control", id: "autocomplete_#{id}"}
|
|
26
|
+
|
|
27
|
+
##Setto valore utilizzando le impostazioni di identificativo del campo per autocomplete :display_field
|
|
28
|
+
unless options[:display_field].nil?
|
|
29
|
+
opts[:value] = object.send(method).try(options[:display_field])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
super.merge(opts)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_html
|
|
36
|
+
bootstrap_wrapping do
|
|
37
|
+
buffer = ActiveSupport::SafeBuffer.new
|
|
38
|
+
|
|
39
|
+
html_options = input_html_options
|
|
40
|
+
|
|
41
|
+
hidden_field = nil
|
|
42
|
+
unless options[:value_field].nil?
|
|
43
|
+
hidden_id = "hidden_#{html_options[:id]}_#{SecureRandom.hex}"
|
|
44
|
+
html_options[:id_element] = "##{hidden_id}"
|
|
45
|
+
hidden_field = builder.hidden_field(options[:value_field], id: hidden_id)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
buffer << builder.autocomplete_field(method, options.delete(:url), html_options)
|
|
49
|
+
|
|
50
|
+
buffer << hidden_field unless hidden_field.nil?
|
|
51
|
+
|
|
52
|
+
buffer
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
rescue Exception => e
|
|
57
|
+
if defined?(Rails)
|
|
58
|
+
Rails.logger.debug {"Non riesco a caricare questa input BsAutocompleteInput #{__FILE__}"}
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Classe per la stampa del DatePicker con bootstrap
|
|
3
|
+
#
|
|
4
|
+
#
|
|
5
|
+
class BsDatepickerInput < BsDatetimepickerInput
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def default_javascript_options
|
|
9
|
+
{
|
|
10
|
+
server_format: 'YYYY-MM-DD',
|
|
11
|
+
server_match: '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',
|
|
12
|
+
format: 'DD/MM/YYYY'
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Classe per la stampa del DatetimePicker con bootstrap
|
|
3
|
+
#
|
|
4
|
+
# * *Opzioni* :
|
|
5
|
+
# - inject_js => True|False|Hash per ozioni js
|
|
6
|
+
#
|
|
7
|
+
class BsDatetimepickerInput < Formtastic::Inputs::StringInput
|
|
8
|
+
include FormtasticBootstrap::Inputs::Base
|
|
9
|
+
include ActionView::Helpers::TagHelper
|
|
10
|
+
include ActionView::Context
|
|
11
|
+
include FontAwesome::Rails::IconHelper
|
|
12
|
+
include ActionView::Helpers::JavaScriptHelper
|
|
13
|
+
include ActionView::Helpers::OutputSafetyHelper
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Serve per avere icone differenti nell'interfaccia
|
|
17
|
+
def icon
|
|
18
|
+
fa_icon(:calendar)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_html
|
|
22
|
+
|
|
23
|
+
bootstrap_wrapping do
|
|
24
|
+
tmp = ActiveSupport::SafeBuffer.new
|
|
25
|
+
|
|
26
|
+
tmp<< content_tag(:div, class: 'input-group date tk_date_time_picker', id: picker_container_id) do
|
|
27
|
+
builder.text_field(method, form_control_input_html_options)<<
|
|
28
|
+
content_tag(:span, icon, class: 'input-group-addon')
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if options[:inject_js]
|
|
33
|
+
tmp << javascript_initializations
|
|
34
|
+
end
|
|
35
|
+
tmp
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def picker_container_id
|
|
40
|
+
if @_container_id.nil?
|
|
41
|
+
@_container_id = "date_time_picker_#{form_control_input_html_options[:id]}_#{Random.new_seed}"
|
|
42
|
+
end
|
|
43
|
+
@_container_id
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def javascript_initializations
|
|
47
|
+
|
|
48
|
+
opt = options[:inject_js]
|
|
49
|
+
unless opt.is_a?(Hash)
|
|
50
|
+
opt ={}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
opt=default_javascript_options.merge(opt)
|
|
54
|
+
|
|
55
|
+
if block_given?
|
|
56
|
+
yield opt
|
|
57
|
+
else
|
|
58
|
+
content_tag(:script, :type => "text/javascript") do
|
|
59
|
+
raw "(function(){var data_picker = new Kn.utilities.DateTimePicker({
|
|
60
|
+
selector: $('##{picker_container_id}'),
|
|
61
|
+
server_format: \"#{opt[:server_format]}\",
|
|
62
|
+
server_match: #{opt[:server_match]},
|
|
63
|
+
format: \"#{opt[:format]}\"
|
|
64
|
+
}) ;
|
|
65
|
+
data_picker.initialize() ;
|
|
66
|
+
})();
|
|
67
|
+
"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def default_javascript_options
|
|
73
|
+
{
|
|
74
|
+
server_format: 'YYYY-MM-DD',
|
|
75
|
+
server_match: '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',
|
|
76
|
+
format: 'DD/MM/YYYY HH:mm'
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class BsFileDownloadInput < Formtastic::Inputs::StringInput
|
|
2
|
+
include FormtasticBootstrap::Inputs::Base
|
|
3
|
+
include FormtasticBootstrap::Inputs::Base::Collections
|
|
4
|
+
include ActionView::Helpers::TagHelper
|
|
5
|
+
include ActionView::Context
|
|
6
|
+
include ActionView::Helpers::UrlHelper
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Passare nelle opzioni la chiave :content con una proc che richiamo per generare il buffer
|
|
11
|
+
#
|
|
12
|
+
def to_html
|
|
13
|
+
|
|
14
|
+
bootstrap_wrapping do
|
|
15
|
+
content_tag(:div, class: 'input-group bs_label_with_content') do
|
|
16
|
+
content_tag(:div, class: 'row') do
|
|
17
|
+
tmp = ActiveSupport::SafeBuffer.new
|
|
18
|
+
|
|
19
|
+
tmp << content_tag(:div, class: "col-md-6") do
|
|
20
|
+
builder.input method, :label => false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if object.send(method).exists?
|
|
24
|
+
tmp << content_tag(:div, class: "col-md-6 col-lg-6") do
|
|
25
|
+
link_to I18n.t('formtastic.inputs.bs_file_download.download'), object.send(method).url, class: 'btn btn-default'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
tmp
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class BsImageInput < Formtastic::Inputs::StringInput
|
|
2
|
+
include FormtasticBootstrap::Inputs::Base
|
|
3
|
+
include FormtasticBootstrap::Inputs::Base::Collections
|
|
4
|
+
include ActionView::Helpers::TagHelper
|
|
5
|
+
include ActionView::Context
|
|
6
|
+
include ActionView::Helpers::AssetTagHelper
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Passare nelle opzioni la chiave :content con una proc che richiamo per generare il buffer
|
|
11
|
+
#
|
|
12
|
+
def to_html
|
|
13
|
+
|
|
14
|
+
bootstrap_wrapping do
|
|
15
|
+
content_tag(:div, class: 'input-group bs_label_with_content') do
|
|
16
|
+
content_tag(:div, class: 'row') do
|
|
17
|
+
tmp = ActiveSupport::SafeBuffer.new
|
|
18
|
+
|
|
19
|
+
tmp << content_tag(:div, class: "col-md-6 col-lg-6") do
|
|
20
|
+
builder.input method, :label => false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
if object.send(method).exists?
|
|
24
|
+
tmp << content_tag(:div, class: "col-md-6 col-lg-6") do
|
|
25
|
+
image_tag object.send(method).url,class:'img-responsive img-thumbnail',style:'max-height:200px;'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
tmp
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class BsLabelWithContainerInput < Formtastic::Inputs::StringInput
|
|
2
|
+
include FormtasticBootstrap::Inputs::Base
|
|
3
|
+
include FormtasticBootstrap::Inputs::Base::Collections
|
|
4
|
+
include ActionView::Helpers::TagHelper
|
|
5
|
+
include ActionView::Context
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
##
|
|
9
|
+
# Passare nelle opzioni la chiave :content con una proc che richiamo per generare il buffer
|
|
10
|
+
#
|
|
11
|
+
def to_html
|
|
12
|
+
|
|
13
|
+
bootstrap_wrapping do
|
|
14
|
+
content_tag(:div, class: 'input-group bs_label_with_content') do
|
|
15
|
+
buff = ActiveSupport::SafeBuffer.new
|
|
16
|
+
buff<< content_tag(:p, options[:content].call, class: 'form-control-static',id:"#{form_control_input_html_options[:id]}_container")
|
|
17
|
+
buff
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
class BsLocationPickerInput < Formtastic::Inputs::StringInput
|
|
2
|
+
include FormtasticBootstrap::Inputs::Base
|
|
3
|
+
include FormtasticBootstrap::Inputs::Base::Collections
|
|
4
|
+
include ActionView::Helpers::TagHelper
|
|
5
|
+
include ActionView::Context
|
|
6
|
+
include FontAwesome::Rails::IconHelper
|
|
7
|
+
include ActionView::Helpers::JavaScriptHelper
|
|
8
|
+
|
|
9
|
+
class ZoomInvalid < StandardError
|
|
10
|
+
def initialize(msg="Zoom non valido, deve essere intero")
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
##
|
|
17
|
+
# Stampa Una Mappa di Google Maps, che rende possibile la selezione di un punto sulla mappa
|
|
18
|
+
# e di salvarlo nei due campi Lat Lng della form.
|
|
19
|
+
#
|
|
20
|
+
# Necessario aver aggiunto anche l'asset kono_utils/utilities
|
|
21
|
+
# per avere il javascript necessario alla generazione della mappa
|
|
22
|
+
#
|
|
23
|
+
# Nell'inizializzatore di kono_utils installato con il generatore impostare la chiave di google:
|
|
24
|
+
# google_api_key
|
|
25
|
+
#
|
|
26
|
+
# La mappa ha un contenitore
|
|
27
|
+
#
|
|
28
|
+
# Options:
|
|
29
|
+
# - default_center -> Array con [lat,lng] nel caso non siano impostati i valori iniziali
|
|
30
|
+
# - height -> [300px] Altezza da mettere nello stile della canvas di google maps
|
|
31
|
+
# - fields -> Array[:lat,:lng] campi che identificano la Latitudine e Longitudine
|
|
32
|
+
# nel record
|
|
33
|
+
# - zoom_level -> [5] Integer livello zoom della mappa, se passo una Proc viene elaborata
|
|
34
|
+
# passando il record, deve tornare un Integer
|
|
35
|
+
#
|
|
36
|
+
def to_html
|
|
37
|
+
|
|
38
|
+
default_center = options[:default_center] || [42.90887521920127, 12.303765624999983]
|
|
39
|
+
center = default_center
|
|
40
|
+
|
|
41
|
+
height = options[:height] || '300px'
|
|
42
|
+
fields = options[:fields] || [:lat, :lng]
|
|
43
|
+
zoom_level = options[:zoom_level] || 5
|
|
44
|
+
|
|
45
|
+
if zoom_level.is_a?(Proc)
|
|
46
|
+
zoom_level = zoom_level.call(object)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
raise ZoomInvalid unless zoom_level.is_a?(Integer)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
bootstrap_wrapping do
|
|
53
|
+
content_tag(:div) do
|
|
54
|
+
|
|
55
|
+
id = SecureRandom.hex
|
|
56
|
+
|
|
57
|
+
callback_name = "initMap#{id}"
|
|
58
|
+
|
|
59
|
+
buff = ActiveSupport::SafeBuffer.new
|
|
60
|
+
|
|
61
|
+
buff<< content_tag(:div, :class => "container_google_maps clearfix", :style => 'width:100%;') do
|
|
62
|
+
content_tag(:div, nil, id: id, style: "height:#{height}")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
id_hidden_lat = SecureRandom.hex
|
|
66
|
+
buff<< builder.hidden_field(fields[0], form_control_input_html_options.merge(:id => id_hidden_lat))
|
|
67
|
+
id_hidden_lng = SecureRandom.hex
|
|
68
|
+
buff<< builder.hidden_field(fields[1], form_control_input_html_options.merge(:id => id_hidden_lng))
|
|
69
|
+
|
|
70
|
+
unless object.send(fields[0]).blank? or object.send(fields[1]).blank?
|
|
71
|
+
center = [object.send(fields[0]), object.send(fields[1])]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
buff<< content_tag(:script, :type => "text/javascript") do
|
|
75
|
+
raw "function #{callback_name}(){
|
|
76
|
+
$('##{id}').kono_util_location_picker({
|
|
77
|
+
center:{lat:#{center[0]},lng:#{center[1]}},
|
|
78
|
+
zoom_level:#{zoom_level},
|
|
79
|
+
selector_field_lat:'##{id_hidden_lat}',
|
|
80
|
+
selector_field_lng:'##{id_hidden_lng}'
|
|
81
|
+
});
|
|
82
|
+
}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
buff<< content_tag(:script, nil,
|
|
86
|
+
src: "https://maps.googleapis.com/maps/api/js?key=#{KonoUtils.configuration.google_api_key}&callback=#{callback_name}",
|
|
87
|
+
:type => "text/javascript", async: '', defer: '')
|
|
88
|
+
|
|
89
|
+
buff
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|