Class: SmartListing::Helper::Builder
- Inherits:
-
Object
- Object
- SmartListing::Helper::Builder
- Defined in:
- app/helpers/smart_listing/helper.rb
Constant Summary collapse
- UNSAFE_PARAMS =
Params that should not be visible in pagination links (pages, per-page, sorting, etc.)
{:authenticity_token => nil, :utf8 => nil}
Instance Method Summary collapse
- #collection ⇒ Object
-
#empty? ⇒ Boolean
Check if smart list is empty.
-
#initialize(smart_listing_name, smart_listing, template, options, proc) ⇒ Builder
constructor
A new instance of Builder.
-
#item_new(options = {}) ⇒ Object
Add new item button & placeholder to list.
-
#max_count? ⇒ Boolean
Check if smart list reached its item max count.
- #paginate(options = {}) ⇒ Object
- #pagination_per_page_links(options = {}) ⇒ Object
-
#render(options = {}, locals = {}, &block) ⇒ Object
Basic render block wrapper that adds smart_listing reference to local variables.
-
#render_list ⇒ Object
Renders the main partial (whole list).
- #sortable(title, attribute, options = {}) ⇒ Object
- #update(options = {}) ⇒ Object
Constructor Details
#initialize(smart_listing_name, smart_listing, template, options, proc) ⇒ Builder
Returns a new instance of Builder.
27 28 29 |
# File 'app/helpers/smart_listing/helper.rb', line 27 def initialize(smart_listing_name, smart_listing, template, , proc) @smart_listing_name, @smart_listing, @template, @options, @proc = smart_listing_name, smart_listing, template, , proc end |
Instance Method Details
#collection ⇒ Object
37 38 39 |
# File 'app/helpers/smart_listing/helper.rb', line 37 def collection @smart_listing.collection end |
#empty? ⇒ Boolean
Check if smart list is empty
125 126 127 |
# File 'app/helpers/smart_listing/helper.rb', line 125 def empty? @smart_listing.count == 0 end |
#item_new(options = {}) ⇒ Object
Add new item button & placeholder to list
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/smart_listing/helper.rb', line 107 def item_new = {} @template.concat(@template.content_tag(:tr, '', :class => "info new_item_placeholder disabled")) @template.concat(@template.content_tag(:tr, :class => "info new_item_action #{'disabled' if !empty? && max_count?}") do @template.concat(@template.content_tag(:td, :colspan => .delete(:colspan)) do @template.concat(@template.content_tag(:p, :class => "no_records pull-left #{'disabled' unless empty?}") do @template.concat(.delete(:no_items_text)) end) @template.concat(@template.link_to(.delete(:link), :remote => true, :class => "btn pull-right #{'disabled' if max_count?}") do @template.concat(@template.content_tag(:i, '', :class => "glyphicon glyphicon-plus")) @template.concat(" ") @template.concat(.delete(:text)) end) end) end) nil end |
#max_count? ⇒ Boolean
Check if smart list reached its item max count
130 131 132 133 |
# File 'app/helpers/smart_listing/helper.rb', line 130 def max_count? return false if @smart_listing.max_count.nil? @smart_listing.count >= @smart_listing.max_count end |
#paginate(options = {}) ⇒ Object
31 32 33 34 35 |
# File 'app/helpers/smart_listing/helper.rb', line 31 def paginate = {} if @smart_listing.collection.respond_to? :current_page @template.paginate @smart_listing.collection, :remote => true, :param_name => @smart_listing.param_names[:page], :params => UNSAFE_PARAMS end end |
#pagination_per_page_links(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/smart_listing/helper.rb', line 41 def pagination_per_page_links = {} @template.content_tag(:div, :class => "pagination_per_page #{'disabled' if empty?}") do if @smart_listing.count > @smart_listing.page_sizes.first @template.concat(@template.t('views.pagination.per_page')) per_page_sizes = @smart_listing.page_sizes.clone per_page_sizes.push(0) if @smart_listing.unlimited_per_page? per_page_sizes.each do |p| name = p == 0 ? @template.t('views.pagination.unlimited') : p if @smart_listing.per_page.to_i != p @template.concat(@template.link_to(name, @template.url_for(sanitize_params(@template.params.merge(@smart_listing.param_names[:per_page] => p, @smart_listing.param_names[:page] => 1))), :remote => true)) else @template.concat(@template.content_tag(:span, name)) end break if p > @smart_listing.count end @template.concat ' | ' end if @smart_listing.[:paginate] @template.concat(@template.t('views.pagination.total')) @template.concat(@template.content_tag(:span, @smart_listing.count, :class => "count")) end end |
#render(options = {}, locals = {}, &block) ⇒ Object
Basic render block wrapper that adds smart_listing reference to local variables
96 97 98 99 100 101 102 103 104 |
# File 'app/helpers/smart_listing/helper.rb', line 96 def render = {}, locals = {}, &block if locals.empty? [:locals] ||= {} [:locals].merge!(:smart_listing => self) else locals.merge!({:smart_listing => self}) end @template.render , locals, &block end |
#render_list ⇒ Object
Renders the main partial (whole list)
89 90 91 92 93 |
# File 'app/helpers/smart_listing/helper.rb', line 89 def render_list if @smart_listing.partial @template.render :partial => @smart_listing.partial, :locals => {:smart_listing => self} end end |
#sortable(title, attribute, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/smart_listing/helper.rb', line 63 def sortable title, attribute, = {} extra = .delete(:extra) sort_params = { @smart_listing.param_names[:sort_attr] => attribute, @smart_listing.param_names[:sort_order] => (@smart_listing.sort_order == "asc") ? "desc" : "asc", @smart_listing.param_names[:sort_extra] => extra } @template.link_to(@template.url_for(sanitize_params(@template.params.merge(sort_params))), :class => "sortable", :data => {:attr => attribute}, :remote => true) do @template.concat(title) if @smart_listing.sort_attr == attribute && (!@smart_listing.sort_extra || @smart_listing.sort_extra == extra.to_s) @template.concat(@template.content_tag(:span, "", :class => (@smart_listing.sort_order == "asc" ? "glyphicon glyphicon-chevron-up" : "glyphicon glyphicon-chevron-down"))) else @template.concat(@template.content_tag(:span, "", :class => "glyphicon glyphicon-resize-vertical")) end end end |
#update(options = {}) ⇒ Object
82 83 84 85 86 |
# File 'app/helpers/smart_listing/helper.rb', line 82 def update = {} part = .delete(:partial) || @smart_listing.partial || @smart_listing_name @template.render(:partial => 'smart_listing/update_list', :locals => {:name => @smart_listing_name, :part => part, :smart_listing => self}) end |