Class: Spyro::ActionViewExtension::CollectionForHelper::Output::Table
- Inherits:
-
Base
- Object
- Base
- Spyro::ActionViewExtension::CollectionForHelper::Output::Table
show all
- Includes:
- Fields
- Defined in:
- lib/spyro/collections/outputs/table.rb
Instance Method Summary
collapse
Methods included from Fields
#format_boolean, #format_classy_enum, #format_cw_file, #format_cw_image, #format_datetime, #format_default, #format_email, #format_float, #format_html, #format_period, #format_prct, #format_progress, #format_string, #format_text, #format_url
Methods inherited from Base
#initialize, #t
Instance Method Details
70
71
72
|
# File 'lib/spyro/collections/outputs/table.rb', line 70
def custom_value_formatted value, elem
value
end
|
#default_destroy_link_attributes ⇒ Object
30
31
32
|
# File 'lib/spyro/collections/outputs/table.rb', line 30
def default_destroy_link_attributes
{:data => {:confirm => "Are you sure?", :method => "delete", :'confirm-title' => "Confirmation"}}
end
|
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/spyro/collections/outputs/table.rb', line 57
def format_value value, elem
return self.send("format_#{elem.as}".to_sym, value, {}) if elem.as
@@fields.each do |keys, values|
klass, pattern = *keys
if (Symbol === klass and klass == elem.db_type) or (Class === klass and value.is_a? klass)
return self.send("format_#{values[:method]}".to_sym, value, {}) if elem.name.to_s.match pattern
end
end
value
end
|
14
15
16
|
# File 'lib/spyro/collections/outputs/table.rb', line 14
def
||= (@unicollection.meta[:header] || []) + (@unicollection.meta[:actions] ? ['Actions'] : [])
end
|
#render ⇒ Object
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/spyro/collections/outputs/table.rb', line 112
def render
return "" if @unicollection.rows.empty?
table_html_opts = {:class => ['table', self.class.to_s.demodulize.underscore]}.deep_merge(@unicollection.meta[:html] || {}) { |key, old, new| Array.wrap(old) + Array.wrap(new) }
content_tag :table, table_html_opts do
html = .html_safe
html << render_body
html <<
html
end
end
|
#render_body ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/spyro/collections/outputs/table.rb', line 74
def render_body
content = @unicollection.rows.map do |row|
html = row[:data].map do |elem|
value_formatted = elem.value
value_formatted = t(value_formatted) if elem.translate
value_formatted = format_value value_formatted, elem
value_formatted = link_to value_formatted, elem.link if elem.link
value_formatted = custom_value_formatted value_formatted, elem
elem.html ? content_tag(:td, value_formatted, elem.html) : "<td>#{value_formatted}</td>"
end.join('')
html += render_cell_buttons row if @unicollection.meta[:actions]
(row[:meta][:opts] and row[:meta][:opts][:html]) ? content_tag(:tr, html.html_safe, row[:meta][:opts][:html]) : "<tr>#{html}</tr>"
end.join('').html_safe
if @unicollection.meta[:header]
content_tag :tbody, @unicollection.meta[:html_body] do
content
end
else
content
end
end
|
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/spyro/collections/outputs/table.rb', line 34
def render_cell_buttons row
row[:meta][:actions] = {} if row[:meta][:actions].nil?
html = if row[:meta][:actions].is_a? Hash
(row[:meta][:actions] || []).map do |name, link|
case name
when :show
mini_button_success name, link
when :edit
mini_button_info name, link
when :destroy
mini_button_danger name, link, default_destroy_link_attributes
else
mini_button name, link
end
end.join ''
else
row[:meta][:actions]
end
"<td><span class='btn-group'>#{html}</span></td>"
end
|
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/spyro/collections/outputs/table.rb', line 97
def
return "" unless @unicollection.meta[:footer] and @unicollection.meta[:header]
total = .count
content_tag :tfoot, @unicollection.meta[:html_footer] do
content = @unicollection.meta[:footer].map do |elem|
colspan = [(.count / @unicollection.meta[:footer].count.to_f).ceil, total].min
total -= colspan
"<td colspan='#{colspan}'>#{elem}</td>"
end.join('')
"<tr>#{content}</tr>".html_safe
end
end
|
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/spyro/collections/outputs/table.rb', line 18
def
return "" unless @unicollection.meta[:header]
content_tag :thead, @unicollection.meta[:html_header] do
html = .map do ||
= t()
= @unicollection.meta[:block_header].call , if @unicollection.meta[:block_header]
"<th>#{header}</th>"
end.join('')
"<tr>#{html}</tr>".html_safe
end
end
|