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.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/README.rdoc +0 -76
  3. data/app/assets/javascripts/kono_utils/core.coffee +477 -0
  4. data/app/assets/stylesheets/kono_utils/{_kono_styles.css.scss → core.css.scss} +1 -16
  5. data/app/policies/kono_utils/base_editing_policy_concern.rb +52 -3
  6. data/app/policies/kono_utils/base_search_form_policy_concern.rb +25 -0
  7. data/config/locales/it.yml +3 -1
  8. data/lib/generators/kono_utils/install/install_generator.rb +40 -3
  9. data/lib/generators/templates/base_editing_controller.template +3 -0
  10. data/lib/generators/templates/base_editing_helper.template +3 -0
  11. data/lib/generators/templates/base_editing_policy.template +4 -0
  12. data/lib/generators/templates/initializer.rb +3 -1
  13. data/lib/kono_utils.rb +20 -22
  14. data/lib/kono_utils/application_core_helper.rb +524 -0
  15. data/lib/kono_utils/application_enum_helper.rb +53 -0
  16. data/lib/kono_utils/application_helper.rb +4 -578
  17. data/lib/kono_utils/base_editing_core_helper.rb +194 -0
  18. data/lib/kono_utils/base_editing_helper.rb +3 -186
  19. data/lib/kono_utils/base_search.rb +32 -19
  20. data/lib/kono_utils/concerns/active_record_translation.rb +8 -4
  21. data/lib/kono_utils/concerns/active_storage_remover_helper.rb +61 -0
  22. data/lib/kono_utils/concerns/base_editing.rb +199 -53
  23. data/lib/kono_utils/configuration.rb +18 -0
  24. data/lib/kono_utils/engine.rb +15 -7
  25. data/lib/kono_utils/paginate_proxer.rb +17 -0
  26. data/lib/kono_utils/search_form_builder.rb +24 -0
  27. data/lib/kono_utils/version.rb +1 -1
  28. data/spec/dummy/app/assets/config/manifest.js +2 -0
  29. data/spec/dummy/app/assets/javascripts/application.js +1 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  31. data/spec/dummy/app/controllers/base_editing_controller.rb +3 -0
  32. data/spec/dummy/app/controllers/users_controller.rb +2 -0
  33. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  34. data/spec/dummy/app/helpers/base_editing_helper.rb +3 -0
  35. data/spec/dummy/app/models/application_record.rb +5 -0
  36. data/spec/dummy/app/models/user.rb +2 -0
  37. data/spec/dummy/app/policies/application_policy.rb +49 -0
  38. data/spec/dummy/app/policies/base_editing_policy.rb +4 -0
  39. data/spec/dummy/app/policies/user_policy.rb +23 -0
  40. data/spec/dummy/config/application.rb +1 -1
  41. data/spec/dummy/config/initializers/kono_utils.rb +3 -1
  42. data/spec/dummy/config/routes.rb +4 -0
  43. data/spec/dummy/db/migrate/20190716093114_create_users.rb +11 -0
  44. data/spec/dummy/db/schema.rb +23 -0
  45. data/spec/dummy/spec/models/user_spec.rb +5 -0
  46. metadata +63 -131
  47. data/app/assets/javascripts/kono_utils/utilities.coffee +0 -480
  48. data/app/assets/stylesheets/kono_utils/utils.css.scss +0 -4
  49. data/app/input/bs_aceeditor_input.rb +0 -53
  50. data/app/input/bs_autocomplete_input.rb +0 -60
  51. data/app/input/bs_datepicker_input.rb +0 -16
  52. data/app/input/bs_datetimepicker_input.rb +0 -80
  53. data/app/input/bs_file_download_input.rb +0 -35
  54. data/app/input/bs_image_input.rb +0 -35
  55. data/app/input/bs_label_with_container_input.rb +0 -22
  56. data/app/input/bs_location_picker_input.rb +0 -95
  57. data/app/input/bs_readonly_input.rb +0 -52
  58. data/app/input/bs_timepicker_input.rb +0 -14
  59. data/app/views/kono_utils/application/_search_panel.html.erb +0 -36
  60. data/app/views/kono_utils/base_editing/_edit.html.erb +0 -3
  61. data/app/views/kono_utils/base_editing/_edit_page_side_title_header.html.erb +0 -3
  62. data/app/views/kono_utils/base_editing/_edit_page_title_header.html.erb +0 -3
  63. data/app/views/kono_utils/base_editing/_form.html.erb +0 -15
  64. data/app/views/kono_utils/base_editing/_index_buttons.html.erb +0 -2
  65. data/app/views/kono_utils/base_editing/_index_page_side_title_header.html.erb +0 -3
  66. data/app/views/kono_utils/base_editing/_index_page_title_header.html.erb +0 -3
  67. data/app/views/kono_utils/base_editing/_index_tfoot.html.erb +0 -0
  68. data/app/views/kono_utils/base_editing/_new.html.erb +0 -3
  69. data/app/views/kono_utils/base_editing/_new_page_side_title_header.html.erb +0 -3
  70. data/app/views/kono_utils/base_editing/_new_page_title_header.html.erb +0 -3
  71. data/app/views/kono_utils/base_editing/_search_form.html.erb +0 -1
  72. data/app/views/kono_utils/base_editing/application/_edit_page_side_title_header.html.erb +0 -1
  73. data/app/views/kono_utils/base_editing/application/_edit_page_title_header.html.erb +0 -1
  74. data/app/views/kono_utils/base_editing/application/_index_page_side_title_header.html.erb +0 -1
  75. data/app/views/kono_utils/base_editing/application/_index_page_title_header.html.erb +0 -1
  76. data/app/views/kono_utils/base_editing/application/_new_page_side_title_header.html.erb +0 -1
  77. data/app/views/kono_utils/base_editing/application/_new_page_title_header.html.erb +0 -1
  78. data/app/views/kono_utils/base_editing/application/edit.html.erb +0 -1
  79. data/app/views/kono_utils/base_editing/application/new.html.erb +0 -1
  80. data/app/views/kono_utils/base_editing/edit.html.erb +0 -1
  81. data/app/views/kono_utils/base_editing/index.html.erb +0 -36
  82. data/app/views/kono_utils/base_editing/new.html.erb +0 -1
  83. data/lib/kono_utils/concerns.rb +0 -10
  84. data/lib/kono_utils/encoder.rb +0 -47
  85. data/lib/kono_utils/fiscal_code.rb +0 -47
  86. data/lib/kono_utils/params_hash_array.rb +0 -37
  87. data/lib/kono_utils/percentage.rb +0 -60
  88. data/lib/kono_utils/tmp_file.rb +0 -81
  89. data/lib/kono_utils/virtual_model.rb +0 -22
  90. data/lib/tasks/kono_utils_tasks.rake +0 -4
  91. data/spec/lib/kono_utils/fiscal_code_spec.rb +0 -56
  92. data/vendor/assets/javascripts/EventEmitter.js +0 -473
