Class: KonoUtils::Object::Cell::Forms::Fields::NestedWrapper

Inherits:
Base
  • Object
show all
Defined in:
app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb

Overview

La cella base dei componenti della form contiene sempre la form come model la base class di un nested diventa il modello della relazione

** Options:

  • as_display_list -> Boolean che mi definisce se renderizzare come solo display la lista dei componenti

Direct Known Subclasses

NestedModalWrapper

Instance Method Summary collapse

Methods inherited from Base

#_prefixes, #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_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

#base_classObject



15
16
17
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 15

def base_class
  reflection_association.klass
end

#forms_container_layoutObject



24
25
26
27
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 24

def forms_container_layout
  layout = context[:nested_layout].blank? ? "layout" : context[:nested_layout]
  layout_ns("cell/forms/fields/nested_wrappers/forms_containers/#{layout}")
end

#has_multiple_elements?Boolean

Semplicemente se è un has_many ha multipli elementi, altrimenti no

Returns:

  • (Boolean)


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

def has_multiple_elements?
  reflection_association.macro == :has_many
end

#initialize_first_nestedObject

Inizializza un nuovo record se necessario. Si basa sulla reflection dell’associazione. reflections supportate:

  • has_one

  • has_many



41
42
43
44
45
46
47
48
49
50
51
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 41

def initialize_first_nested
  case reflection_association.macro
  when :has_one, :belongs_to
    form.object.send("build_#{attribute_name}") if form.object.send(attribute_name).nil?
  when :has_many

    #   form.object.send(attribute_name).build if form.object.send(attribute_name).empty?
  else
    raise "not defined - #{reflection_association.macro}"
  end
end

#parent_base_classObject



13
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 13

alias_method :parent_base_class, :base_class

#show(&block) ⇒ Object



19
20
21
22
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 19

def show(&block)
  initialize_first_nested
  super
end

#target_container_for_new_nestedObject



53
54
55
# File 'app/concepts/kono_utils/object/cell/forms/fields/nested_wrapper.rb', line 53

def target_container_for_new_nested
  @_unique ||= SecureRandom.uuid
end