Class: Dima::Html::Table
- Inherits:
-
AbstractForm
- Object
- Element
- AbstractForm
- Dima::Html::Table
- Defined in:
- lib/dima/html/form.rb
Overview
Table.
Instance Attribute Summary collapse
-
#actions_width ⇒ Object
Returns the value of attribute actions_width.
-
#vals ⇒ Object
Returns the value of attribute vals.
Attributes inherited from AbstractForm
#collapsed, #help, #icon, #method, #submit, #title
Instance Method Summary collapse
- #cols ⇒ Object
- #generate_body ⇒ Object
-
#generate_content ⇒ Object
Getting html node for this form.
- #generate_header ⇒ Object
- #generate_row(val) ⇒ Object
- #generate_table ⇒ Object
-
#item_actions ⇒ Object
Get form’s actions.
Methods inherited from AbstractForm
Methods included from Init
Methods inherited from Element
Instance Attribute Details
#actions_width ⇒ Object
Returns the value of attribute actions_width.
191 192 193 |
# File 'lib/dima/html/form.rb', line 191 def actions_width @actions_width end |
#vals ⇒ Object
Returns the value of attribute vals.
190 191 192 |
# File 'lib/dima/html/form.rb', line 190 def vals @vals end |
Instance Method Details
#cols ⇒ Object
199 200 201 |
# File 'lib/dima/html/form.rb', line 199 def cols @cols ||= FormFields.new end |
#generate_body ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/dima/html/form.rb', line 231 def generate_body tbody = Node.new(tag: 'tbody') if vals and vals.any? vals.each do |val| tbody << generate_row(val) end else tr = Node.new(tag: 'tr') size = item_actions.empty? ? cols.size : cols.size + 1 td = Node.new(tag: 'td', attributes: { colspan: cols.size + 1, class: 'dim-empty' }, text: '(no data)') tr << td tbody << tr end tbody end |
#generate_content ⇒ Object
Getting html node for this form.
204 205 206 207 |
# File 'lib/dima/html/form.rb', line 204 def generate_content generate_table end |
#generate_header ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/dima/html/form.rb', line 216 def generate_header thead = Node.new(tag: 'thead') tr = Node.new(tag: 'tr') cols.fields.each do |f| if f.[:col_width] tr << Node.new(tag: 'th', text: f.label, attributes: { width: f.[:col_width] }) else tr << Node.new(tag: 'th', text: f.label) end end tr << Node.new(tag: 'th', text: '', attributes: { width: actions_width || 100 }) unless item_actions.empty? thead << tr thead end |
#generate_row(val) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/dima/html/form.rb', line 247 def generate_row(val) tr = Node.new(tag: 'tr') cols.fields.each do |f| f << val td = Node.new(tag: 'td', attributes: { class: 'dim-field' }) td.add_class(f.align) if f.align td << f.value_node tr << td end unless item_actions.empty? td = Node.new(tag: 'td', attributes: { class: 'dim-table-actions' }) item_actions.each do |a| td << a.to_n(val) end tr << td end tr end |
#generate_table ⇒ Object
209 210 211 212 213 214 |
# File 'lib/dima/html/form.rb', line 209 def generate_table tbl = Node.new(tag: 'table', attributes: { class: 'dim-table' }) tbl << generate_header tbl << generate_body tbl end |
#item_actions ⇒ Object
Get form’s actions.
194 195 196 |
# File 'lib/dima/html/form.rb', line 194 def item_actions @item_actions ||= [] end |