Module: SmartListing::Helper
- Defined in:
- app/helpers/smart_listing/helper.rb
Defined Under Namespace
Modules: ControllerExtensions Classes: Builder
Instance Method Summary collapse
-
#smart_listing_for(name, *args, &block) ⇒ Object
Outputs smart list container.
-
#smart_listing_item(name, item_action, object = nil, partial = nil, options = {}) ⇒ Object
Renders single item (i.e for create, update actions).
-
#smart_listing_item_actions(actions = []) ⇒ Object
Render item action buttons (ie. edit, destroy and custom ones).
- #smart_listing_limit_left(name) ⇒ Object
-
#smart_listing_update(name) ⇒ Object
Updates the smart list.
Instance Method Details
#smart_listing_for(name, *args, &block) ⇒ Object
Outputs smart list container
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/helpers/smart_listing/helper.rb', line 143 def smart_listing_for name, *args, &block raise ArgumentError, "Missing block" unless block_given? name = name.to_sym = args. = .delete(:bare) builder = Builder.new(name, @smart_listings[name], self, , block) output ="" data = {} data['max-count'] = @smart_listings[name].max_count if @smart_listings[name].max_count && @smart_listings[name].max_count > 0 data['href'] = @smart_listings[name].href if @smart_listings[name].href if output = capture(builder, &block) else output = content_tag(:div, :class => "smart_listing", :id => name, :data => data) do concat(content_tag(:div, "", :class => "loading")) concat(content_tag(:div, :class => "content") do concat(capture(builder, &block)) end) end end output end |
#smart_listing_item(name, item_action, object = nil, partial = nil, options = {}) ⇒ Object
Renders single item (i.e for create, update actions)
250 251 252 253 254 255 256 257 |
# File 'app/helpers/smart_listing/helper.rb', line 250 def smart_listing_item name, item_action, object = nil, partial = nil, = {} name = name.to_sym type = object.class.name.downcase.to_sym if object id = object.id if object object_key = .delete(:object_key) || :object render(:partial => "smart_listing/item/#{item_action.to_s}", :locals => {:name => name, :id => id, :object_key => object_key, :object => object, :part => partial}) end |
#smart_listing_item_actions(actions = []) ⇒ Object
Render item action buttons (ie. edit, destroy and custom ones)
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'app/helpers/smart_listing/helper.rb', line 172 def smart_listing_item_actions actions = [] content_tag(:span) do actions.each do |action| next unless action.is_a?(Hash) if action.has_key?(:if) unless action[:if] concat(content_tag(:i, '', :class => "glyphicon glyphicon-remove-circle")) next end end case action.delete(:name).to_sym when :edit url = action.delete(:url) = { :remote => true, :class => "edit", :title => t("smart_listing.actions.edit") }.merge(action) concat(link_to(url, ) do concat(content_tag(:i, '', :class => "glyphicon glyphicon-pencil")) end) when :destroy url = action.delete(:url) icon = action.delete(:icon) || "glyphicon glyphicon-trash" = { :remote => true, :class => "destroy", :method => :delete, :title => t("smart_listing.actions.destroy"), :data => {:confirmation => action.delete(:confirmation) || t("smart_listing.msgs.destroy_confirmation")}, }.merge(action) concat(link_to(url, ) do concat(content_tag(:i, '', :class => icon)) end) when :custom url = action.delete(:url) icon = action.delete(:icon) = action concat(link_to(url, ) do concat(content_tag(:i, '', :class => icon)) end) end end end end |
#smart_listing_limit_left(name) ⇒ Object
223 224 225 226 227 228 |
# File 'app/helpers/smart_listing/helper.rb', line 223 def smart_listing_limit_left name name = name.to_sym smart_listing = @smart_listings[name] smart_listing.max_count - smart_listing.count end |
#smart_listing_update(name) ⇒ Object
Updates the smart list
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'app/helpers/smart_listing/helper.rb', line 234 def smart_listing_update name name = name.to_sym smart_listing = @smart_listings[name] builder = Builder.new(name, smart_listing, self, {}, nil) render(:partial => 'smart_listing/update_list', :locals => { :name => smart_listing.name, :part => smart_listing.partial, :smart_listing => builder, :smart_listing_data => { :params => smart_listing.all_params, 'max-count' => smart_listing.max_count, } }) end |