class AutoForme::Table

  1. lib/autoforme/table.rb
Superclass: Object

Helper class for formating HTML tables used for the browse/search results pages.

Methods

Public Class

  1. new

Public Instance

  1. action
  2. columns
  3. h
  4. model
  5. objs
  6. request
  7. to_s
  8. type

Attributes

action [R]

The AutoForme::Action for the current table

columns [R]

The data columns for the current table

model [R]

The AutoForme::Model for the current table

objs [R]

An array of objects to show in the table

request [R]

The AutoForme::Request for the current table

type [R]

The action type for the current table

Public Class methods

new (action, objs)
[show source]
   # File lib/autoforme/table.rb
24 def initialize(action, objs)
25   @action = action
26   @request = action.request
27   @model = action.model
28   @type = action.normalized_type
29   @columns = model.columns_for(type, request)
30   @objs = objs
31 end

Public Instance methods

h (s)
[show source]
   # File lib/autoforme/table.rb
33 def h(s)
34   action.h(s)
35 end
to_s ()

Return an HTML string for the table.

[show source]
   # File lib/autoforme/table.rb
38 def to_s
39   html = String.new
40   html << "<table id=\"autoforme_table\" class=\"#{model.table_class_for(type, request)}\">"
41 
42   html << "<thead><tr>"
43   columns.each do |column|
44     html << "<th>#{h action.column_label_for(type, request, model, column)}</th>"
45   end
46   html << "<th>Show</th>" if show = model.supported_action?(:show, request)
47   html << "<th>Edit</th>" if edit = model.supported_action?(:edit, request)
48   html << "<th>Delete</th>" if delete = model.supported_action?(:delete, request)
49   html << "</tr></thead>"
50 
51   html << "<tbody>"
52   objs.each do |obj|
53     html << "<tr>"
54     columns.each do |column|
55       unless val = model.show_html_for(obj, column, type, request)
56         val = model.column_value(type, request, obj, column)
57         val = val.to_s('F') if defined?(BigDecimal) && val.is_a?(BigDecimal)
58         val = h(val)
59       end
60       html << "<td>#{val}</td>"
61     end
62     html << "<td><a href=\"#{action.url_for("show/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-info\">Show</a></td>" if show
63     html << "<td><a href=\"#{action.url_for("edit/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-primary\">Edit</a></td>" if edit
64     html << "<td><a href=\"#{action.url_for("delete/#{model.primary_key_value(obj)}")}\" class=\"btn btn-xs btn-danger\">Delete</a></td>" if delete
65     html << "</tr>"
66   end
67   html << "</tbody></table>"
68   html
69 end