Class: Dima::Html::Table

Inherits:
AbstractForm show all
Defined in:
lib/dima/html/form.rb

Overview

Table.

Instance Attribute Summary collapse

Attributes inherited from AbstractForm

#collapsed, #help, #icon, #method, #submit, #title

Instance Method Summary collapse

Methods inherited from AbstractForm

#actions, #html, #to_n

Methods included from Init

#initialize

Methods inherited from Element

#id, #id=

Instance Attribute Details

#actions_widthObject

Returns the value of attribute actions_width.



191
192
193
# File 'lib/dima/html/form.rb', line 191

def actions_width
  @actions_width
end

#valsObject

Returns the value of attribute vals.



190
191
192
# File 'lib/dima/html/form.rb', line 190

def vals
  @vals
end

Instance Method Details

#colsObject



199
200
201
# File 'lib/dima/html/form.rb', line 199

def cols
  @cols ||= FormFields.new
end

#generate_bodyObject



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_contentObject

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_headerObject



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.options[:col_width]
      tr << Node.new(tag: 'th', text: f.label, attributes: { width: f.options[: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_tableObject



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_actionsObject

Get form’s actions.



194
195
196
# File 'lib/dima/html/form.rb', line 194

def item_actions
  @item_actions ||= []
end