kono_utils_bootstrap_view4 0.1.0.pre.rc.3 → 0.1.0.pre.rc.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/concepts/kono_utils/object/cell/base.rb +99 -97
  3. data/app/concepts/kono_utils/object/cell/buttons/base.rb +55 -54
  4. data/app/concepts/kono_utils/object/cell/buttons/collapse_search.rb +29 -23
  5. data/app/concepts/kono_utils/object/cell/buttons/create.rb +20 -15
  6. data/app/concepts/kono_utils/object/cell/buttons/delete.rb +29 -24
  7. data/app/concepts/kono_utils/object/cell/buttons/download.rb +22 -16
  8. data/app/concepts/kono_utils/object/cell/buttons/edit.rb +17 -12
  9. data/app/concepts/kono_utils/object/cell/buttons/list.rb +17 -11
  10. data/app/concepts/kono_utils/object/cell/buttons/reset_search.rb +21 -15
  11. data/app/concepts/kono_utils/object/cell/create/base.rb +6 -5
  12. data/app/concepts/kono_utils/object/cell/create/page_title.rb +11 -6
  13. data/app/concepts/kono_utils/object/cell/create/side_title.rb +8 -2
  14. data/app/concepts/kono_utils/object/cell/edits/base.rb +6 -5
  15. data/app/concepts/kono_utils/object/cell/edits/page_title.rb +11 -6
  16. data/app/concepts/kono_utils/object/cell/edits/side_title.rb +9 -3
  17. data/app/concepts/kono_utils/object/cell/form.rb +51 -48
  18. data/app/concepts/kono_utils/object/cell/forms/base.rb +12 -10
  19. data/app/concepts/kono_utils/object/cell/forms/container.rb +22 -18
  20. data/app/concepts/kono_utils/object/cell/forms/containers/layout.rb +14 -10
  21. data/app/concepts/kono_utils/object/cell/forms/containers/modal_layout.rb +10 -4
  22. data/app/concepts/kono_utils/object/cell/forms/containers/search_layout.rb +10 -4
  23. data/app/concepts/kono_utils/object/cell/forms/containers/table_layout.rb +11 -5
  24. data/app/concepts/kono_utils/object/cell/forms/field_selector.rb +68 -64
  25. data/app/concepts/kono_utils/object/cell/forms/field_selectors/layout.rb +9 -4
  26. data/app/concepts/kono_utils/object/cell/forms/field_selectors/modal_layout.rb +10 -4
  27. data/app/concepts/kono_utils/object/cell/forms/field_selectors/table_layout.rb +11 -5
  28. data/app/concepts/kono_utils/object/cell/forms/fields/association.rb +11 -4
  29. data/app/concepts/kono_utils/object/cell/forms/fields/base.rb +21 -16
  30. data/app/concepts/kono_utils/object/cell/forms/fields/bases/layout.rb +24 -17
  31. data/app/concepts/kono_utils/object/cell/forms/fields/bases/modal_layout.rb +14 -4
  32. data/app/concepts/kono_utils/object/cell/forms/fields/bases/table_layout.rb +17 -7
  33. data/app/concepts/kono_utils/object/cell/forms/fields/check_box.rb +14 -6
  34. data/app/concepts/kono_utils/object/cell/forms/fields/collection.rb +20 -12
  35. data/app/concepts/kono_utils/object/cell/forms/fields/date_field.rb +18 -10
  36. data/app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb +34 -30
  37. data/app/concepts/kono_utils/object/cell/forms/fields/enum.rb +23 -15
  38. data/app/concepts/kono_utils/object/cell/forms/fields/file_field.rb +29 -21
  39. data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrapper.rb +10 -3
  40. data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrappers/forms_container.rb +13 -5
  41. data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrappers/show.rb +19 -10
  42. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb +54 -49
  43. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/form.rb +41 -35
  44. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/layout.rb +17 -8
  45. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/modal_layout.rb +14 -4
  46. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/table_layout.rb +14 -4
  47. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_container.rb +44 -36
  48. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/layout.rb +17 -10
  49. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/modal_layout.rb +17 -6
  50. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/table_layout.rb +20 -11
  51. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/header.rb +31 -23
  52. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_button.rb +46 -40
  53. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/layout.rb +14 -7
  54. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/modal_layout.rb +14 -4
  55. data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/table_layout.rb +14 -4
  56. data/app/concepts/kono_utils/object/cell/forms/fields/read_only.rb +16 -9
  57. data/app/concepts/kono_utils/object/cell/forms/fields/time_field.rb +14 -7
  58. data/app/concepts/kono_utils/object/cell/forms/layout.rb +8 -4
  59. data/app/concepts/kono_utils/object/cell/forms/submit.rb +21 -16
  60. data/app/concepts/kono_utils/object/cell/index/base.rb +9 -7
  61. data/app/concepts/kono_utils/object/cell/index/page_title.rb +11 -6
  62. data/app/concepts/kono_utils/object/cell/index/row.rb +38 -36
  63. data/app/concepts/kono_utils/object/cell/index/row_buttons.rb +8 -4
  64. data/app/concepts/kono_utils/object/cell/index/row_footer.rb +8 -3
  65. data/app/concepts/kono_utils/object/cell/index/row_header.rb +13 -7
  66. data/app/concepts/kono_utils/object/cell/index/side_title.rb +8 -2
  67. data/app/concepts/kono_utils/object/cell/index/table.rb +12 -9
  68. data/app/concepts/kono_utils/object/cell/inject.rb +103 -102
  69. data/app/concepts/kono_utils/object/cell/modals/base.rb +7 -3
  70. data/app/concepts/kono_utils/object/cell/modals/bodies/layout.rb +9 -4
  71. data/app/concepts/kono_utils/object/cell/modals/body.rb +7 -3
  72. data/app/concepts/kono_utils/object/cell/modals/container.rb +5 -1
  73. data/app/concepts/kono_utils/object/cell/modals/containers/layout.rb +12 -6
  74. data/app/concepts/kono_utils/object/cell/modals/footer.rb +5 -2
  75. data/app/concepts/kono_utils/object/cell/modals/footers/layout.rb +9 -4
  76. data/app/concepts/kono_utils/object/cell/modals/header.rb +6 -3
  77. data/app/concepts/kono_utils/object/cell/modals/headers/layout.rb +9 -4
  78. data/app/concepts/kono_utils/object/cell/search.rb +22 -19
  79. data/app/concepts/kono_utils/object/cell/searches/form.rb +12 -9
  80. data/app/concepts/kono_utils/object/cell/show.rb +25 -20
  81. data/app/concepts/kono_utils/object/cell/shows/base.rb +6 -5
  82. data/app/concepts/kono_utils/object/cell/shows/page_title.rb +11 -6
  83. data/app/concepts/kono_utils/object/cell/shows/side_title.rb +8 -2
  84. data/lib/kono_utils_bootstrap_view4/version.rb +1 -1
  85. metadata +1 -1