@@ -1,3 +1,4 @@
1
+
1
2
  .kono_delete_button, .kono_edit_button {
2
3
  margin: 1px;
3
4
  &.align-right {
@@ -8,22 +9,6 @@
8
9
  }
9
10
  }
10
11
 
11
- .search_panel {
12
- .panel-title {
13
- .icon-search {
14
- cursor: pointer;
15
- }
16
- }
17
- }
18
-
19
- .bs_file_download {
20
- .form-wrapper {
21
- display: block;
22
- .input-group{
23
- width:100%;
24
- }
25
- }
26
- }
27
12
 
28
13
  //classi per una spaziatura verticale , utilizzare
29
14
  // passando la classe generale v-space e poi il valore scelto: space-x1
@@ -5,10 +5,59 @@ module KonoUtils
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
+
9
+ ##
10
+ # elenco degli attributi filtrati alla ricezione nel controller
11
+ # @return [Array<Symbol>]
8
12
  def permitted_attributes
9
- # [:descrizione]
13
+ cleard_columns+virtual_appended_attributes
14
+ end
15
+
16
+ ##
17
+ # elenco attributi editabili nella form
18
+ # @return [Array<Symbol>]
19
+ def editable_attributes
20
+ cleard_columns
21
+ end
22
+
23
+ ##
24
+ # elenco attributi visualizzabili nella show
25
+ # @return [Array<Symbol>]
26
+ def displayable_attributes
27
+ editable_attributes
28
+ end
29
+
30
+ ##
31
+ # Elenco attributi da visualizzare, utilizzati nella vista della index
32
+ # @return [Array<Symbol>]
33
+ def show_attributes
34
+ cleard_columns
35
+ end
36
+
37
+ private
38
+
39
+ def cleard_columns
10
40
  record.class.column_names.collect { |s| s.to_sym } - [:id, :created_at, :updated_at]
11
41
  end
42
+
43
+ ##
44
+ # Elenco di attributi generati dinamicamente da KonoUtils.
45
+ # Come ad esempio l'attributo per la cancellazione del file allegato
46
+ # @return [Array<Symbol>]
47
+ def virtual_appended_attributes
48
+ out = []
49
+ if record.class.respond_to?(:attribute_purger_name)
50
+ record.class.instance_methods.each do |c|
51
+ next if c.match(/=$/) #skippiamo per i writers
52
+ if record.respond_to?(record.class.attribute_purger_name(c))
53
+ Rails.logger.debug c.inspect
54
+ out << record.class.attribute_purger_name(c)
55
+ end
56
+ end
57
+ end
58
+ out
59
+ end
60
+
12
61
  end
