Created
April 21, 2011 19:03
-
-
Save tylerflint/935256 to your computer and use it in GitHub Desktop.
BlockPile Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# views/shared/_simple_list_container.html.erb | |
<div class="content company"> | |
<ul class="list <%= p.object_label_plural.downcase %>"> | |
<li class="first search" title="Search <%= p.object_label_plural.capitalize %> List"><span class="admin-sprite icon"></span><input id="search-filter" value="Search <%= p.object_label_plural.capitalize %>" onfocus="if(this.value=='Search <%= p.object_label_plural.capitalize %>')value=''" onblur="if(this.value=='')this.value='Search <%= p.object_label_plural.capitalize %>'"/> | |
<div class='actions-bar'> | |
<a href="<%= url_for [:new, :admin, @company, p.object] %>" title="Add New <%= p.object_label_plural %>" class="sprite add"></a> | |
<a href="#link" title="Enables [Item] Removal" class="sprite remove" onclick="toggleRemove()"></a> | |
</div> | |
</li> | |
<div class="results"> | |
<%= p.list %> | |
</div> | |
<li class="last"><a href="<%= url_for [:new, :admin, @company, p.object] %>" class="add" title="Add New">Add New <%= p.object_label %><span class="sprite add"></span></a></li> | |
</ul> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- views/companies/index.html.erb --> | |
<% content_for :left do %> | |
<%= render :partial => 'admin/companies/menu', :locals => {:active => :companies} %> | |
<% end %> | |
<%= simple_list(:company, @companies, {:item_url => "admin_company_dashboard_url"}) %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# helpers/simple_list_pile.rb | |
class SimpleListPile < Blockpile::Base | |
def build(object, collection, options={}) | |
@object = object | |
@collection = collection | |
@options = options | |
@display_column = options[:display_column] || :name | |
@template = 'admin/shared/simple_list_container' | |
end | |
def show_all? | |
params[:show_all] && params[:show_all].eql?('true') | |
end | |
def object | |
@object | |
end | |
def object_label | |
object.to_s.capitalize | |
end | |
def object_label_plural | |
object_label.pluralize | |
end | |
def collection | |
if params[:search] | |
@collection = @collection.where(@display_column => /^#{params[:search]}.*/i) | |
end | |
@collection = @collection.limit(10) unless show_all? | |
@collection.asc(@display_column) | |
end | |
def item_url(company, item) | |
if @options[:item_url] | |
eval "#{@options[:item_url]}('#{item.id}')" | |
else | |
url_for [:edit, :admin, company, item] | |
end | |
end | |
def list | |
render( :partial => 'admin/shared/simple_list', :locals => {:p => self} ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment