Prettify the Customer pages
authorIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 20:33:12 +0000 (12:33 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 20:33:12 +0000 (12:33 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/customer_controller.rb
app/views/customer/index.rhtml [new file with mode: 0644]
app/views/customer/list.rhtml
app/views/customer/search.rhtml [moved from app/views/customer/searchbyname.rhtml with 73% similarity]
app/views/customer/searchresults.rhtml
app/views/layouts/admin.rhtml

index 1e560c0..296f64f 100644 (file)
@@ -1,11 +1,11 @@
 class CustomerController < ApplicationController
+  layout "admin"
 
   # Make sure that the user has logged in before they can take any action
   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)
@@ -53,12 +53,13 @@ class CustomerController < ApplicationController
     redirect_to :action => 'list'
   end
 
-  def searchbyname
-    render :action => 'searchbyname'
-  end
-
-  def searchresults
-    query = params[:q]
-    @customers = Customer.find(:all, :conditions => ["name like ?", query[0]+"%"] )
+  def search
+    if request.post?
+      @query = params[:q]
+      @customers = Customer.find(:all, :conditions => ["name like ?", @query[0]+"%"])
+      render :action => 'searchresults'
+    else
+      render :action => 'search'
+    end
   end
 end
diff --git a/app/views/customer/index.rhtml b/app/views/customer/index.rhtml
new file mode 100644 (file)
index 0000000..521b806
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Customer Maintenence</h1>
+
+<h3>Actions</h3>
+<ul>
+  <li><%= link_to 'List All Customers', :action => 'list' %></li>
+  <li><%= link_to 'Search for a Customer', :action => 'search' %></li>
+  <li><%= link_to 'Add a new Customer to the system', :action => 'new' %></li>
+</ul>
index 30ffdb6..c9bce2b 100644 (file)
@@ -1,6 +1,6 @@
-<h1>Listing customers</h1>
+<h1>Listing Customers</h1>
 
-<table>
+<table border="1">
   <tr>
   <th>Customer ID</th>
   <% for column in Customer.content_columns %>
@@ -14,9 +14,9 @@
   <% for column in Customer.content_columns %>
     <td><%=h customer.send(column.name) %></td>
   <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => customer %></td>
+    <td><%= link_to 'View', :action => 'show', :id => customer %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => customer %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %></td>
   </tr>
 <% end %>
 </table>
similarity index 73%
rename from app/views/customer/searchbyname.rhtml
rename to app/views/customer/search.rhtml
index 7b17ec1..fd105b7 100644 (file)
@@ -1,6 +1,6 @@
 <h1>Search for a Customer by Name</h1>
 
-<%= start_form_tag :action => 'searchresults'%>
+<%= start_form_tag :action => 'search'%>
 <%= text_field 'q', nil  %>
   <%= submit_tag 'Search' %></form>
 <%= end_form_tag %>
index a6488ce..cc32efe 100644 (file)
@@ -1,9 +1,9 @@
-<h1>Search Results</h1>
+<h1>Search Results for '<%= @query[0].to_s %>'</h1>
 
 <% if @customers.empty? %>
 <p>Sorry, there were no results</p>
 <% else %>
-<table>
+<table border="1">
   <tr>
   <th>Customer ID</th>
   <% for column in Customer.content_columns %>
index aba2ff5..a4ad91a 100644 (file)
@@ -19,7 +19,7 @@
       <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 => 'index' %></p>
-      <p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %></p>
+      <p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'index' %></p>
       <br/>
       <p><%= link_to "Logout", :controller => 'login', :action => 'logout' %></p>
     </div>