13
62
 
14
63
  if defined? ::Application::Scope
@@ -19,9 +68,9 @@ module KonoUtils
19
68
  end
20
69
  end
21
70
 
22
- # module ClassMethods
71
+ # module ClassMethods
23
72
 
24
- # end
73
+ # end
25
74
  end
26
75
  end
27
76
 
@@ -0,0 +1,25 @@
1
+ require 'active_support/concern'
2
+ module KonoUtils
3
+
4
+ module BaseSearchFormPolicyConcern
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+
9
+ ##
10
+ # elenco degli attributi filtrati alla ricezione nel controller
11
+ def permitted_attributes
12
+ record.search_attributes.collect(&:field)
13
+ end
14
+
15
+ alias_method :editable_attributes, :permitted_attributes
16
+
17
+ end
18
+
19
+
20
+ # module ClassMethods
21
+
22
+ # end
23
+ end
24
+ end
25
+
@@ -15,4 +15,6 @@ it:
15
15
  messages:
16
16
  created: "%{model} creato correttamente."
17
17
  updated: "%{model} aggiornato correttamente."
18
- destroyed: "%{model} è stato correttamente cancellato."
18
+ destroyed: "%{model} è stato correttamente cancellato."
19
+ kono_utils:
20
+ user_not_authorized: Utente non autorizzato a modificare %{model}
@@ -19,12 +19,49 @@ module KonoUtils
19
19
  copy_file 'initializer.rb', 'config/initializers/kono_utils.rb'
20
20
  end
21
21
 
22
+ def install_pundit
23
+ run "rails g pundit:install"
24
+ end
25
+
26
+ def install_helper_on_application_helper
27
+ inject_into_file 'app/helpers/application_helper.rb', "\n include KonoUtils::ApplicationHelper", after: "module ApplicationHelper"
28
+ end
29
+
30
+ def install_active_record_traslation_on_application_record
31
+ inject_into_file 'app/models/application_record.rb', "\n include KonoUtils::Concerns::ActiveRecordTranslation\n", after: "ActiveRecord::Base"
32
+ inject_into_file 'app/models/application_record.rb', "\n include KonoUtils::Concerns::ActiveStorageRemoverHelper\n", after: "ActiveRecord::Base"
33
+ rescue Exception => e
34
+ puts "Attenzione, includere a mano:
35
+ - KonoUtils::Concerns::ActiveRecordTranslation
36
+ - KonoUtils::Concerns::ActiveStorageRemoverHelper
37
+ nel modello da cui darivano i modelli del base editing - #{e.message}"
38
+ end
39
+
40
+ def append_gem_dependency
41
+ append_to_file 'Gemfile', "# gem 'codice_fiscale'"
42
+ rescue Exception => e
43
+ puts e.message
44
+ end
45
+
46
+
47
+
22
48
  def install_node_dependency
23
- run "yarn add patternfly-bootstrap-treeview"
49
+ pacchetti_yarn = ["underscore"]#"wolfy87-eventemitter",
50
+
51
+ run "yarn add #{pacchetti_yarn.join(" ")}"
24
52
  end
25
53
 
26
- def append_js_dependecy_to_assets
27
- inject_into_file 'app/assets/javascripts/application.js',"//= require kono_utils/utilities\n", before: "//= require_tree ."
54
+ def base_editing_install
55
+ resp = ask "Vuoi che installi la struttura base del controller e base editing? y/n"
56
+ if resp=='y'
57
+ @controller_da_cui_derivare = ask("Controller da cui derivare il BaseEditingController?[RestrictedAreaController]")
58
+ @controller_da_cui_derivare = "RestrictedAreaController" if @controller_da_cui_derivare.blank?
59
+ template('base_editing_controller.template','app/controllers/base_editing_controller.rb')
60
+ template('base_editing_helper.template','app/helpers/base_editing_helper.rb')
61
+ template('base_editing_policy.template','app/policies/base_editing_policy.rb')
62
+ say "Tutti i Controller che dovranno lavorare con il base editing dovranno derivare da BaseEditingController"
63
+ say "Tutte le policy che dovranno lavorare con il base editing dovranno derivare da BaseEditingPolicy"
64
+ end
28
65
  end
29
66
 
30
67
  end
