Prettify the COItem pages
authorIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 20:23:13 +0000 (12:23 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 20:23:13 +0000 (12:23 -0800)
Also, remove some unneeded functions from the controller, such as
create and destroy.

Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/coitem_controller.rb
app/views/coitem/index.rhtml [new file with mode: 0644]
app/views/coitem/list.rhtml
app/views/coitem/new.rhtml [deleted file]
app/views/coitem/overdue.rhtml [new file with mode: 0644]
app/views/coitem/return.rhtml
app/views/layouts/admin.rhtml
db/development.sqlite3

index d93a4b0..ef8ea7c 100644 (file)
@@ -1,12 +1,12 @@
 class CoitemController < ApplicationController
+  layout "admin"
 
   # Make sure that the user has logged in before they can take any
   # action on checked out items
   before_filter :authorize
 
   def index
-    list
-    render :action => 'list'
+    render :action => 'index'
   end
 
   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
@@ -21,19 +21,8 @@ class CoitemController < ApplicationController
     @coitem = Coitem.find(params[:id])
   end
 
-  def new
-    @coitem = Coitem.new
-  end
-
-  def create
-    @coitem = Coitem.new(params[:coitem])
-    if @coitem.save
-      flash[:notice] = 'Coitem was successfully created.'
-      redirect_to :action => 'list'
-    else
-      render :action => 'new'
-    end
-  end
+  # We should never create new checked out items via the web interface, so remove
+  # the new and create methods.
 
   def edit
     @coitem = Coitem.find(params[:id])
@@ -49,48 +38,46 @@ class CoitemController < ApplicationController
     end
   end
 
-  def destroy
-    Coitem.find(params[:id]).destroy
-    redirect_to :action => 'list'
-  end
+  # We should never delete a checked out item directly via the web interface, so
+  # remove the destroy method.
 
   # Awesome, paginating overdue list, ordered by customer
   def overdue
-    @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => "due_date < DATE('NOW', 'LOCALTIME')", :order => "customer_id"
-    render :action => 'list'
+    @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => ["due_date < ?", Time.now.to_date], :order => "customer_id"
+    render :action => 'overdue'
   end
 
   def return
-    render :action => 'return'
-  end
-
-  def return_validate
-    rentable_id = params[:rentable_id]
-    @rentable = Rentable.find_by_id(rentable_id)
-
-    if @rentable.nil?
-      flash[:error] = "Unable to find this rentable"
-      redirect_to :action => :return
-      return
-    end
-
-    @coitem = Coitem.find_by_rentable_id(rentable_id)
-    if @coitem.nil?
-      flash[:error] = "This item is not checked out!"
-      redirect_to :action => :return
-      return
-    end
-
-    # Check if the item is overdue
-    if @coitem.overdue?
-      @coitem.customer.debt += @coitem.late_fee
-      @coitem.customer.save
+    if request.post?
+      rentable_id = params[:rentable_id]
+      @rentable = Rentable.find_by_id(rentable_id)
+
+      if @rentable.nil?
+        flash[:notice] = "Unable to find this rentable"
+        redirect_to :action => :return
+        return
+      end
+
+      @coitem = Coitem.find_by_rentable_id(rentable_id)
+      if @coitem.nil?
+        flash[:notice] = "This item is not checked out!"
+        redirect_to :action => :return
+        return
+      end
+
+      # Check if the item is overdue
+      if @coitem.overdue?
+        @coitem.customer.debt += @coitem.late_fee
+        @coitem.customer.save
+      end
+
+      # Delete the row
+      @coitem.destroy
+
+      flash[:notice] = "Successfully returned item"
+      redirect_to :action => :return, :method => :get
+    else
+      render :action => 'return'
     end
-
-    # Delete the row
-    @coitem.destroy
-
-    flash[:notice] = "Successfully returned item"
-    redirect_to :action => :return
   end
 end
diff --git a/app/views/coitem/index.rhtml b/app/views/coitem/index.rhtml
new file mode 100644 (file)
index 0000000..3465f5a
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Checked Out Items Maintenence</h1>
+
+<h3>Actions</h3>
+<ul>
+  <li><%= link_to 'List All Checked Out Items', :action => 'list' %></li>
+  <li><%= link_to 'List All Overdue Items', :action => 'overdue' %></li>
+  <li><%= link_to 'Return a Checked Out Item', :action => 'return' %></li>
+</ul>
index f6514cb..2b0db69 100644 (file)
@@ -1,26 +1,22 @@
-<h1>Listing coitems</h1>
+<h1>Listing Checked Out Items</h1>
 
-<table>
+<table border="1">
   <tr>
-  <th>Customer</th>
-  <th>Rentable</th>
-  <th>Overdue</th>
-  <% for column in Coitem.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
+    <th>Customer</th>
+    <th>Rentable</th>
+    <th>Overdue</th>
+    <th>Date Checked Out</th>
+    <th>Due Date</th>
   </tr>
   
 <% for coitem in @coitems %>
   <tr>
-  <td><%=h coitem.customer.name %></td>
-  <td><%=h coitem.rentable.title %></td>
-  <td><%=h coitem.overdue? %></td>
-  <% for column in Coitem.content_columns %>
-    <td><%=h coitem.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => coitem %></td>
-    <td><%= link_to 'Edit', :action => 'edit', :id => coitem %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => coitem }, :confirm => 'Are you sure?', :method => :post %></td>
+    <td><%=h coitem.customer.name %></td>
+    <td><%=h coitem.rentable.title %></td>
+    <td><%=h tf_to_yesno(coitem.overdue?) %></td>
+    <td><%=h coitem.out_date %></td>
+    <td><%=h coitem.due_date %></td>
+    <td><%= link_to 'View', :action => 'show', :id => coitem %></td>
   </tr>
 <% end %>
 </table>
