Module: Jav::Fields::FieldExtensions::VisibleInDifferentViews

Included in:
BaseResourceTool, BaseField, Sidebar, Tab
Defined in:
lib/jav/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.



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

def show_on_edit
  @show_on_edit
end

#show_on_indexObject

Returns the value of attribute show_on_index.



5
6
7
# File 'lib/jav/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.



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

def show_on_new
  @show_on_new
end

#show_on_showObject

Returns the value of attribute show_on_show.



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

def show_on_show
  @show_on_show
end

Instance Method Details

#except_on(*where) ⇒ Object



44
45
46
47
48
49
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 44

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

#hide_on(*where) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 29

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



7
8
9
10
11
12
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 7

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



37
38
39
40
41
42
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 37

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

#show_on(*where) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 21

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



52
53
54
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 52

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



57
58
59
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 57

def show_on_update
  show_on_edit
end

#visible_on?(view) ⇒ Boolean

Validates if the field is visible on certain view

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/jav/fields/field_extensions/visible_in_different_views.rb', line 15

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

  send :"show_on_#{view}"
end