kono_utils_bootstrap_view4 0.1.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +21 -0
- data/Rakefile +32 -0
- data/app/assets/config/kono_utils_bootstrap_view4_manifest.js +0 -0
- data/app/assets/javascripts/kono_utils_bootstrap_view4/application.js.erb +12 -0
- data/app/assets/javascripts/kono_utils_bootstrap_view4/kono_utils_bootstrap_view4.js +36 -0
- data/app/assets/stylesheets/kono_utils_bootstrap_view4/application.css.scss.erb +12 -0
- data/app/concepts/kono_utils/object/cell/base.rb +123 -0
- data/app/concepts/kono_utils/object/cell/buttons/base.rb +57 -0
- data/app/concepts/kono_utils/object/cell/buttons/collapse_search.rb +31 -0
- data/app/concepts/kono_utils/object/cell/buttons/create.rb +22 -0
- data/app/concepts/kono_utils/object/cell/buttons/delete.rb +32 -0
- data/app/concepts/kono_utils/object/cell/buttons/download.rb +23 -0
- data/app/concepts/kono_utils/object/cell/buttons/edit.rb +18 -0
- data/app/concepts/kono_utils/object/cell/buttons/list.rb +17 -0
- data/app/concepts/kono_utils/object/cell/buttons/reset_search.rb +21 -0
- data/app/concepts/kono_utils/object/cell/create/base.rb +8 -0
- data/app/concepts/kono_utils/object/cell/create/page_title.rb +10 -0
- data/app/concepts/kono_utils/object/cell/create/side_title.rb +5 -0
- data/app/concepts/kono_utils/object/cell/edits/base.rb +8 -0
- data/app/concepts/kono_utils/object/cell/edits/page_title.rb +10 -0
- data/app/concepts/kono_utils/object/cell/edits/side_title.rb +5 -0
- data/app/concepts/kono_utils/object/cell/form.rb +51 -0
- data/app/concepts/kono_utils/object/cell/forms/base.rb +13 -0
- data/app/concepts/kono_utils/object/cell/forms/container.rb +25 -0
- data/app/concepts/kono_utils/object/cell/forms/containers/layout.rb +16 -0
- data/app/concepts/kono_utils/object/cell/forms/containers/modal_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/containers/search_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/containers/table_layout.rb +8 -0
- data/app/concepts/kono_utils/object/cell/forms/field_selector.rb +77 -0
- data/app/concepts/kono_utils/object/cell/forms/field_selectors/layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/field_selectors/modal_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/field_selectors/table_layout.rb +8 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/association.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/base.rb +25 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/bases/layout.rb +24 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/bases/modal_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/bases/table_layout.rb +11 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/check_box.rb +10 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/collection.rb +17 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/date_field.rb +15 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/date_time_field.rb +51 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/enum.rb +20 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/file_field.rb +31 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrapper.rb +6 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrappers/forms_container.rb +9 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_modal_wrappers/show.rb +14 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb +63 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/form.rb +38 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/layout.rb +13 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/modal_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms/table_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_container.rb +45 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/layout.rb +15 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/modal_layout.rb +9 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/table_layout.rb +16 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/header.rb +31 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_button.rb +44 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/layout.rb +10 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/modal_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/remove_buttons/table_layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/read_only.rb +15 -0
- data/app/concepts/kono_utils/object/cell/forms/fields/time_field.rb +11 -0
- data/app/concepts/kono_utils/object/cell/forms/layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/forms/submit.rb +22 -0
- data/app/concepts/kono_utils/object/cell/index/base.rb +12 -0
- data/app/concepts/kono_utils/object/cell/index/page_title.rb +10 -0
- data/app/concepts/kono_utils/object/cell/index/row.rb +40 -0
- data/app/concepts/kono_utils/object/cell/index/row_buttons.rb +7 -0
- data/app/concepts/kono_utils/object/cell/index/row_footer.rb +6 -0
- data/app/concepts/kono_utils/object/cell/index/row_header.rb +11 -0
- data/app/concepts/kono_utils/object/cell/index/side_title.rb +5 -0
- data/app/concepts/kono_utils/object/cell/index/table.rb +15 -0
- data/app/concepts/kono_utils/object/cell/inject.rb +122 -0
- data/app/concepts/kono_utils/object/cell/modals/base.rb +6 -0
- data/app/concepts/kono_utils/object/cell/modals/bodies/layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/modals/body.rb +6 -0
- data/app/concepts/kono_utils/object/cell/modals/container.rb +24 -0
- data/app/concepts/kono_utils/object/cell/modals/containers/layout.rb +10 -0
- data/app/concepts/kono_utils/object/cell/modals/footer.rb +6 -0
- data/app/concepts/kono_utils/object/cell/modals/footers/layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/modals/header.rb +6 -0
- data/app/concepts/kono_utils/object/cell/modals/headers/layout.rb +7 -0
- data/app/concepts/kono_utils/object/cell/search.rb +27 -0
- data/app/concepts/kono_utils/object/cell/searches/form.rb +14 -0
- data/app/concepts/kono_utils/object/cell/show.rb +26 -0
- data/app/concepts/kono_utils/object/cell/shows/base.rb +8 -0
- data/app/concepts/kono_utils/object/cell/shows/page_title.rb +10 -0
- data/app/concepts/kono_utils/object/cell/shows/side_title.rb +5 -0
- data/app/concepts/kono_utils/object/view/create/side_title.erb +1 -0
- data/app/concepts/kono_utils/object/view/edits/side_title.erb +1 -0
- data/app/concepts/kono_utils/object/view/form.erb +9 -0
- data/app/concepts/kono_utils/object/view/forms/container.erb +5 -0
- data/app/concepts/kono_utils/object/view/forms/containers/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/containers/modal_layout.erb +5 -0
- data/app/concepts/kono_utils/object/view/forms/containers/search_layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/containers/table_layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/field_selector.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/field_selectors/layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/field_selectors/modal_layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/field_selectors/table_layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/association.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/base.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/bases/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/fields/bases/layout.scss +25 -0
- data/app/concepts/kono_utils/object/view/forms/fields/bases/modal_layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/fields/bases/table_layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/fields/check_box.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/collection.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_modal_wrapper.erb +23 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_modal_wrappers/forms_container.erb +12 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_modal_wrappers/show.erb +28 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrapper.erb +18 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/form.erb +17 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms/layout.erb +18 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms/modal_layout.erb +4 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms/table_layout.erb +4 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms_container.erb +11 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms_containers/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms_containers/modal_layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/forms_containers/table_layout.erb +14 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/header.erb +27 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/remove_button.erb +28 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/remove_buttons/layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/remove_buttons/modal_layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/forms/fields/nested_wrappers/remove_buttons/table_layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/forms/layout.erb +1 -0
- data/app/concepts/kono_utils/object/view/index/row.erb +10 -0
- data/app/concepts/kono_utils/object/view/index/row_buttons.erb +2 -0
- data/app/concepts/kono_utils/object/view/index/row_footer.erb +0 -0
- data/app/concepts/kono_utils/object/view/index/row_header.erb +8 -0
- data/app/concepts/kono_utils/object/view/index/side_title.erb +1 -0
- data/app/concepts/kono_utils/object/view/index/table.erb +9 -0
- data/app/concepts/kono_utils/object/view/inject.erb +8 -0
- data/app/concepts/kono_utils/object/view/modals/bodies/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/modals/body.erb +1 -0
- data/app/concepts/kono_utils/object/view/modals/container.erb +13 -0
- data/app/concepts/kono_utils/object/view/modals/containers/layout.erb +7 -0
- data/app/concepts/kono_utils/object/view/modals/footer.erb +1 -0
- data/app/concepts/kono_utils/object/view/modals/footers/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/modals/header.erb +1 -0
- data/app/concepts/kono_utils/object/view/modals/headers/layout.erb +3 -0
- data/app/concepts/kono_utils/object/view/search.erb +40 -0
- data/app/concepts/kono_utils/object/view/searches/form.erb +16 -0
- data/app/concepts/kono_utils/object/view/show.erb +6 -0
- data/app/concepts/kono_utils/object/view/shows/side_title.erb +1 -0
- data/app/inputs/file_input_download_input.rb +22 -0
- data/app/inputs/tempus_dominus_input.rb +38 -0
- data/app/views/kaminari/_first_page.html.erb +3 -0
- data/app/views/kaminari/_gap.html.erb +3 -0
- data/app/views/kaminari/_last_page.html.erb +3 -0
- data/app/views/kaminari/_next_page.html.erb +3 -0
- data/app/views/kaminari/_page.html.erb +9 -0
- data/app/views/kaminari/_paginator.html.erb +17 -0
- data/app/views/kaminari/_prev_page.html.erb +3 -0
- data/app/views/kono_utils/base_editing/edit.html.erb +8 -0
- data/app/views/kono_utils/base_editing/edit.inject.erb +2 -0
- data/app/views/kono_utils/base_editing/index.html.erb +10 -0
- data/app/views/kono_utils/base_editing/new.html.erb +9 -0
- data/app/views/kono_utils/base_editing/new.inject.erb +2 -0
- data/app/views/kono_utils/base_editing/show.html.erb +8 -0
- data/app/views/kono_utils/base_editing/success_create_show.inject.erb +6 -0
- data/app/views/kono_utils/base_editing/success_update_show.inject.erb +6 -0
- data/config/initializers/kaminari_config.rb +30 -0
- data/config/initializers/simple_form.rb +179 -0
- data/config/initializers/simple_form_bootstrap.rb +439 -0
- data/config/locales/kono_utils_bootstrap4.en.yml +15 -0
- data/config/locales/kono_utils_bootstrap4.it.yml +15 -0
- data/config/locales/simple_form.en.yml +31 -0
- data/config/routes.rb +2 -0
- data/lib/generators/kono_utils_bootstrap_view4/concept/concept_generator.rb +79 -0
- data/lib/generators/kono_utils_bootstrap_view4/concept/templates/form.template +8 -0
- data/lib/generators/kono_utils_bootstrap_view4/concept/templates/forms/field_selector.template +13 -0
- data/lib/generators/kono_utils_bootstrap_view4/install/install_generator.rb +76 -0
- data/lib/generators/kono_utils_bootstrap_view4/install/templates/kono_utils_bootstrap_view4.js.erb.template +20 -0
- data/lib/generators/kono_utils_bootstrap_view4/install/templates/kono_utils_bootstrap_view4.template +5 -0
- data/lib/kono_utils_bootstrap_view4.rb +26 -0
- data/lib/kono_utils_bootstrap_view4/application_icon_helper.rb +31 -0
- data/lib/kono_utils_bootstrap_view4/base_class_concept_ns.rb +47 -0
- data/lib/kono_utils_bootstrap_view4/base_search.rb +5 -0
- data/lib/kono_utils_bootstrap_view4/configuration.rb +20 -0
- data/lib/kono_utils_bootstrap_view4/editable_field.rb +63 -0
- data/lib/kono_utils_bootstrap_view4/engine.rb +59 -0
- data/lib/kono_utils_bootstrap_view4/paginate_proxer.rb +11 -0
- data/lib/kono_utils_bootstrap_view4/search_form_builder.rb +14 -0
- data/lib/kono_utils_bootstrap_view4/version.rb +3 -0
- data/lib/tasks/kono_utils_bootstrap_view4_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +15 -0
- metadata +391 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
#
|
3
|
+
# Classe per la gestione del campo collection
|
4
|
+
class Collection < Base
|
5
|
+
|
6
|
+
# @return [Hash]
|
7
|
+
def base_field_options
|
8
|
+
super.merge(as: :select, collection: collection)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Array,Hash]
|
12
|
+
def collection
|
13
|
+
options.fetch(:collection, [])
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
4
|
+
|
5
|
+
def input_picker_format
|
6
|
+
"L"
|
7
|
+
end
|
8
|
+
|
9
|
+
def input_value
|
10
|
+
value = form.object.send(attribute_name)
|
11
|
+
value.is_a?(Date) ? "date: moment('#{value&.rfc2822}')," : ''
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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
|
4
|
+
|
5
|
+
|
6
|
+
def show(&block)
|
7
|
+
|
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
|
+
$('##{datetime_picker_identifier}').datetimepicker({
|
15
|
+
#{ input_value }
|
16
|
+
locale: '#{I18n.locale}',
|
17
|
+
keepOpen: false,
|
18
|
+
debug: false,
|
19
|
+
format: '#{input_picker_format}'
|
20
|
+
});
|
21
|
+
})();
|
22
|
+
"
|
23
|
+
end
|
24
|
+
|
25
|
+
bf
|
26
|
+
end
|
27
|
+
|
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
|
35
|
+
|
36
|
+
def input_picker_format
|
37
|
+
"L LT"
|
38
|
+
end
|
39
|
+
|
40
|
+
def base_field_options
|
41
|
+
super.merge(as: :tempus_dominus, date_time_picker_identifier: datetime_picker_identifier)
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def datetime_picker_identifier
|
46
|
+
@_unique ||= SecureRandom.uuid
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
7
|
+
|
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
|
14
|
+
|
15
|
+
def show(&block)
|
16
|
+
render "forms/fields/collection"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
class FileField < Base
|
3
|
+
|
4
|
+
def show(&block)
|
5
|
+
form.input(attribute_name, field_options)
|
6
|
+
end
|
7
|
+
|
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)
|
16
|
+
|
17
|
+
label = form.object.class.han(attribute_purger_name,
|
18
|
+
default: I18n.t('kono_utils.bootstrap4.forms.fields.file_field.purge_file.label'))
|
19
|
+
|
20
|
+
remove_checkbox = concept("cell/forms/fields/check_box",
|
21
|
+
KonoUtilsBootstrapView4::EditableField.new(attribute_purger_name),
|
22
|
+
field_options: { label: label }
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
super.merge({ as: :file_input_download, download_button: download_button, remove_checkbox: remove_checkbox })
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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
|
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
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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
|
8
|
+
|
9
|
+
|
10
|
+
alias_method :parent_base_class, :base_class
|
11
|
+
|
12
|
+
def base_class
|
13
|
+
reflection_association.klass
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def show(&block)
|
18
|
+
initialize_first_nested
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
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
|
32
|
+
|
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
|
50
|
+
|
51
|
+
|
52
|
+
def target_container_for_new_nested
|
53
|
+
@_unique ||= SecureRandom.uuid
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def reflection_association
|
59
|
+
form.object.class.reflect_on_association(attribute_name)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
##
|
3
|
+
# Rappresenta la classe che renderizza il contenitore della singola nested form
|
4
|
+
##
|
5
|
+
class NestedWrappers::Form < Base
|
6
|
+
|
7
|
+
##
|
8
|
+
# Per i nested abbiamo un elenco di campi da visualizzare,
|
9
|
+
# questo elenco ci viene fornito tramite il modello EditableField dal nested_wrapper,
|
10
|
+
# il quale elabora rispetto ai nested delle policy, oppure direttamente dalla policy del model
|
11
|
+
def form_attributes
|
12
|
+
options[:form_attributes] || KonoUtilsBootstrapView4::EditableField.editable_fields_to_field_array(policy(model).editable_attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
##
|
17
|
+
# Visualizzare o meno il bottone di cancellazione
|
18
|
+
def show_remove_button?
|
19
|
+
options[:show_remove_button] || false
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Id per identificare il container che raggruppa campi e bottone per cancellare
|
24
|
+
def container_id
|
25
|
+
@_unique ||= context[:container_id] = SecureRandom.uuid
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def container_layout
|
30
|
+
context[:nested_layout].blank? ? nil : layout_ns("cell/forms/containers/#{context[:nested_layout]}")
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_button_layout
|
34
|
+
context[:nested_layout].blank? ? nil : layout_ns("cell/forms/fields/nested_wrappers/remove_buttons/#{context[:nested_layout]}")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
class NestedWrappers::Forms::Layout < Base
|
3
|
+
|
4
|
+
def container_id
|
5
|
+
context[:container_id] # generato dalla cella Form, trovare sistema più bello? FIXME
|
6
|
+
end
|
7
|
+
|
8
|
+
def object_header
|
9
|
+
form.object.class.model_name.human
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
##
|
3
|
+
# Rappresenta la classe che renderizza il contenitore della singola nested form
|
4
|
+
#
|
5
|
+
# ** Options:
|
6
|
+
# - as_display_list -> Boolean che mi definisce se renderizzare come solo display la lista dei componenti
|
7
|
+
#
|
8
|
+
##
|
9
|
+
class NestedWrappers::FormsContainer < Base
|
10
|
+
|
11
|
+
delegates :parent_cell, :has_multiple_elements?
|
12
|
+
|
13
|
+
def parent_cell
|
14
|
+
context[:parent_cell]
|
15
|
+
end
|
16
|
+
|
17
|
+
# causa di una stranezza di simple form che non ritiene safe il contenuto passato
|
18
|
+
def inner_form_block
|
19
|
+
form.simple_fields_for(attribute_name,include_id: false) do |inside_form|
|
20
|
+
capture do
|
21
|
+
yield(inside_form)
|
22
|
+
end.html_safe
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Restituisce il nome della cella da renderizzare, è possibile che sia una form o la show
|
28
|
+
def render_cell_container
|
29
|
+
"cell/forms/fields/nested_wrappers/form"
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Per i nested abbiamo un elenco di campi da visualizzare,
|
34
|
+
# questo elenco ci viene fornito tramite il modello EditableField, il quale elabora rispetto ai nested delle policy
|
35
|
+
def inner_fields
|
36
|
+
model.inner_fields
|
37
|
+
end
|
38
|
+
|
39
|
+
def form_layout
|
40
|
+
layout = context[:nested_layout].blank? ? "layout" : context[:nested_layout]
|
41
|
+
layout_ns("cell/forms/fields/nested_wrappers/forms/#{layout}")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
data/app/concepts/kono_utils/object/cell/forms/fields/nested_wrappers/forms_containers/layout.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
##
|
3
|
+
# Rappresenta il layout del container del Wrapper
|
4
|
+
# abbiamo la versione Standard e versione Table
|
5
|
+
##
|
6
|
+
class NestedWrappers::FormsContainers::Layout < Base
|
7
|
+
|
8
|
+
delegates :parent_cell, :target_container_for_new_nested
|
9
|
+
|
10
|
+
|
11
|
+
def parent_cell
|
12
|
+
context[:parent_cell]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields::NestedWrappers::FormsContainers # namespace
|
2
|
+
##
|
3
|
+
# Rappresenta il layout del container del Wrapper
|
4
|
+
# abbiamo la versione Standard e versione Table
|
5
|
+
##
|
6
|
+
class TableLayout < Layout
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
def columns_to_show
|
11
|
+
model.inner_fields.reject(&:is_hidden?)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
##
|
3
|
+
# Rappresenta la classe per la renderizzazione dell'header nel nested in modo da aggiungere o meno
|
4
|
+
# la gestione del bottone di aggiunta
|
5
|
+
class NestedWrappers::Header < Base
|
6
|
+
|
7
|
+
delegates :parent_cell, :reflection_association
|
8
|
+
delegates :parent_cell, :target_container_for_new_nested
|
9
|
+
delegates :parent_cell, :has_multiple_elements?
|
10
|
+
|
11
|
+
def parent_cell
|
12
|
+
context[:parent_cell]
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Controlla se dobbiamo renderizzare un bottone per fare la build di un nuovo record
|
17
|
+
# @return [TrueClass|FalseClass]
|
18
|
+
def build_new_nested?
|
19
|
+
has_multiple_elements? and form.object.persisted?
|
20
|
+
end
|
21
|
+
|
22
|
+
def target_container
|
23
|
+
inject_as_modal ? 'body' : "##{target_container_for_new_nested}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def inject_as_modal
|
27
|
+
options[:inject_as_modal]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module KonoUtils::Object::Cell::Forms::Fields # namespace
|
2
|
+
##
|
3
|
+
# Bottone per la rimozione della riga nested
|
4
|
+
# *Options:*
|
5
|
+
# - ajax_remove: [Boolean] -> indica se vogliamo che venga veramente cancellato il record
|
6
|
+
class NestedWrappers::RemoveButton < KonoUtils::Object::Cell::Buttons::Delete
|
7
|
+
|
8
|
+
|
9
|
+
def url_to
|
10
|
+
if ajax_remove?
|
11
|
+
destroy_custom_polymorphic_path(model, format: :json)
|
12
|
+
else
|
13
|
+
"#"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Controlla se questo record deve essere cancellato o meno via ajax
|
19
|
+
# @return [TrueClass, FalseClass]
|
20
|
+
def ajax_remove?
|
21
|
+
!!options.fetch(:ajax_remove, false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def automatic_remove_options
|
25
|
+
if ajax_remove?
|
26
|
+
super.merge(remote: true)
|
27
|
+
else
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def show(&block)
|
33
|
+
super + render(&block).html_safe
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# ID div in cui definire che l'elemento viene rimosso
|
38
|
+
def remove_target
|
39
|
+
options[:remove_target]
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|