From: Ira W. Snyder Date: Sun, 25 Nov 2007 20:23:13 +0000 (-0800) Subject: Prettify the COItem pages X-Git-Tag: turned-in~35 X-Git-Url: https://irasnyder.com/gitweb/?a=commitdiff_plain;h=aafbf2bd36dcfa82f56d4586fa19a7d9a1f815e6;hp=db65069f5aa7906f44428b54c26cbf7fe490c2de;p=cs356-p2-videostore.git Prettify the COItem pages Also, remove some unneeded functions from the controller, such as create and destroy. Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/coitem_controller.rb b/app/controllers/coitem_controller.rb index d93a4b0..ef8ea7c 100644 --- a/app/controllers/coitem_controller.rb +++ b/app/controllers/coitem_controller.rb @@ -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 index 0000000..3465f5a --- /dev/null +++ b/app/views/coitem/index.rhtml @@ -0,0 +1,8 @@ +

Checked Out Items Maintenence

+ +

Actions

+ diff --git a/app/views/coitem/list.rhtml b/app/views/coitem/list.rhtml index f6514cb..2b0db69 100644 --- a/app/views/coitem/list.rhtml +++ b/app/views/coitem/list.rhtml @@ -1,26 +1,22 @@ -

Listing coitems

+

Listing Checked Out Items

- +
- - - - <% for column in Coitem.content_columns %> - - <% end %> + + + + + <% for coitem in @coitems %> - - - - <% for column in Coitem.content_columns %> - - <% end %> - - - + + + + + + <% end %>
CustomerRentableOverdue<%= column.human_name %>CustomerRentableOverdueDate Checked OutDue Date
<%=h coitem.customer.name %><%=h coitem.rentable.title %><%=h coitem.overdue? %><%=h coitem.send(column.name) %><%= link_to 'Show', :action => 'show', :id => coitem %><%= link_to 'Edit', :action => 'edit', :id => coitem %><%= link_to 'Destroy', { :action => 'destroy', :id => coitem }, :confirm => 'Are you sure?', :method => :post %><%=h coitem.customer.name %><%=h coitem.rentable.title %><%=h tf_to_yesno(coitem.overdue?) %><%=h coitem.out_date %><%=h coitem.due_date %><%= link_to 'View', :action => 'show', :id => coitem %>
@@ -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 %> -
- -<%= link_to 'New coitem', :action => 'new' %> diff --git a/app/views/coitem/new.rhtml b/app/views/coitem/new.rhtml deleted file mode 100644 index a494968..0000000 --- a/app/views/coitem/new.rhtml +++ /dev/null @@ -1,8 +0,0 @@ -

New coitem

- -<% 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 index 0000000..d6f525e --- /dev/null +++ b/app/views/coitem/overdue.rhtml @@ -0,0 +1,32 @@ +

Listing Overdue Items

+ + + + + + + + + + + + + +<% for coitem in @coitems %> + + + + + + + + + + + +<% end %> +
CustomerCustomer Phone #Customer EmailTypeTitleOverdueDate Checked OutDue Date
<%=link_to coitem.customer.name, :controller => 'customer', :action => 'show', :id => coitem.customer.id %><%=h coitem.customer.phone %><%=h coitem.customer.email %><%=h coitem.rentable.type %><%=h coitem.rentable.title %><%=h tf_to_yesno(coitem.overdue?) %><%=h coitem.out_date %><%=h coitem.due_date %><%= link_to 'View', :action => 'show', :id => coitem %>
+ +<%= 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 %> + diff --git a/app/views/coitem/return.rhtml b/app/views/coitem/return.rhtml index 4a15185..8f537f0 100644 --- a/app/views/coitem/return.rhtml +++ b/app/views/coitem/return.rhtml @@ -1,6 +1,6 @@ -

Return a Rentable Item

+

Return a Checked Out Item

-<%= start_form_tag :action => 'return_validate'%> +<%= start_form_tag :action => 'return'%> <%= text_field 'rentable_id', nil %> <%= submit_tag 'Ok' %> <%= end_form_tag %> diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml index d271822..aba2ff5 100644 --- a/app/views/layouts/admin.rhtml +++ b/app/views/layouts/admin.rhtml @@ -18,7 +18,7 @@

<%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %>

<%= link_to "Game Maintenence", :controller => 'game', :action => 'index' %>

-

<%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %>

+

<%= link_to "Checked Out Items", :controller => 'coitem', :action => 'index' %>

<%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %>


<%= link_to "Logout", :controller => 'login', :action => 'logout' %>

diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 7f2b35a..5dff978 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