Class: KonoUtils::Object::Cell::Inject

Inherits:
Base
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::FormOptionsHelper, SimpleForm::ActionViewExtensions::FormHelper
Defined in:
app/concepts/kono_utils/object/cell/inject.rb

Overview

Classe per la gestione dell’inserimento del contenuto e javascript per l’azione inject

  • Options: html_manipulation_method: [(:append),:prepend,:replaceWith] -> definisce come deve operare il javascript

    nell'operazione di manipolazione del contenitore
    in cui inserire il contenuto
    

    inject_show_modal: [Boolean] -> identifica se stiamo visualizzando la show della modal o meno, default a false

Instance Method Summary collapse

Methods inherited from Base

#_prefixes, #base_class, #concept, #content_for_layout, #content_for_layout?, #destroy_custom_polymorphic_path, #edit_custom_polymorphic_path, #index_custom_polymorphic_path, #kono_user, #legacy_concept, logger, #model_gender, #new_custom_polymorphic_path, #show, #show_custom_polymorphic_path, #title_del, #title_del_g, #title_edit_g, #title_mod, #title_new, #title_new_g, #title_newa, #title_show_g

Methods included from KonoUtilsBootstrapView4::ApplicationIconHelper

#fa_icon, #icon

Instance Method Details

#form_contentObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 35

def form_content
  #nel caso stiamo visualizzando il rimpiazzo dell'output delle modals(quando per esempio abbiamo aggiornato od inserito un nuovo record)
  if options.fetch(:inject_show_modal, false)

    container = nil
    simple_form_for(model, as: "#{params.dig(:kono_utils, :structure_nested)}[#{Time.now.to_i}]", url: '#') do |form|

      container = concept("cell/forms/fields/nested_modal_wrappers/show", model,
                          show_remove_button: true,
                          layout: layout_ns("cell/forms/fields/nested_wrappers/forms/layout"),
                          context: {
                            form: form,
                            base_class: base_class,
                            nested_layout: nested_layout,
                            kono_user: context[:kono_user]
                          }.merge(remote_context)
      )

    end

    container

  else
    if inject_as_modal?

      concept("cell/modals/container",
              concept("cell/form", model,
                      form_options: { remote: true },
                      context: {
                        nested_layout: nested_layout,
                        modal_upgraded_target_container: params.dig(:kono_utils, :modal_upgraded_target_container)
                      }.merge(context)),
              layout: model.class.layout_ns("cell/modals/containers/layout")
      )

    else
      container = nil
      simple_form_for(model, as: "#{params.dig(:kono_utils, :structure_nested)}[#{Time.now.to_i}]", url: '#') do |form|

        container = concept("cell/forms/fields/nested_wrappers/form", model,
                            show_remove_button: !inject_as_modal?, #per le modal non visualizziamo direttamente il bottone
                            layout: form_layout,
                            context: {
                              form: form,
                              base_class: base_class,
                              kono_user: context[:kono_user]
                            }.merge(remote_context)
        )

      end

      container

    end
  end
end

#form_layoutObject



25
26
27
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 25

def form_layout
  layout_ns("cell/forms/fields/nested_wrappers/forms/#{nested_layout}")
end

#html_manipulation_methodObject



100
101
102
103
104
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 100

def html_manipulation_method
  methodo = options.fetch(:html_manipulation_method, :append).to_sym
  raise "METODI DI MANIPOLAZIONE ACCETTATI: :append, :prepend, :replaceWith" unless [:append, :prepend, :replaceWith].include?(methodo)
  methodo
end

#inject_as_modalObject



106
107
108
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 106

def inject_as_modal
  params.dig(:kono_utils, :inject_as_modal)
end

#paramsObject



19
20
21
22
23
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 19

def params
  @_p ||= options[:params]
  @_p.permit!
  @_p
end

#remote_contextObject

TODO documentare cosa serve, qual’era il concetto di questo pezzo di codice



31
32
33
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 31

def remote_context
  params.dig(:kono_utils, :context).to_h.deep_symbolize_keys || {}
end

#target_containerObject



92
93
94
95
96
97
98
# File 'app/concepts/kono_utils/object/cell/inject.rb', line 92

def target_container
  if options.fetch(:inject_show_modal, false)
    "##{params.dig(:kono_utils, :modal_upgraded_target_container)}"
  else
    params.dig(:kono_utils, :target_container)
  end
end