Class: Forma::Table
Instance Attribute Summary collapse
Instance Method Summary
collapse
#active_title, #title_element
#boolean_field, #combo_field, #complex_field, #date_field, #email_field, #image_field, #map_field, #number_field, #password_field, #select_field, #subform, #text_field
Methods included from Html
attr, el
Constructor Details
#initialize(h = {}) ⇒ Table
Returns a new instance of Table.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/forma/table.rb', line 10
def initialize(h = {})
h = h.symbolize_keys
@id = h[:id]
@title = h[:title]
@icon = h[:icon]
@collapsible = h[:collapsible]
@collapsed = h[:collapsed]
@models = h[:models]
@fields = h[:fields] || []
@paginate = h[:paginate]
@title_actions = h[:title_actions] || []
@item_actions = h[:item_actions] || []
@context = h[:context]
end
|
Instance Attribute Details
#collapsed ⇒ Object
Returns the value of attribute collapsed.
7
8
9
|
# File 'lib/forma/table.rb', line 7
def collapsed
@collapsed
end
|
#collapsible ⇒ Object
Returns the value of attribute collapsible.
7
8
9
|
# File 'lib/forma/table.rb', line 7
def collapsible
@collapsible
end
|
#icon ⇒ Object
Returns the value of attribute icon.
7
8
9
|
# File 'lib/forma/table.rb', line 7
def icon
@icon
end
|
#title ⇒ Object
Returns the value of attribute title.
7
8
9
|
# File 'lib/forma/table.rb', line 7
def title
@title
end
|
#title_actions ⇒ Object
Returns the value of attribute title_actions.
8
9
10
|
# File 'lib/forma/table.rb', line 8
def title_actions
@title_actions
end
|
Instance Method Details
#add_field(f) ⇒ Object
50
51
52
|
# File 'lib/forma/table.rb', line 50
def add_field(f)
@fields << f
end
|
#item_action(url, h = {}) ⇒ Object
45
46
47
48
|
# File 'lib/forma/table.rb', line 45
def item_action(url, h={})
h[:url] = url
@item_actions << Action.new(h)
end
|
#paginate(h = {}) ⇒ Object
54
55
56
57
|
# File 'lib/forma/table.rb', line 54
def paginate(h={})
@paginate = true
@paginate_options = h
end
|
#table_body_element ⇒ Object
96
97
98
99
|
# File 'lib/forma/table.rb', line 96
def table_body_element
children =
el('tbody', children: @models.map { |model| table_row(model) })
end
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/forma/table.rb', line 72
def
children = @fields.map { |f|
f.model = @models.first
label_text = f.localized_label
label_hint = f.localized_hint
el('th', attrs: { class: 'ff-field' }, text: label_text, children: [
(el('i', attrs: { class: 'ff-field-hint', 'data-toggle' => 'tooltip', title: label_hint }) if label_hint.present?)
])
}
children << el('th', attrs: { style: {width: '100px'} }) if @item_actions.any?
el('thead', children: [
el('tr', children: children)
])
end
|
#table_row(model) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/forma/table.rb', line 86
def table_row(model)
children = @fields.map { |fld|
fld.model = model
el('td', children: [ fld.to_html(false) ])
}
if @item_actions.any?
children << el('td', children: @item_actions.map { |act| act.to_html(model) })
end
el('tr', children: children)
end
|
#title_action(url, h = {}) ⇒ Object
40
41
42
43
|
# File 'lib/forma/table.rb', line 40
def title_action(url, h={})
h[:url] = url
@title_actions << Action.new(h)
end
|
#to_html ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/forma/table.rb', line 29
def to_html
el(
'div',
attrs: { id: @id, class: ['ff-table'] },
children: [
title_element,
body_element,
]
)
end
|