Skip to content

Commit

Permalink
Making the homepage a little bit DRY'er to use the table partial
Browse files Browse the repository at this point in the history
  • Loading branch information
bamnet committed Apr 28, 2010
1 parent caa0390 commit 95d0ed8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Expand Up @@ -19,7 +19,7 @@ def show
@docs.delete_if {|x| !x.allowed_to_read} #Hide private documents
if @category.allowed_to_read #Show only if the user is allowed to see it
if request.xhr?
render :partial=>'documents/' + @doc_display, :locals => {:documents => @docs}
render :partial=>'documents/' + @doc_display, :locals => {:documents => @docs, :is_ajax => true}
else
respond_to do |format|
format.html # show.html.erb
Expand Down
2 changes: 1 addition & 1 deletion app/views/categories/show.html.erb
Expand Up @@ -66,7 +66,7 @@

<h2 id="doclist">Documents<%= link_to 'Add', new_document_path(:category_id => @category.id), :class => "link-button" if (logged_in? && @category.allowed_to_save) %></h2>
<div id="doc_holder">
<%= render :partial => 'documents/' + @doc_display, :locals => {:documents => @docs} %>
<%= render :partial => 'documents/' + @doc_display, :locals => {:documents => @docs, :is_ajax => true} %>
</div>
<br />
</div>
4 changes: 3 additions & 1 deletion app/views/documents/_grid.html.erb
@@ -1,4 +1,6 @@
<%= link_to 'View in Table', category_path(:type => 'table', :anchor => "doclist"), :class => "link-button update_holder", :style => "font-size:0.6em;" %>
<% if (defined? is_ajax) && is_ajax %>
<%= link_to 'View in Table', category_path(:type => 'table', :anchor => "doclist"), :class => "link-button update_holder", :style => "font-size:0.6em;" %>
<% end %>
<br /><br />
<ul class="iconlist">
<% documents.each do |document| %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/documents/_table.html.erb
@@ -1,4 +1,6 @@
<%= link_to 'View in Grid', category_path(:type => 'grid', :anchor => "doclist"), :class => "link-button update_holder", :style => "font-size:0.6em;" %>
<% if (defined? is_ajax) && is_ajax %>
<%= link_to 'View in Grid', category_path(:type => 'grid', :anchor => "doclist"), :class => "link-button update_holder", :style => "font-size:0.6em;" %>
<% end %>
<br /><br />
<% if !documents.empty? %>
<table cellpadding="0" cellspacing="0" width="100%" class="docs">
Expand Down
39 changes: 1 addition & 38 deletions app/views/home/index.html.erb
Expand Up @@ -6,44 +6,7 @@
<br />
<% if !category.documents.empty? %>
<% docs = category.documents.find(:all, :order => "updated_at DESC", :limit => 3) %>
<table cellpadding="0" cellspacing="0" width="100%" class="docs">
<thead>
<tr class="cat_title">
<th style="text-align:right;">Title</th>
<th>Link</th>
<th style="text-align:left;">Description</th>
<th>Downloads</th>
<th>Updated</th>
<th></th>
</tr>
</thead>
<tbody>
<% docs.each do |document| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><% link_to document do %><h2><%=h document.title %></h2><% end %></td>
<td class="doc_img">
<% unless document.current_revision.blank? %>
<% link_to download_document_revision_path(document, 'current') do %>
<%= image_tag("icons/icon_#{document.current_revision.type}_40.png", {:alt => "Download File", :width => "40px", :height => "40px"}) %>
<% end %>
<% end %>
</td>
<td><p><%=h document.description %></p></td>
<td><%=h document.downloaded %></td>
<td><%=h document.updated_at.strftime('%D') %></td>
<td>
<% if admin_logged_in? || (logged_in? && document.allowed_to_save) %>
<span>
<%= link_to 'Edit', edit_document_path(document), :class => 'edit-link' %>
&nbsp;
<%= link_to 'Remove', document_path(document), :confirm => 'Are you sure you want to remove this document?', :method => :delete, :class => 'cancel-link' %>
</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= render :partial=>'documents/table', :locals => {:documents => docs} %>
<% if category.documents.size > 3 %>
<br />
<p style="text-align:right;"><%= link_to "View More...", category %></p>
Expand Down

0 comments on commit 95d0ed8

Please sign in to comment.