@@ -28,6 +24,3 @@
 <%= link_to 'Previous page', { :page => @coitem_pages.current.previous } if @coitem_pages.current.previous %>
 <%= link_to 'Next page', { :page => @coitem_pages.current.next } if @coitem_pages.current.next %> 
 
-<br />
-
-<%= link_to 'New coitem', :action => 'new' %>
diff --git a/app/views/coitem/new.rhtml b/app/views/coitem/new.rhtml
deleted file mode 100644 (file)
index a494968..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<h1>New coitem</h1>
-
-<% form_tag :action => 'create' do %>
-  <%= render :partial => 'form' %>
-  <%= submit_tag "Create" %>
-<% end %>
-
-<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/coitem/overdue.rhtml b/app/views/coitem/overdue.rhtml
new file mode 100644 (file)
index 0000000..d6f525e
--- /dev/null
@@ -0,0 +1,32 @@
+<h1>Listing Overdue Items</h1>
+
+<table border="1">
+  <tr>
+    <th>Customer</th>
+    <th>Customer Phone #</th>
+    <th>Customer Email</th>
+    <th>Type</th>
+    <th>Title</th>
+    <th>Overdue</th>
+    <th>Date Checked Out</th>
+    <th>Due Date</th>
+  </tr>
+  
+<% for coitem in @coitems %>
+  <tr>
+    <td><%=link_to coitem.customer.name, :controller => 'customer', :action => 'show', :id => coitem.customer.id %></td>
+    <td><%=h coitem.customer.phone %></td>
+    <td><%=h coitem.customer.email %></td>
+    <td><%=h coitem.rentable.type %></td>
+    <td><%=h coitem.rentable.title %></td>
+    <td><%=h tf_to_yesno(coitem.overdue?) %></td>
+    <td><%=h coitem.out_date %></td>
+    <td><%=h coitem.due_date %></td>
+    <td><%= link_to 'View', :action => 'show', :id => coitem %></td>
+  </tr>
+<% end %>
+</table>
+
+<%= link_to 'Previous page', { :page => @coitem_pages.current.previous } if @coitem_pages.current.previous %>
+<%= link_to 'Next page', { :page => @coitem_pages.current.next } if @coitem_pages.current.next %> 
+
index 4a15185..8f537f0 100644 (file)
@@ -1,6 +1,6 @@
-<h1>Return a Rentable Item</h1>
+<h1>Return a Checked Out Item</h1>
 
-<%= start_form_tag :action => 'return_validate'%>
+<%= start_form_tag :action => 'return'%>
 <%= text_field 'rentable_id', nil  %>
   <%= submit_tag 'Ok' %></form>
 <%= end_form_tag %>
index d271822..aba2ff5 100644 (file)
@@ -18,7 +18,7 @@
       <br/>
       <p><%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %></p>
       <p><%= link_to "Game Maintenence", :controller => 'game', :action => 'index' %></p>
-      <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %></p>
+      <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'index' %></p>
       <p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %></p>
       <br/>
       <p><%= link_to "Logout", :controller => 'login', :action => 'logout' %></p>
index 7f2b35a..5dff978 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