@@ -1,7 +1,17 @@
1
- module KonoUtils::Object::Cell::Forms::Fields::Bases # namespace
2
- # Classe contenitore del campo, serve per deviare nelle situazioni in cui non serve stampare un contenitore(id,_destroy) o campi hidden
3
- # il model qua avremo un KonoUtilsBootstrapView4::EditableField
4
- class ModalLayout < Layout
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ module Bases # namespace
7
+ # Classe contenitore del campo, serve per deviare nelle situazioni in cui non serve stampare un contenitore(id,_destroy) o campi hidden
8
+ # il model qua avremo un KonoUtilsBootstrapView4::EditableField
9
+ class ModalLayout < Layout
5
10
 
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
6
16
  end
7
17
  end
@@ -1,11 +1,21 @@
1
- module KonoUtils::Object::Cell::Forms::Fields::Bases # namespace
2
- # Classe contenitore del campo, serve per deviare nelle situazioni in cui non serve stampare un contenitore(id,_destroy) o campi hidden
3
- # il model qua avremo un KonoUtilsBootstrapView4::EditableField
4
- class TableLayout < Layout
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ module Bases # namespace
7
+ # Classe contenitore del campo, serve per deviare nelle situazioni in cui non serve stampare un contenitore(id,_destroy) o campi hidden
8
+ # il model qua avremo un KonoUtilsBootstrapView4::EditableField
9
+ class TableLayout < Layout
5
10
 
6
- def cell_column_classes
7
- []
8
- end
11
+ def cell_column_classes
12
+ []
13
+ end
9
14
 
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
10
20
  end
11
21
  end
@@ -1,10 +1,18 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- # Campo checkbox
3
- class CheckBox < Base
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ # Campo checkbox
7
+ class CheckBox < Base
4
8
 
5
- def base_field_options
6
- super.merge(as: :boolean)
7
- end
9
+ def base_field_options
10
+ super.merge(as: :boolean)
11
+ end
8
12
 
13
+ end
14
+ end
15
+ end
16
+ end
9
17
  end
10
18
  end
@@ -1,17 +1,25 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- #
3
- # Classe per la gestione del campo collection
4
- class Collection < Base
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ #
7
+ # Classe per la gestione del campo collection
8
+ class Collection < Base
5
9
 
