Class: SuperLookingList
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#list ⇒ Object
Returns the value of attribute list.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#table_width ⇒ Object
Returns the value of attribute table_width.
Instance Method Summary collapse
- #format_column(item, column) ⇒ Object
-
#initialize(model, list, columns, speed, table_width, options = {}) ⇒ SuperLookingList
constructor
A new instance of SuperLookingList.
- #render(xml = nil, &block) ⇒ Object
Constructor Details
#initialize(model, list, columns, speed, table_width, options = {}) ⇒ SuperLookingList
Returns a new instance of SuperLookingList.
7 8 9 |
# File 'lib/smklib/super_looking_list.rb', line 7 def initialize(model, list, columns, speed, table_width, = {}) @model, @list, @columns, @speed, @table_width, @options = model, list, columns, speed, table_width, end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def columns @columns end |
#list ⇒ Object
Returns the value of attribute list.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def list @list end |
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def model @model end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def @options end |
#speed ⇒ Object
Returns the value of attribute speed.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def speed @speed end |
#table_width ⇒ Object
Returns the value of attribute table_width.
5 6 7 |
# File 'lib/smklib/super_looking_list.rb', line 5 def table_width @table_width end |
Instance Method Details
#format_column(item, column) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/smklib/super_looking_list.rb', line 11 def format_column(item, column) c = column[:field] val = item.send(c) if column[:format] val = column[:format].call(item, c) else if item.respond_to? :format_for_display STDERR.puts "Warning: {model}::format_for_display is deprecated (#{item.to_s})" val = item.format_for_display(c) end end val = "n/a" if val.to_s.empty? return val.to_s end |
#render(xml = nil, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/smklib/super_looking_list.rb', line 26 def render(xml = nil, &block) xml ||= Builder::XmlMarkup.new(:indent => 2) xml.div do xml.tight_table("border" => "1", "width" => table_width.to_s, "cellpadding" => "2", "class" => "SuperTableList #{@model.capitalize}") do xml.tr do columns.each { |c| xml.th { if [:header_format] [:header_format].call(xml, c) else xml << c[:label] end } } end idx = 0 for item in list style = ((idx % 2 == 0) ? "even" : "odd") + " type_#{item.class}" xml.tr("id" => "#{model}_row_#{idx}", "onclick" => "proceed_on_click(this, #{speed})", "onmouseover" => "show_details(this);", "class" => style, "onmouseout" => "hide_last_shown(this);") do columns.each do |col| xml.td("class" => "field_#{col[:field]}") { xml << format_column(item, col) } end end xml.tr("class" => "current", "id" => "#{model}_row_#{idx}_details", "style" => "display: none;") do xml.td("colspan" => columns.size) do xml.div("style" => "overflow: auto;", "id" => "#{model}_row_#{idx}_block_details") do yield(xml, item) end end end idx += 1 end end end end |