@@ -0,0 +1,3 @@
1
+ class BaseEditingController < <%= @controller_da_cui_derivare %>
2
+ include KonoUtils::Concerns::BaseEditing
3
+ end
@@ -0,0 +1,3 @@
1
+ module BaseEditingHelper
2
+ include KonoUtils::BaseEditingHelper
3
+ end
@@ -0,0 +1,4 @@
1
+ class BaseEditingPolicy < ApplicationPolicy
2
+ include KonoUtils::BaseEditingPolicyConcern
3
+
4
+ end
@@ -1,3 +1,5 @@
1
1
  KonoUtils.configure do |config|
2
2
  #config.google_api_key = '' #chiave API
3
- end
3
+ end
4
+
5
+ Rails.application.config.action_controller.include_all_helpers=false
@@ -1,27 +1,29 @@
1
- require 'kono_utils/engine' if defined?(::Rails)
1
+ require "zeitwerk"
2
+ loader = Zeitwerk::Loader.for_gem
3
+ loader.ignore("#{__dir__}/generators")
2
4
 
3
- module KonoUtils
4
- extend ActiveSupport::Autoload
5
-
6
- autoload :VirtualModel
7
- autoload :Encoder
8
- autoload :ParamsHashArray
9
- autoload :Percentage
10
- autoload :FiscalCode
11
- autoload :TmpFile
12
- autoload :ApplicationHelper
13
- autoload :BaseEditingHelper
14
- autoload :BaseSearch
15
- autoload :Concerns
16
-
17
- class Configuration
18
- attr_accessor :google_api_key
5
+
6
+ if defined?(::Rails)
7
+ if Rails.gem_version <= Gem::Version.new('4.2.0')
8
+ # Non facciamo eager load nel caso di nuovi rails
9
+ translations_concerns = "#{__dir__}/kono_utils/concerns/active_record_translation"
10
+ loader.do_not_eager_load(translations_concerns)
19
11
  end
12
+ else
13
+ # non carichiamo l'engine se non presente rails
14
+ loader.do_not_eager_load("#{__dir__}/kono_utils/engine")
15
+ end
16
+
17
+ loader.enable_reloading # you need to opt-in before setup
18
+ loader.setup
19
+
20
+ module KonoUtils
20
21
 
21
22
  class << self
22
23
  attr_writer :configuration
23
24
  end
24
25
 
26
+ # @return [Configuration]
25
27
  def self.configuration
26
28
  @configuration ||= Configuration.new
27
29
  end
@@ -34,8 +36,4 @@ module KonoUtils
34
36
  end
35
37
 
36
38
 
