From aafbf2bd36dcfa82f56d4586fa19a7d9a1f815e6 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 25 Nov 2007 12:23:13 -0800 Subject: [PATCH] Prettify the COItem pages Also, remove some unneeded functions from the controller, such as create and destroy. Signed-off-by: Ira W. Snyder --- app/controllers/coitem_controller.rb | 89 ++++++++++++--------------- app/views/coitem/index.rhtml | 8 +++ app/views/coitem/list.rhtml | 33 ++++------ app/views/coitem/new.rhtml | 8 --- app/views/coitem/overdue.rhtml | 32 ++++++++++ app/views/coitem/return.rhtml | 4 +- app/views/layouts/admin.rhtml | 2 +- db/development.sqlite3 | Bin 24576 -> 24576 bytes 8 files changed, 94 insertions(+), 82 deletions(-) create mode 100644 app/views/coitem/index.rhtml delete mode 100644 app/views/coitem/new.rhtml create mode 100644 app/views/coitem/overdue.rhtml 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 7f2b35ab1ba24679bbd21b637aa1f11f26474d79..5dff97849d345a10ad62e7d3f94da65eb718f913 100644 GIT binary patch delta 327 zcmZoTz}Rqrae_3X(MFjU>;h~|=|IFR#GJ`=nE5vI%8iY|Oq0{Oq8TM7ALe>$%woXC z&LFI)t;*<=nCFvUtl*fFn44c*kXn*jnaoS$oAYNl&qY@%yuY+}kV`8Kzj zDDx2pHfB8r<}BuA%pJ^n%s$MInDsU`N-$5>> z%w?FMvYaq60}B|-&|-22zl{w81A`pc0Jst(W0(>nQyEUE0Za%nILl&_z;kg%{mn1b zWfYjj84@P5duXw4VCY~-nAoVrq~z>;%EH8`PDFt?0l?D>1<5t%tFkWOoy3oZ)^-@nw-uR%_ubaFxOLKGsQ@A zRYsS@JcZ!A%9PY16Jv7)@67z1;*!J^1(zZ{Uao+g#N^bxlFURM1!qTIE=!}yx4G3s z85kJYne`Z$A2AkujWQ zCc_GmWnzSjA!JP_cktWT$S^?-;KZgxh7l^ughkeDlfZLvMuW{S)MXTyMHuc(X7|vV T*tD8S%XxCYt=eW5&p%=S