Module: Avo::Concerns::VisibleInDifferentViews

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#show_on_editObject

Returns the value of attribute show_on_edit.



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

def show_on_edit
  @show_on_edit
end

#show_on_indexObject

Returns the value of attribute show_on_index.



4
5
6
# File 'lib/avo/concerns/visible_in_different_views.rb', line 4

def show_on_index
  @show_on_index
end

#show_on_newObject

Returns the value of attribute show_on_new.



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

def show_on_new
  @show_on_new
end

#show_on_previewObject

Returns the value of attribute show_on_preview.



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

def show_on_preview
  @show_on_preview
end

#show_on_showObject

Returns the value of attribute show_on_show.



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

def show_on_show
  @show_on_show
end

Instance Method Details

#except_on(*where) ⇒ Object



61
62
63
64
65
66
# File 'lib/avo/concerns/visible_in_different_views.rb', line 61

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

#hide_on(*where) ⇒ Object



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

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_viewsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/avo/concerns/visible_in_different_views.rb', line 14

def initialize_views
  # Set defaults
  @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
  @show_on_preview = @show_on_preview.nil? ? false : @show_on_preview

  if @args.present?
    # Execute options
    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?
  end
end

#only_on(*where) ⇒ Object



54
55
56
57
58
59
# File 'lib/avo/concerns/visible_in_different_views.rb', line 54

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

#post_initializeObject



10
11
12
# File 'lib/avo/concerns/visible_in_different_views.rb', line 10

def post_initialize
  initialize_views
end

#show_on(*where) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/avo/concerns/visible_in_different_views.rb', line 38

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



69
70
71
# File 'lib/avo/concerns/visible_in_different_views.rb', line 69

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



74
75
76
# File 'lib/avo/concerns/visible_in_different_views.rb', line 74

def show_on_update
  show_on_edit
end

#visible_in_view?(view:) ⇒ Boolean

Validates if the field is visible on certain view

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/avo/concerns/visible_in_different_views.rb', line 32

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

  send :"show_on_#{view}"
end