37
- if defined?(::Rails)
38
- if Rails.gem_version > Gem::Version.new('4.2.0')
39
- require 'kono_utils/concerns/active_record_translation'
40
- end
41
- end
39
+ loader.eager_load
@@ -0,0 +1,524 @@
1
+ module KonoUtils
2
+ module ApplicationCoreHelper
3
+
4
+ # def self.included(base)
5
+ #
6
+ #
7
+ #
8
+ # base.send :include, FontAwesome::Rails::IconHelper
9
+ #
10
+ # end
11
+
12
+ # def will_paginate_bst(collection)
13
+ # will_paginate collection, renderer: BootstrapPagination::Rails
14
+ # end
15
+
16
+
17
+ ##
18
+ # Crea un DIV che racchiude tutto il contenuto all'interno della classe utilizzata, splittando il nome della classe
19
+ # per suoi moduli, rendendo quindi filtrabile il contenuto sottostante
20
+ # @param [Proc] block -> contenuto che verrà inserito nel content
21
+ # @return [String]
22
+ def namespace_content(&block)
23
+ content_tag :div, class: "#{(controller.class.name.split("::") + [action_name]).join(" ")}" do
24
+ yield
25
+ end
26
+
27
+ end
28
+
29
+ # def true_false_label(val)
30
+ #
31
+ # if val
32
+ # icon =fa_icon(:check)
33
+ # classe='success'
34
+ # else
35
+ # classe='danger'
36
+ # icon =fa_icon(:times)
37
+ # end
38
+ #
39
+ # content_tag(:span, icon, class: "label label-#{classe}")
40
+ #
41
+ # end
42
+
43
+
44
+ ##
45
+ # Genera una modal da riutilizzare per far aspettare determinate operazioni al client
46
+ # def bootstrap_please_wait
47
+ # content_tag(:div,
48
+ # class: 'modal fade',
49
+ # id: 'processing_wait',
50
+ # tabindex: "-1",
51
+ # role: "dialog",
52
+ # "aria-hidden".to_sym => "true") do
53
+ # content_tag :div, class: 'modal-dialog modal-sm' do
54
+ # content_tag :div, class: 'modal-content' do
55
+ #
56
+ # buff = ActiveSupport::SafeBuffer.new
57
+ #
58
+ # buff << content_tag(:div, class: 'modal-header') do
59
+ # content_tag(:h4, "Processing...", class: "modal-title")
60
+ # end
61
+ #
62
+ # buff << content_tag(:div, class: 'modal-body') do
63
+ # content_tag :div, class: "progress" do
64
+ # content_tag :div, ' ', class: "progress-bar progress-bar-striped active", role: "progressbar", style: "width: 100%"
65
+ # end
66
+ # end
67
+ #
68
+ # buff
69
+ # end
70
+ # end
71
+ # end
72
+ # end
73
+
74
+
75
+ ##
76
+ # Genera la form di ricerca
77
+ # * *Args* :
78
+ # - search_model -> KonoUtils::BaseSearch
79
+ # - args -> Hash with configurations:
80
+ # - attributes -> array of symbols for the search, if empty used from search_model
81
+ # - reset_path -> path per cui resettare la ricerca, nil
82
+ # - form_opts -> opzioni da aggiungere per la form
83
+ # - buttons_editor -> Proc chiamata, con il passaggio dell'oggetto della form e
84
+ # del ActiveSupport::SafeBuffer con all'interno dei bottoni
85
+ # come parametro, deve ritornare
86
+ # un ActiveSupport::SafeBuffer a sua volta
87
+ # * *Returns* :
88
+ # -
89
+ #
90
+ # def search_form(search_model, args={})
91
+ #
92
+ # args = {
93
+ # :attributes => [],
94
+ # :reset_path => nil,
95
+ # :form_opts => {},
96
+ # :field_option => {:wrapper_html => {:class => "col-xs-12 col-sm-6 col-md-4 col-lg-3"}},
97
+ # :buttons_editor => Proc.new {|form_obj, sb| sb}
98
+ # }.merge(args)
99
+ #
100
+ # base_search_form_wrapper(search_model, {:attributes => args[:attributes], :form_opts => args[:form_opts]}) do |f|
101
+ #
102
+ # render :partial => '/application/search_panel.html', locals: {
103
+ # form: f,
104
+ # search_model: search_model
105
+ # }.merge(args)
106
+ #
107
+ # end
108
+ #
109
+ # end
110
+
111
+ # class BaseSearchFormWrapper < Struct.new(:formtastic_form, :attributes, :current_user)
112
+ #
113
+ # def fields_builder(cfgs={field_options: {}})
114
+ # form_buffer = ActiveSupport::SafeBuffer.new
115
+ #
116
+ # self.attributes.each do |field|
117
+ #
118
+ # form_options = field.form_options
119
+ # if form_options.is_a?(Proc)
120
+ # form_options = form_options.call(current_user, self.formtastic_form)
121
+ # end
122
+ #
123
+ # form_buffer << self.formtastic_form.input(field.field, cfgs[:field_options].merge(form_options))
124
+ # end
125
+ #
126
+ # form_buffer
127
+ # end
128
+ # end
129
+
130
+ ##
131
+ # Utility interna che si occupa della logica minima per generare la il form di ricerca
132
+ # def base_search_form_wrapper(search_model, args={:attributes => [], :form_opts => {}})
133
+ # attributes = args[:attributes] || {}
134
+ # form_opts = args[:form_opts] || {}
135
+ # if attributes.length==0
136
+ # attributes = search_model.search_attributes
137
+ # end
138
+ #
139
+ # form_opts = {method: :get, :html => {autocomplete: 'off'}}.merge(form_opts)
140
+ #
141
+ # semantic_form_for search_model, form_opts do |f|
142
+ # yield BaseSearchFormWrapper.new(f, attributes, @current_user)
143
+ # end
144
+ # end
145
+
146
+
147
+ ##
148
+ # Helper per generare una modal con all'interno un form
149
+ # Utilizzare passando un block il quale riceve come parametro la form di formtastic
150
+ # possibile passare anche una proc in buttons_proc per scrivere in modo differente i bottoni nella modal,
151
+ # alla proc viene passato il solito form di formtastic e il bottone standard di chiusura
152
+ #
153
+ # def modal_form_generator(args = {})
154
+ #
155
+ # args = {
156
+ # id: 'modal',
157
+ # class: '',
158
+ # title: 'Titolo',
159
+ # form_cfgs: [],
160
+ # buttons_proc: Proc.new do |f, default_close_btn|
161
+ # default_close_btn +
162
+ # f.action(:submit, button_html: {class: 'btn btn-primary'}, :label => :save_and_close)
163
+ # end
164
+ # }.merge(args)
165
+ #
166
+ # raise 'Passare le configurazioni per la form' if args[:form_cfgs]==[]
167
+ #
168
+ # default_close_btn = content_tag(:button, 'Chiudi', type: 'button', class: 'btn btn-default', data: {dismiss: "modal"})
169
+ #
170
+ # content_tag(:div,
171
+ # class: "modal fade kono_modal_form",
172
+ # id: args[:id],
173
+ # tabindex: "-1",
174
+ # role: "dialog",
175
+ # "aria-hidden".to_sym => "true") do
176
+ # content_tag :div, class: 'modal-dialog' do
177
+ # semantic_form_for(*args[:form_cfgs]) do |f|
178
+ # content_tag :div, class: 'modal-content' do
179
+ #
180
+ # buff = ActiveSupport::SafeBuffer.new
181
+ #
182
+ # buff << content_tag(:div, class: 'modal-header') do
183
+ # content_tag(:button, raw("&times;"), type: "button", class: "close", data: {dismiss: 'modal'}, "aria-hidden".to_sym => "true") +
184
+ # content_tag(:h4, args[:title], class: "modal-title")
185
+ # end
186
+ #
187
+ # buff << content_tag(:div, class: 'modal-body') do
188
+ # yield f
189
+ # end
190
+ #
191
+ # buff << content_tag(:div, class: 'modal-footer') do
192
+ # args[:buttons_proc].call(f, default_close_btn)
193
+ # end
194
+ #
195
+ # buff
196
+ # end
197
+ # end
198
+ # end
199
+ # end
200
+ #
201
+ # end
202
+
203
+
204
+ ##
205
+ # Genera il bottone per editazione con una modal del contenuto,
206
+ # gli viene passato un block contenente la modal da lanciare per l'editazione,
207
+ # solitamente generata con modal_form_generator.
208
+ # come parametri viene passato l'id del target che si aspetta di richiamare
209
+ #
210
+ # ES:
211
+ # modal_edit_button do |id|
212
+ # render 'tikal_core/people/person_contacts/modal_form', :contact => contact, :id => id %>
213
+ # end
214
+ #
215
+ # Attributes:
216
+ # align: left|rigth
217
+ # updatable_content: elemento da rimpiazzare con il partial restituito
218
+ # class: classi aggiuntive per selezionare meglio il bottone
219
+ # btn_class: classi aggiuntive del bottone
220
+ # bnt_icon: Symbol che identifica che icona utilizzare per il bottone
221
+ #
222
+ #
223
+ # def modal_edit_button(*args, &block)
224
+ #
225
+ # options = {
226
+ # align: 'left',
227
+ # updatable_content: '',
228
+ # class: '',
229
+ # btn_class: '',
230
+ # bnt_icon: :edit
231
+ # }.merge(args.extract_options!)
232
+ #
233
+ # id = "#{SecureRandom.hex}"
234
+ #
235
+ #
236
+ # content_tag :div, class: "kono_edit_button align-#{options[:align]} #{options[:class]}", :data => {updatable_content: options[:updatable_content]} do
237
+ # buffer = ActiveSupport::SafeBuffer.new
238
+ #
239
+ # buffer << button_tag(data: {toggle: 'modal', target: "##{id}"}, class: "btn btn-default btn-xs #{options[:btn_class]}") {fa_icon(options[:bnt_icon])}
240
+ #
241
+ # buffer << capture do
242
+ # block.call(id)
243
+ # end
244
+ #
245
+ # buffer
246
+ # end
247
+ # end
248
+
249
+
250
+ ##
251
+ # Genera il bottone per la cancellazione di un elemento
252
+ #
253
+ # modal_delete_button(path, [options])
254
+ # path -> resource to delete
255
+ # options:
256
+ # * confirm : Text to display in modal
257
+ # * align : left|right
258
+ # * callback_remove : id dell'elemento da rimuove una volta avuto successo il javascript di cancellazione
259
+ # * bnt_icon : Symbol che identifica che icona utilizzare per il bottone
260
+ # def modal_delete_button(*args)
261
+ # options = {
262
+ # confirm: 'Sicuri di voler eliminare il record? L\'azione non è annullabile.',
263
+ # align: 'left',
264
+ # callback_remove: nil,
265
+ # bnt_icon: :times
266
+ # }.merge(args.extract_options!)
267
+ # path = args[0]
268
+ #
269
+ # id = "#{SecureRandom.hex}"
270
+ #
271
+ # content_tag :div, class: "tk_delete_button align-#{options[:align]}" do
272
+ #
273
+ # buffer = ActiveSupport::SafeBuffer.new
274
+ #
275
+ # buffer<<button_tag(data: {toggle: 'modal', target: "##{id}"}, class: 'btn btn-danger btn-xs') {fa_icon(options[:bnt_icon])}
276
+ #
277
+ # buffer<< content_tag(:div,
278
+ # class: 'modal fade',
279
+ # id: id,
280
+ # tabindex: "-1",
281
+ # role: "dialog",
282
+ # "aria-hidden".to_sym => "true") do
283
+ # form_tag(path, method: :delete, data: {callback_remove: options[:callback_remove]}) do
284
+ # content_tag :div, class: 'modal-dialog' do
285
+ # content_tag :div, class: 'modal-content' do
286
+ #
287
+ # buff = ActiveSupport::SafeBuffer.new
288
+ #
289
+ # buff << content_tag(:div, class: 'modal-header') do
290
+ # tmp_buff = ActiveSupport::SafeBuffer.new
291
+ # tmp_buff<<button_tag(fa_icon(:times), type: "button", class: "close", data: {dismiss: "modal"}, "aria-hidden".to_sym => true)
292
+ # tmp_buff<<content_tag(:h4, "Attenzione", class: "modal-title")
293
+ # tmp_buff
294
+ # end
295
+ #
296
+ # buff << content_tag(:div, options[:confirm], class: 'modal-body text-danger')
297
+ #
298
+ # buff << content_tag(:div, class: 'modal-footer') do
299
+ # button_tag('Annulla', type: "button", class: "btn btn-default", data: {dismiss: "modal"})+
300
+ # button_tag('Conferma', type: 'submit', class: "btn btn-danger")
301
+ # end
302
+ #
303
+ # buff
304
+ # end
305
+ #
306
+ # end
307
+ # end
308
+ # end
309
+ #
310
+ # buffer << content_tag(:script, raw("$('##{id} form').kono_delete_button();"), :type => 'text/javascript')
311
+ #
312
+ # buffer
313
+ # end
314
+ # end
315
+
316
+ ##
317
+ # Colleziona i mesi per la select box
318
+ def month_collection
319
+ (1..12).collect {|m| [t('date.month_names')[m].capitalize, m]}
320
+ end
321
+
322
+
323
+ ##
324
+ # Genera una collection degli anni per la select box
325
+ # parte da -8 a +1
326
+ #
327
+ def year_collection(start=-8, last=1)
328
+ ((Time.now.year+start)..(Time.now.year+last)).to_a.reverse
329
+ end
330
+
331
+ module_function :year_collection
332
+
333
+
334
+ ##
335
+ # Si occupa di generare la visualizzazione dell'exception passata, con informazioni
336
+ # aggiuntive se utente è super admin
337
+ # * *Args* :
338
+ # - exception -> Exception
339
+ # def bs_rescue_printer(exception)
340
+ # bff = ActiveSupport::SafeBuffer.new
341
+ #
342
+ # bff<< content_tag(:div, class: "alert alert-warning") do
343
+ # button_tag(raw("&times;"), data: {dismiss: "alert", hidden: "true"}, class: 'close') +
344
+ # content_tag(:strong, 'Errore') +
345
+ # " Attenzione, il codice eseguito non è valido, contattare l'amministratore."
346
+ # end
347
+ #
348
+ # if @current_user.is_super_admin?
349
+ #
350
+ # bff<<content_tag(:div, class: "panel panel-info") do
351
+ # tmp = ActiveSupport::SafeBuffer.new
352
+ # tmp<<content_tag(:div, class: "panel-heading") do
353
+ # content_tag :h3, "Messagio di Errore: #{exception.message} "
354
+ # end
355
+ # tmp<<content_tag(:div, class: "panel-body") do
356
+ # content_tag :pre, exception.backtrace.join("\n")
357
+ # end
358
+ #
359
+ # tmp
360
+ # end
361
+ # end
362
+ #
363
+ # bff
364
+ # end
365
+
366
+ ##
367
+ #
368
+ # * *Args* :
369
+ # - int -> Valore intero per definire
370
+ # - class -> optional classi aggiuntive
371
+ # * *Returns* :
372
+ # - content
373
+ #
374
+ # def bs_spacer(space, classe='')
375
+ # content_tag :div, nil, class: "v-spacer space-x#{space} #{classe}"
376
+ # end
377
+
378
+
379
+ ##
380
+ # Costruisce una tabella con i campi utili alla creazione di elementi multipli
381
+ #
382
+ # Attributes:
383
+ # form -> la form proveniente da formtastic
384
+ # field -> il campo referente dell'associazione
385
+ # fields -> elenco di campi su cui costruire le varie colonne
386
+ # options -> Hash di opzioni:
387
+ # :disable_duplication => [false] : server per disabilitare il bottone della duplicazione
388
+ #
389
+ # se gli si passa un blocco allora possiamo elaborare la costruzione dei differenti campi in modo personale
390
+ # al blocco viene passato la classe di formtastic della form, il campo, e un blocco contenente la proc per
391
+ # elaborare i campi in modo standard
392
+ #
393
+ # multiple_elements_table(form, :campo_has_many, [:label, :string_value, :number_value]) do |field, form|
394
+ # case field
395
+ # when :string_value, :number_value
396
+ # form.input field, label: false, input_html: {:autocomplete => 'off', class: 'toggle_value'}
397
+ # else
398
+ # form.input field, label: false, input_html: {:autocomplete => 'off'}
399
+ # end
400
+ # end
401
+ #
402
+ # Traduzioni delle colonne:
403
+ #
404
+ # modello_iniziale/campo_has_many:
405
+ # campo_del_has_many
406
+ #
407
+ #
408
+ # def multiple_elements_table(*params)
409
+ # options = params.extract_options!
410
+ #
411
+ # options = {:disable_duplication => false}.merge(options)
412
+ #
413
+ # form = params[0]
414
+ # field = params[1]
415
+ # fields = params[2]
416
+ #
417
+ # semantic_form_nested=[field]
418
+ #
419
+ # #inserimento logiche per scope su elenco elementi multipli
420
+ # unless options[:scope].nil?
421
+ # semantic_form_nested<<options[:scope]
422
+ # end
423
+ #
424
+ # content_tag :table, class: "table table-bordered" do
425
+ #
426
+ # b = ActiveSupport::SafeBuffer.new
427
+ #
428
+ # b<< content_tag(:thead) do
429
+ # content_tag :tr do
430
+ # c = ActiveSupport::SafeBuffer.new
431
+ #
432
+ # fields.each do |f|
433
+ # ::Rails.logger.debug {form.object.class.inspect}
434
+ # ::Rails.logger.debug {field}
435
+ # ::Rails.logger.debug {f.inspect}
436
+ # c<<content_tag(:th, form.object.class.human_attribute_name("#{field}.#{f}"), class: "multi_tab_#{f}")
437
+ # end
438
+ # unless options[:disable_duplication]
439
+ # c<<content_tag(:td, nil)
440
+ # end
441
+ #
442
+ # c
443
+ # end
444
+ # end
445
+ #
446
+ # b<<content_tag(:tbody) do
447
+ # form.semantic_fields_for(*semantic_form_nested) do |measure|
448
+ #
449
+ # default_execution = Proc.new {|field| measure.input field, :label => false}
450
+ #
451
+ # content_tag :tr, class: "form-inline list riga_misura" do
452
+ #
453
+ # d = ActiveSupport::SafeBuffer.new
454
+ #
455
+ # fields.each do |f|
456
+ # d<<content_tag(:td, class: "multi_tab_#{f}") do
457
+ #
458
+ # if block_given?
459
+ # yield(f, measure, default_execution)
460
+ # else
461
+ # default_execution.call(f)
462
+ # end
463
+ #
464
+ # end
465
+ # end
466
+ #
467
+ # unless options[:disable_duplication]
468
+ # d << content_tag(:td) do
469
+ #
470
+ # link_to "#", class: 'btn btn-xs btn-default add_one_more' do
471
+ #
472
+ # h = ActiveSupport::SafeBuffer.new
473
+ # h<< fa_icon(:plus)
474
+ # h<< measure.input(:_destroy, as: :hidden)
475
+ #
476
+ # h
477
+ # end
478
+ #
479
+ # end
480
+ # end
481
+ #
482
+ # d
483
+ # end
484
+ # end
485
+ # end
486
+ #
487
+ # b
488
+ # end
489
+ # end
490
+
491
+
492
+ ##
493
+ # Genera un'albero con bootstrap-tree
494
+ # deve ricevere un array di dati da trasformare in json.
495
+ # per come scrivere il parametro data vedi
496
+ # https://github.com/jonmiles/bootstrap-treeview
497
+ #
498
+ # def bs_tree(data)
499
+ #
500
+ # id_div = SecureRandom.hex(10)
501
+ #
502
+ # tmp = ActiveSupport::SafeBuffer.new
503
+ #
504
+ # tmp<< content_tag(:div, nil, id: id_div, class: 'bs_tree_list')
505
+ #
506
+ # tmp<< javascript_tag do
507
+ # raw "$('##{id_div}').treeview({data: #{data.to_json}});"
508
+ # end
509
+ #
510
+ # end
511
+
512
+ ##
513
+ # Stampa una data con il default delle date se questa non è nil
514
+ #
515
+ def print_rescue_date(date)
516
+ unless date.nil?
517
+ return l date.to_date
518
+ end
519
+ ''
520
+ end
521
+
522
+
523
+ end
524
+ end