6
- # @return [Hash]
7
- def base_field_options
8
- super.merge(as: :select, collection: collection)
9
- end
10
+ # @return [Hash]
11
+ def base_field_options
12
+ super.merge(as: :select, collection: collection)
13
+ end
10
14
 
11
- # @return [Array,Hash]
12
- def collection
13
- options.fetch(:collection, [])
14
- end
15
+ # @return [Array,Hash]
16
+ def collection
17
+ options.fetch(:collection, [])
18
+ end
15
19
 
20
+ end
21
+ end
22
+ end
23
+ end
16
24
  end
17
25
  end
@@ -1,15 +1,23 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- # La cella base dei componenti della form contiene sempre la form come model
3
- class DateField < DateTimeField
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ # La cella base dei componenti della form contiene sempre la form come model
7
+ class DateField < DateTimeField
4
8
 
5
- def input_picker_format
6
- "L"
7
- end
9
+ def input_picker_format
10
+ "L"
11
+ end
8
12
 
9
- def input_value
10
- value = form.object.send(attribute_name)
11
- value.is_a?(Date) ? "date: moment('#{value&.rfc2822}')," : ''
12
- end
13
+ def input_value
14
+ value = form.object.send(attribute_name)
15
+ value.is_a?(Date) ? "date: moment('#{value&.rfc2822}')," : ''
16
+ end
13
17
 
18
+ end
19
+ end
20
+ end
21
+ end
14
22
  end
15
23
  end
@@ -1,16 +1,18 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- # La cella base dei componenti della form contiene sempre la form come model
3
- class DateTimeField < Base
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ # La cella base dei componenti della form contiene sempre la form come model
7
+ class DateTimeField < Base
4
8
 
9
+ def show(&block)
5
10
 
6
- def show(&block)
11
+ bf = bf = ActiveSupport::SafeBuffer.new
12
+ bf << form.input(attribute_name, field_options)
7
13
 
8
- bf = bf = ActiveSupport::SafeBuffer.new
9
- bf << form.input(attribute_name, field_options)
10
-
11
-
12
- bf << content_tag(:script, :type => "text/javascript") do
13
- raw "(function(){
14
+ bf << content_tag(:script, :type => "text/javascript") do
15
+ raw "(function(){
14
16
  $('##{datetime_picker_identifier}').datetimepicker({
15
17
  #{ input_value }
16
18
  locale: '#{I18n.locale}',
@@ -20,32 +22,34 @@ module KonoUtils::Object::Cell::Forms::Fields # namespace
20
22
  });
21
23
  })();
22
24
  "
23
- end
25
+ end
24
26
 
25
- bf
26
- end
27
+ bf
28
+ end
27
29
 
28
- ##
29
- # Carica il valore nel js per poterlo avere precaricato nel campo
30
- #
31
- def input_value
32
- value = form.object.send(attribute_name)
33
- value.is_a?(DateTime) ? "date: moment('#{value&.rfc2822}')," : ''
34
- end
30
+ ##
31
+ # Carica il valore nel js per poterlo avere precaricato nel campo
32
+ #
33
+ def input_value
34
+ value = form.object.send(attribute_name)
35
+ value.is_a?(DateTime) ? "date: moment('#{value&.rfc2822}')," : ''
36
+ end
35
37
 
36
- def input_picker_format
37
- "L LT"
38
- end
38
+ def input_picker_format
39
+ "L LT"
40
+ end
39
41
 
40
- def base_field_options
41
- super.merge(as: :tempus_dominus, date_time_picker_identifier: datetime_picker_identifier)
42
- end
42
+ def base_field_options
43
+ super.merge(as: :tempus_dominus, date_time_picker_identifier: datetime_picker_identifier)
44
+ end
43
45
 
46
+ def datetime_picker_identifier
47
+ @_unique ||= SecureRandom.uuid
48
+ end
44
49
 
45
- def datetime_picker_identifier
46
- @_unique ||= SecureRandom.uuid
50
+ end
51
+ end
52
+ end
47
53
  end
48
-
49
-
50
54
  end
51
55
  end
@@ -1,20 +1,28 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- #
3
- # Classe per la gestione del campo Enum, semplicemente estendendo la collection, ed estrapolando automaticamente
4
- # i valori della select e relative traduzioni
5
- class Enum < Collection
6
- include KonoUtils::ApplicationEnumHelper
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ #
7
+ # Classe per la gestione del campo Enum, semplicemente estendendo la collection, ed estrapolando automaticamente
8
+ # i valori della select e relative traduzioni
9
+ class Enum < Collection
10
+ include KonoUtils::ApplicationEnumHelper
7
11
 
