Class: Jav::Tab
- Inherits:
-
Object
- Object
- Jav::Tab
- Includes:
- Concerns::IsResourceItem, Concerns::VisibleItems, Fields::FieldExtensions::VisibleInDifferentViews
- Defined in:
- lib/jav/tab.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#holds_one_field ⇒ Object
Returns the value of attribute holds_one_field.
-
#identity_name ⇒ Object
readonly
Returns the value of attribute identity_name.
-
#items_holder ⇒ Object
Returns the value of attribute items_holder.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Attributes included from Fields::FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #has_a_single_item? ⇒ Boolean
- #hydrate(view: nil) ⇒ Object
-
#initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) ⇒ Tab
constructor
A new instance of Tab.
- #name ⇒ Object
- #turbo_frame_id(parent: nil) ⇒ Object
-
#visible_on?(view) ⇒ Boolean
Checks for visibility on itself or on theone field it holds.
Methods included from Fields::FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on, #show_on_create, #show_on_update
Methods included from Concerns::VisibleItems
#items, #visible, #visible?, #visible_items
Methods included from Concerns::IsResourceItem
#is_field?, #is_main_panel?, #is_panel?, #is_row?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Constructor Details
#initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) ⇒ Tab
Returns a new instance of Tab.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jav/tab.rb', line 12 def initialize(name: nil, description: nil, view: nil, holds_one_field: false, **args) # Initialize the visibility markers super @name = name @description = description @holds_one_field = holds_one_field @items_holder = Jav::ItemsHolder.new @view = view show_on args[:show_on] if args[:show_on].present? hide_on args[:hide_on] if args[:hide_on].present? only_on args[:only_on] if args[:only_on].present? except_on args[:except_on] if args[:except_on].present? @identity_name = args[:identity_name] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/jav/tab.rb', line 10 def description @description end |
#holds_one_field ⇒ Object
Returns the value of attribute holds_one_field.
10 11 12 |
# File 'lib/jav/tab.rb', line 10 def holds_one_field @holds_one_field end |
#identity_name ⇒ Object (readonly)
Returns the value of attribute identity_name.
9 10 11 |
# File 'lib/jav/tab.rb', line 9 def identity_name @identity_name end |
#items_holder ⇒ Object
Returns the value of attribute items_holder.
10 11 12 |
# File 'lib/jav/tab.rb', line 10 def items_holder @items_holder end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
9 10 11 |
# File 'lib/jav/tab.rb', line 9 def view @view end |
Instance Method Details
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/jav/tab.rb', line 55 def empty? visible_items.blank? end |
#has_a_single_item? ⇒ Boolean
68 69 70 |
# File 'lib/jav/tab.rb', line 68 def has_a_single_item? items.count == 1 end |
#hydrate(view: nil) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/jav/tab.rb', line 37 def hydrate(view: nil) @view = view items_holder.items.grep(Jav::Panel).each do |panel| panel.hydrate(view: view) end self end |
#name ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/jav/tab.rb', line 29 def name if @name.respond_to?(:call) Jav::Hosts::BaseHost.new(block: @name).handle else @name end end |
#turbo_frame_id(parent: nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/jav/tab.rb', line 47 def turbo_frame_id(parent: nil) id = "#{Jav::Tab.to_s.parameterize} #{name} #{@identity_name}".parameterize return id if parent.nil? "#{parent.turbo_frame_id} #{id}".parameterize end |
#visible_on?(view) ⇒ Boolean
Checks for visibility on itself or on theone field it holds
60 61 62 63 64 65 66 |
# File 'lib/jav/tab.rb', line 60 def visible_on?(view) if holds_one_field super && items.first.visible_on?(view) else super end end |