Module: Avo::Fields::FieldExtensions::VisibleInDifferentViews

Included in:
BaseResourceTool, BaseField, Sidebar, Tab
Defined in:
lib/avo/fields/field_extensions/visible_in_different_views.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#show_on_editObject

Returns the value of attribute show_on_edit.



8
9
10
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 8

def show_on_edit
  @show_on_edit
end

#show_on_indexObject

Returns the value of attribute show_on_index.



5
6
7
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 5

def show_on_index
  @show_on_index
end

#show_on_newObject

Returns the value of attribute show_on_new.



7
8
9
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 7

def show_on_new
  @show_on_new
end

#show_on_showObject

Returns the value of attribute show_on_show.



6
7
8
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 6

def show_on_show
  @show_on_show
end

Instance Method Details

#except_on(*where) ⇒ Object



47
48
49
50
51
52
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 47

def except_on(*where)
  show_on_all
  normalize_views(where).flatten.each do |view|
    show_on_view view
  end
end

#hide_on(*where) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 32

def hide_on(*where)
  return hide_on_all if where.include? :all

  normalize_views(where).flatten.each do |view|
    hide_on_view view
  end
end

#initialize(id = nil, **args, &block) ⇒ Object



10
11
12
13
14
15
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 10

def initialize(id = nil, **args, &block)
  @show_on_index = @show_on_index.nil? ? true : @show_on_index
  @show_on_show = @show_on_show.nil? ? true : @show_on_show
  @show_on_new = @show_on_new.nil? ? true : @show_on_new
  @show_on_edit = @show_on_edit.nil? ? true : @show_on_edit
end

#only_on(*where) ⇒ Object



40
41
42
43
44
45
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 40

def only_on(*where)
  hide_on_all
  normalize_views(where).flatten.each do |view|
    show_on_view view
  end
end

#show_on(*where) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 24

def show_on(*where)
  return show_on_all if where.include? :all

  normalize_views(where).flatten.each do |view|
    show_on_view view
  end
end

#show_on_createObject

When submitting the form on creation, the new page will be create but we don’t have a visibility marker for create so we’ll default to new



55
56
57
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 55

def show_on_create
  show_on_new
end

#show_on_updateObject

When submitting the form on update, the new page will be create but we don’t have a visibility marker for update so we’ll default to edit



60
61
62
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 60

def show_on_update
  show_on_edit
end

#visible_on?(view) ⇒ Boolean

Validates if the field is visible on certain view

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/avo/fields/field_extensions/visible_in_different_views.rb', line 18

def visible_on?(view)
  raise "No view specified on visibility check." if view.blank?

  send :"show_on_#{view.to_s}"
end