8
- ##
9
- # Ritorna la rappresentazione da utilizzare per stampare la select dell'enum
10
- # @return [Hash]
11
- def collection
12
- enum_collection(form.object.class, model.name)
13
- end
12
+ ##
13
+ # Ritorna la rappresentazione da utilizzare per stampare la select dell'enum
14
+ # @return [Hash]
15
+ def collection
16
+ enum_collection(form.object.class, model.name)
17
+ end
14
18
 
15
- def show(&block)
16
- render "forms/fields/collection"
17
- end
19
+ def show(&block)
20
+ render "forms/fields/collection"
21
+ end
18
22
 
23
+ end
24
+ end
25
+ end
26
+ end
19
27
  end
20
28
  end
@@ -1,31 +1,39 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- class FileField < Base
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ class FileField < Base
3
7
 
4
- def show(&block)
5
- form.input(attribute_name, field_options)
6
- end
8
+ def show(&block)
9
+ form.input(attribute_name, field_options)
10
+ end
11
+
12
+ def base_field_options
13
+ download_button = nil
14
+ remove_checkbox = remove_checkbox
15
+ if form.object.send(attribute_name).attached?
16
+ download_button = concept("cell/buttons/download", form.object.send(attribute_name), button_options: { class: 'btn-outline-secondary' })
17
+ if form.object.class.respond_to?(:attribute_purger_name)
18
+ attribute_purger_name = form.object.class.attribute_purger_name(attribute_name)
19
+ if form.object.respond_to?(attribute_purger_name)
7
20
 
8
- def base_field_options
9
- download_button = nil
10
- remove_checkbox = remove_checkbox
11
- if form.object.send(attribute_name).attached?
12
- download_button = concept("cell/buttons/download", form.object.send(attribute_name), button_options: { class: 'btn-outline-secondary' })
13
- if form.object.class.respond_to?(:attribute_purger_name)
14
- attribute_purger_name = form.object.class.attribute_purger_name(attribute_name)
15
- if form.object.respond_to?(attribute_purger_name)
21
+ label = form.object.class.han(attribute_purger_name,
22
+ default: I18n.t('kono_utils.bootstrap4.forms.fields.file_field.purge_file.label'))
16
23
 
17
- label = form.object.class.han(attribute_purger_name,
18
- default: I18n.t('kono_utils.bootstrap4.forms.fields.file_field.purge_file.label'))
24
+ remove_checkbox = concept("cell/forms/fields/check_box",
25
+ KonoUtilsBootstrapView4::EditableField.new(attribute_purger_name),
26
+ field_options: { label: label }
27
+ )
28
+ end
29
+ end
30
+ end
31
+ super.merge({ as: :file_input_download, download_button: download_button, remove_checkbox: remove_checkbox })
32
+ end
19
33
 
20
- remove_checkbox = concept("cell/forms/fields/check_box",
21
- KonoUtilsBootstrapView4::EditableField.new(attribute_purger_name),
22
- field_options: { label: label }
23
- )
24
34
  end
25
35
  end
26
36
  end
27
- super.merge({ as: :file_input_download, download_button: download_button, remove_checkbox: remove_checkbox })
28
37
  end
29
-
30
38
  end
31
39
  end
@@ -1,6 +1,13 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- class NestedModalWrapper < NestedWrapper
3
-
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ class NestedModalWrapper < NestedWrapper
4
7
 
8
+ end
9
+ end
10
+ end
11
+ end
5
12
  end
6
13
  end
@@ -1,9 +1,17 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- class NestedModalWrappers::FormsContainer < NestedWrappers::FormsContainer
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ class NestedModalWrappers::FormsContainer < NestedWrappers::FormsContainer
3
7
 
4
- def render_cell_container
5
- "cell/forms/fields/nested_modal_wrappers/show"
6
- end
8
+ def render_cell_container
9
+ "cell/forms/fields/nested_modal_wrappers/show"
10
+ end
7
11
 
12
+ end
13
+ end
14
+ end
15
+ end
8
16
  end
9
17
  end
@@ -1,14 +1,23 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- ##
3
- # Rappresenta la classe che renderizza il contenitore della versione di visualizzazione del dato
4
- ##
5
- class NestedModalWrappers::Show < NestedWrappers::Form
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
6
 
7
- # nella show dobbiamo renderizzare nascosti solo i campi dell'ID del destroy
8
- # FIXME serve questo codice?
9
- # def form_attributes
10
- # super.select { |v| v.name == :id or v.name == :_destroy }
11
- # end
7
+ ##
8
+ # Rappresenta la classe che renderizza il contenitore della versione di visualizzazione del dato
9
+ ##
10
+ class NestedModalWrappers::Show < NestedWrappers::Form
12
11
 
