Class: TableFor::Base
- Inherits:
-
WithTemplate::Base
- Object
- WithTemplate::Base
- TableFor::Base
- Defined in:
- lib/table_for/base.rb
Instance Attribute Summary collapse
-
#current_record ⇒ Object
(also: #current_row)
Returns the value of attribute current_record.
Instance Method Summary collapse
- #cell_content(record, column, options = {}) ⇒ Object
- #footer(options = {}, &block) ⇒ Object
- #header(name, options = {}, &block) ⇒ Object
- #header_cell_content(column, options = {}) ⇒ Object
- #header_column_html(column, options = {}) ⇒ Object
- #header_sort_link(column, options = {}, &block) ⇒ Object
-
#initialize(view, options = {}) ⇒ Base
constructor
A new instance of Base.
- #set_current_record(record) ⇒ Object
Constructor Details
#initialize(view, options = {}) ⇒ Base
Returns a new instance of Base.
12 13 14 |
# File 'lib/table_for/base.rb', line 12 def initialize(view, ={}) super(view, TableFor.config.merge()) end |
Instance Attribute Details
#current_record ⇒ Object Also known as: current_row
Returns the value of attribute current_record.
9 10 11 |
# File 'lib/table_for/base.rb', line 9 def current_record @current_record end |
Instance Method Details
#cell_content(record, column, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/table_for/base.rb', line 53 def cell_content(record, column, ={}) if [:link_url] || [:link_action] || [:link_method] || [:link_confirm] || [:link] url = [:link_url] ? call_with_params([:link_url], record) : [[:link_action], [:link_namespace], record].flatten end if [:formatter] if [:formatter].is_a?(Proc) content = call_with_params([:formatter], record.send(column.name), ) else content = record.send(column.name).try(*[:formatter]) end elsif [:data] || [:edit, :show, :delete].include?(column.name) content = call_with_params([:data], record) else content = record.send(column.name) end if content.blank? || url.blank? || [:link] == false content elsif url view.link_to content, url, {:method => [:link_method], :confirm => [:link_confirm]}.merge([:link_html]) end end |
#footer(options = {}, &block) ⇒ Object
20 21 22 |
# File 'lib/table_for/base.rb', line 20 def (={}, &block) define(:footer_content, , &block) end |
#header(name, options = {}, &block) ⇒ Object
16 17 18 |
# File 'lib/table_for/base.rb', line 16 def header(name, ={}, &block) define("#{name.to_s}_header", .reverse_merge(:header => true), &block) end |
#header_cell_content(column, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/table_for/base.rb', line 39 def header_cell_content(column, ={}) unless [:header] == false header_sort_link(column, ) do if [:header] call_with_params [:header], column elsif column.anonymous nil else I18n.t("#{translation_lookup_prefix}.#{column.name.to_s.underscore}", :default => column.name.to_s.titleize) end end end end |
#header_column_html(column, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/table_for/base.rb', line 24 def header_column_html(column, ={}) header_column_html = call_each_hash_value_with_params([:header_column_html], column) if [:sortable] order = [:order] ? [:order].to_s : column.name.to_s sort_modes = TableFor.config.sort_modes current_sort_mode = (view.params[:order] != order || view.params[:sort_mode].blank?) ? nil : view.params[:sort_mode] current_sort_mode = sort_modes[sort_modes.index(current_sort_mode.to_sym)] rescue nil if current_sort_mode sort_class = "sorting#{"_#{current_sort_mode}" if current_sort_mode}" header_column_html[:class] = (header_column_html[:class] ? "#{header_column_html[:class]} #{sort_class}" : sort_class) end header_column_html end |
#header_sort_link(column, options = {}, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/table_for/base.rb', line 81 def header_sort_link(column, ={}, &block) if [:sortable] && ([:header] || !column.anonymous) order = [:order] ? [:order].to_s : column.name.to_s sort_modes = TableFor.config.sort_modes current_sort_mode = (view.params[:order] != order || view.params[:sort_mode].blank?) ? nil : view.params[:sort_mode] next_sort_mode_index = sort_modes.index(current_sort_mode.to_sym) + 1 rescue 0 if next_sort_mode_index == sort_modes.length next_sort_mode = nil else next_sort_mode = sort_modes[next_sort_mode_index] end parameters = view.params.merge(:order => order, :sort_mode => next_sort_mode) parameters.delete(:action) parameters.delete(:controller) url = [:sort_url] ? [:sort_url] : "" view.link_to view.capture(self, &block), "#{url}?#{parameters.to_query}" else view.capture(self, &block) end end |
#set_current_record(record) ⇒ Object
77 78 79 |
# File 'lib/table_for/base.rb', line 77 def set_current_record(record) self.current_record = record end |