Module: ActsAsDataTableHelper
- Defined in:
- app/helpers/acts_as_data_table_helper.rb
Instance Method Summary collapse
- #active_scope_filter(group) ⇒ Object
-
#scope_filter_arg(group, scope, name) ⇒ Object, NilClass
Looks up a set argument for a given filter, e.g.
-
#scope_filter_args(group, scope) ⇒ Hash
Arguments used for the given filter.
-
#scope_filter_caption(group, scope, args = {}) ⇒ Object
Generates a scope filter caption.
- #scope_filter_form(group, scope, options = {}, &proc) ⇒ Object
-
#scope_filter_form_url(group, scope) ⇒ String
Generates a URL to be used as form action for filters which require dynamic arguments.
-
#scope_filter_link(group, scope, options = {}) ⇒ Object
Generates a link to add/remove a certain scope filter.
-
#scope_filter_link_url(group, scope, options) ⇒ String
Generates a URL to add/remove/toggle a given scope filter.
-
#scope_filter_reset_url ⇒ String
URL to remove all active scope filters for the current action.
-
#sortable_column(model, column, caption, options = {}, &proc) ⇒ Object
—————————————————————- Sortable Columns —————————————————————-.
- #sortable_column_data(model, column) ⇒ Object
Instance Method Details
#active_scope_filter(group) ⇒ Object
127 128 129 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 127 def active_scope_filter(group) acts_as_data_table_session.active_filter(group) end |
#scope_filter_arg(group, scope, name) ⇒ Object, NilClass
Looks up a set argument for a given filter, e.g. to highlight it in the search results
108 109 110 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 108 def scope_filter_arg(group, scope, name) Acts::DataTable.lookup_nested_hash(acts_as_data_table_session.active_filters, group.to_s, scope.to_s, name.to_s) end |
#scope_filter_args(group, scope) ⇒ Hash
Returns Arguments used for the given filter.
115 116 117 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 115 def scope_filter_args(group, scope) Acts::DataTable.lookup_nested_hash(acts_as_data_table_session.active_filters, group.to_s, scope.to_s) || {} end |
#scope_filter_caption(group, scope, args = {}) ⇒ Object
Generates a scope filter caption
122 123 124 125 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 122 def (group, scope, args = {}) model = Acts::DataTable::ScopeFilters::ActionController.get_request_model Acts::DataTable::ScopeFilters::ActiveRecord.(model, group, scope, args) end |
#scope_filter_form(group, scope, options = {}, &proc) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 79 def scope_filter_form(group, scope, = {}, &proc) content = capture(Acts::DataTable::ScopeFilters::FormHelper.new(self, group, scope), &proc) method = [:method] || :get if .delete(:remote) .delete(:method) form_remote_tag :url => scope_filter_form_url(group, scope), :method => method, :html => do concat(content) end else form_tag scope_filter_form_url(group, scope), do concat(content) end end end |
#scope_filter_form_url(group, scope) ⇒ String
Generates a URL to be used as form action for filters which require dynamic arguments
74 75 76 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 74 def scope_filter_form_url(group, scope) url_for({:scope_filters => {:action => 'add', :group => group, :scope => scope}}) end |
#scope_filter_link(group, scope, options = {}) ⇒ Object
Generates a link to add/remove a certain scope filter
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 22 def scope_filter_link(group, scope, = {}) = .delete(:caption) || (group, scope, [:args]) surrounding_tag = .delete(:surrounding) remote = .delete(:remote) args = [:args] url = scope_filter_link_url(group, scope, ) classes = [:class].try(:split, ' ') || [] classes << 'active' if scope && acts_as_data_table_session.active_filter?(group, scope, args) [:class] = classes.join(' ') if remote link = link_to_remote , :url => url, :method => :get, :html => else link = link_to , url, end surrounding_tag ? content_tag(surrounding_tag, link, :class => [:class]) : link end |
#scope_filter_link_url(group, scope, options) ⇒ String
Generates a URL to add/remove/toggle a given scope filter
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 50 def scope_filter_link_url(group, scope, ) args = .delete(:args) toggle = .delete(:toggle) auto_remove = scope && toggle && acts_as_data_table_session.active_filter?(group, scope, args) remove = .delete(:remove) || auto_remove if remove url_for({:scope_filters => {:action => 'remove', :group => group}}) else url_for({:scope_filters => {:action => 'add', :group => group, :scope => scope, :args => args}}) end end |
#scope_filter_reset_url ⇒ String
Returns URL to remove all active scope filters for the current action.
97 98 99 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 97 def scope_filter_reset_url url_for({:scope_filters => {:action => :reset}}) end |
#sortable_column(model, column, caption, options = {}, &proc) ⇒ Object
Sortable Columns
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 135 def sortable_column(model, column, , = {}, &proc) renderer_class = .delete(:renderer) || Acts::DataTable::SortableColumns::Renderers.default_renderer sortable = sortable_column_data(model, column) sortable[:html_options] = sortable[:caption] = sortable[:remote] = .delete(:remote) sortable[:remote] = true if sortable[:remote].blank? sortable = OpenStruct.new(sortable) #If a block is given, we let the user handle the content of the table #header himself. Otherwise, we'll generate the default links. if block_given? yield sortable else renderer = renderer_class.is_a?(Class) ? renderer_class : renderer_class.constantize renderer.new(sortable, self).to_html end end |
#sortable_column_data(model, column) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/helpers/acts_as_data_table_helper.rb', line 155 def sortable_column_data(model, column) sortable = {} sortable[:direction] = acts_as_data_table_session.sorting_direction(model, column) sortable[:active] = acts_as_data_table_session.active_column?(model, column) urls = {} urls[:toggle] = url_for({:sortable_columns => {:action => :toggle, :model => model, :column => column}}) urls[:change_direction] = url_for({:sortable_columns => {:action => :change_direction, :model => model, :column => column}}) urls[:set_base] = url_for({:sortable_columns => {:action => :set_base, :model => model, :column => column}}) sortable[:urls] = OpenStruct.new(urls) sortable end |