12
+ # nella show dobbiamo renderizzare nascosti solo i campi dell'ID del destroy
13
+ # FIXME serve questo codice?
14
+ # def form_attributes
15
+ # super.select { |v| v.name == :id or v.name == :_destroy }
16
+ # end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
13
22
  end
14
23
  end
@@ -1,63 +1,68 @@
1
- module KonoUtils::Object::Cell::Forms::Fields # namespace
2
- # La cella base dei componenti della form contiene sempre la form come model
3
- # la base class di un nested diventa il modello della relazione
4
- #
5
- # ** Options:
6
- # - as_display_list -> Boolean che mi definisce se renderizzare come solo display la lista dei componenti
7
- class NestedWrapper < Base
1
+ module KonoUtils
2
+ module Object
3
+ module Cell
4
+ module Forms # namespace
5
+ module Fields
6
+ # La cella base dei componenti della form contiene sempre la form come model
7
+ # la base class di un nested diventa il modello della relazione
8
+ #
9
+ # ** Options:
10
+ # - as_display_list -> Boolean che mi definisce se renderizzare come solo display la lista dei componenti
11
+ class NestedWrapper < Base
8
12
 
13
+ alias_method :parent_base_class, :base_class
9
14
 
10
- alias_method :parent_base_class, :base_class
15
+ def base_class
16
+ reflection_association.klass
17
+ end
11
18
 
12
- def base_class
13
- reflection_association.klass
14
- end
19
+ def show(&block)
20
+ initialize_first_nested
21
+ super
22
+ end
15
23
 
24
+ def forms_container_layout
25
+ layout = context[:nested_layout].blank? ? "layout" : context[:nested_layout]
26
+ layout_ns("cell/forms/fields/nested_wrappers/forms_containers/#{layout}")
27
+ end
16
28
 
17
- def show(&block)
18
- initialize_first_nested
19
- super
20
- end
29
+ ##
30
+ # Semplicemente se è un has_many ha multipli elementi, altrimenti no
31
+ def has_multiple_elements?
32
+ reflection_association.macro == :has_many
33
+ end
21
34
 
22
- def forms_container_layout
23
- layout = context[:nested_layout].blank? ? "layout" : context[:nested_layout]
24
- layout_ns("cell/forms/fields/nested_wrappers/forms_containers/#{layout}")
25
- end
26
-
27
- ##
28
- # Semplicemente se è un has_many ha multipli elementi, altrimenti no
29
- def has_multiple_elements?
30
- reflection_association.macro == :has_many
31
- end
35
+ ##
36
+ # Inizializza un nuovo record se necessario.
37
+ # Si basa sulla reflection dell'associazione.
38
+ # reflections supportate:
39
+ # - has_one
40
+ # - has_many
41
+ def initialize_first_nested
42
+ case reflection_association.macro
43
+ when :has_one, :belongs_to
44
+ form.object.send("build_#{attribute_name}") if form.object.send(attribute_name).nil?
45
+ when :has_many
32
46
 
33
- ##
34
- # Inizializza un nuovo record se necessario.
35
- # Si basa sulla reflection dell'associazione.
36
- # reflections supportate:
37
- # - has_one
38
- # - has_many
39
- def initialize_first_nested
40
- case reflection_association.macro
41
- when :has_one, :belongs_to
42
- form.object.send("build_#{attribute_name}") if form.object.send(attribute_name).nil?
43
- when :has_many
44
-
45
- # form.object.send(attribute_name).build if form.object.send(attribute_name).empty?
46
- else
47
- raise "not defined - #{reflection_association.macro}"
48
- end
49
- end
47
+ # form.object.send(attribute_name).build if form.object.send(attribute_name).empty?
48
+ else
49
+ raise "not defined - #{reflection_association.macro}"
50
+ end
51
+ end
50
52
 
53
+ def target_container_for_new_nested
54
+ @_unique ||= SecureRandom.uuid
55
+ end
51
56
 
52
- def target_container_for_new_nested
53
- @_unique ||= SecureRandom.uuid
54
- end
57
+ protected
55
58
 
56
- protected
59
+ def reflection_association
60
+ form.object.class.reflect_on_association(attribute_name)
61
+ end
57
62
 
58
- def reflection_association
59
- form.object.class.reflect_on_association(attribute_name)
63
+ end
64
+ end
65
+ end
60
66
  end
61
-
62
67
  end
63
68
  end