From 544bfab488e8b62e7b13a622d966e4927f4bf5e0 Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Mon, 19 Jun 2006 05:32:35 +0000
Subject: [PATCH] Unify layout in application.rhtml.  Added logout button and
 made it work.

---
 app/controllers/application.rb        |  5 -----
 app/controllers/users_controller.rb   | 11 ++++++++---
 app/views/call_attempts/edit.rhtml    |  2 +-
 app/views/call_attempts/list.rhtml    |  2 +-
 app/views/call_attempts/new.rhtml     |  2 +-
 app/views/call_attempts/show.rhtml    |  2 ++
 app/views/layouts/application.rhtml   | 21 +++++++++++++++++++++
 app/views/layouts/call_attempts.rhtml | 13 -------------
 app/views/layouts/recordings.rhtml    | 13 -------------
 app/views/layouts/users.rhtml         | 13 -------------
 app/views/recordings/edit.rhtml       |  2 +-
 app/views/recordings/list.rhtml       |  2 +-
 app/views/recordings/list_owned.rhtml |  2 +-
 app/views/recordings/new.rhtml        |  2 +-
 app/views/recordings/show.rhtml       |  1 +
 app/views/users/edit.rhtml            |  2 +-
 app/views/users/list.rhtml            |  2 +-
 app/views/users/login.rhtml           |  2 +-
 app/views/users/new.rhtml             |  2 +-
 app/views/users/show.rhtml            |  1 +
 20 files changed, 44 insertions(+), 58 deletions(-)
 create mode 100644 app/views/layouts/application.rhtml
 delete mode 100644 app/views/layouts/call_attempts.rhtml
 delete mode 100644 app/views/layouts/recordings.rhtml
 delete mode 100644 app/views/layouts/users.rhtml

diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index af59594..c08899c 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -1,9 +1,4 @@
 # Filters added to this controller will be run for all controllers in the application.
 # Likewise, all the methods added will be available for all controllers.
 class ApplicationController < ActionController::Base
-  def logout
-    cookies.delete :user_id
-    flash[:notice] = "You have been logged out"
-    redirect_to :controller => "users", :action => "login"
-  end
 end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index a3fafd6..a1a495c 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -50,12 +50,10 @@ class UsersController < ApplicationController
   end
 
   def login
-
-    logger.add(Logger::DEBUG, "This is a log message!")
-
     @user_pages, @users = paginate :users, :per_page => 10
 
     if params[:id].nil?
+      @hide_logout = true
       return
     end
       
@@ -69,4 +67,11 @@ class UsersController < ApplicationController
     flash[:notice] = "Welcome, " + user.username
     redirect_to :controller => "recordings", :action => "list_owned"
   end
+
+  def logout
+    cookies.delete :user_id
+    flash[:notice] = "You have been logged out"
+    redirect_to :controller => "users", :action => "login"
+  end
+
 end
diff --git a/app/views/call_attempts/edit.rhtml b/app/views/call_attempts/edit.rhtml
index db61e46..5bd1800 100644
--- a/app/views/call_attempts/edit.rhtml
+++ b/app/views/call_attempts/edit.rhtml
@@ -1,4 +1,4 @@
-<h1>Editing call_attempt</h1>
+<% @heading = "Editing call_attempt" %>
 
 <%= start_form_tag :action => 'update', :id => @call_attempt %>
   <%= render :partial => 'form' %>
diff --git a/app/views/call_attempts/list.rhtml b/app/views/call_attempts/list.rhtml
index 7fe5cec..db46b0b 100644
--- a/app/views/call_attempts/list.rhtml
+++ b/app/views/call_attempts/list.rhtml
@@ -1,4 +1,4 @@
-<h1>Listing call_attempts</h1>
+<% @heading = "Listing call_attempts" %>
 
 <table>
   <tr>
diff --git a/app/views/call_attempts/new.rhtml b/app/views/call_attempts/new.rhtml
index 2f38ef2..81eaac6 100644
--- a/app/views/call_attempts/new.rhtml
+++ b/app/views/call_attempts/new.rhtml
@@ -1,4 +1,4 @@
-<h1>New call_attempt</h1>
+<% @heading = "New call_attempt" %>
 
 <%= start_form_tag :action => 'create' %>
   <%= render :partial => 'form' %>
diff --git a/app/views/call_attempts/show.rhtml b/app/views/call_attempts/show.rhtml
index 07fb205..4937c48 100644
--- a/app/views/call_attempts/show.rhtml
+++ b/app/views/call_attempts/show.rhtml
@@ -1,3 +1,5 @@
+<% @heading = "Showing call_attempt" %>
+
 <% for column in CallAttempt.content_columns %>
 <p>
   <b><%= column.human_name %>:</b> <%=h @call_attempt.send(column.name) %>
diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml
new file mode 100644
index 0000000..5e7fff9
--- /dev/null
+++ b/app/views/layouts/application.rhtml
@@ -0,0 +1,21 @@
+<html>
+<head>
+  <title><%= @heading %></title>
+  <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<h1><%= @heading %></h1>
+<%= @content_for_layout %>
+
+<% unless @hide_logout %>
+  <form method="post" 
+	action="<%= url_for :controller=>"users", :action=>"logout" %>" >
+    <input type="submit" value="Logout" />
+  </form>
+<% end %>
+
+</body>
+</html>
diff --git a/app/views/layouts/call_attempts.rhtml b/app/views/layouts/call_attempts.rhtml
deleted file mode 100644
index d8a91f4..0000000
--- a/app/views/layouts/call_attempts.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-  <title>CallAttempts: <%= controller.action_name %></title>
-  <%= stylesheet_link_tag 'scaffold' %>
-</head>
-<body>
-
-<p style="color: green"><%= flash[:notice] %></p>
-
-<%= @content_for_layout %>
-
-</body>
-</html>
diff --git a/app/views/layouts/recordings.rhtml b/app/views/layouts/recordings.rhtml
deleted file mode 100644
index fd35911..0000000
--- a/app/views/layouts/recordings.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-  <title>Recordings: <%= controller.action_name %></title>
-  <%= stylesheet_link_tag 'scaffold' %>
-</head>
-<body>
-
-<p style="color: green"><%= flash[:notice] %></p>
-
-<%= @content_for_layout %>
-
-</body>
-</html>
diff --git a/app/views/layouts/users.rhtml b/app/views/layouts/users.rhtml
deleted file mode 100644
index 30bf3ce..0000000
--- a/app/views/layouts/users.rhtml
+++ /dev/null
@@ -1,13 +0,0 @@
-<html>
-<head>
-  <title>Users: <%= controller.action_name %></title>
-  <%= stylesheet_link_tag 'scaffold' %>
-</head>
-<body>
-
-<p style="color: green"><%= flash[:notice] %></p>
-
-<%= @content_for_layout %>
-
-</body>
-</html>
diff --git a/app/views/recordings/edit.rhtml b/app/views/recordings/edit.rhtml
index 32de3c1..9358bc9 100644
--- a/app/views/recordings/edit.rhtml
+++ b/app/views/recordings/edit.rhtml
@@ -1,4 +1,4 @@
-<h1>Editing recording</h1>
+<% @heading = "New call_attempt" %>
 
 <%= start_form_tag :action => 'update', :id => @recording %>
   <%= render :partial => 'form' %>
diff --git a/app/views/recordings/list.rhtml b/app/views/recordings/list.rhtml
index a231230..f80b5f6 100644
--- a/app/views/recordings/list.rhtml
+++ b/app/views/recordings/list.rhtml
@@ -1,4 +1,4 @@
-<h1>Listing recordings</h1>
+<% @heading = "Listing recordings" %>
 
 <table>
   <tr>
diff --git a/app/views/recordings/list_owned.rhtml b/app/views/recordings/list_owned.rhtml
index 7df55e3..0588d6f 100644
--- a/app/views/recordings/list_owned.rhtml
+++ b/app/views/recordings/list_owned.rhtml
@@ -1,4 +1,4 @@
-<h1>Listing owned recordings</h1>
+<% @heading = "Listing owned recordings" %>
 
 <p>All recordings owned by <%= @owner.username %>.
 
diff --git a/app/views/recordings/new.rhtml b/app/views/recordings/new.rhtml
index 45b6338..60168aa 100644
--- a/app/views/recordings/new.rhtml
+++ b/app/views/recordings/new.rhtml
@@ -1,4 +1,4 @@
-<h1>New recording</h1>
+<% @heading = "New recording" %>
 
 <%= start_form_tag :action => 'create' %>
   <%= render :partial => 'form' %>
diff --git a/app/views/recordings/show.rhtml b/app/views/recordings/show.rhtml
index a77c280..610df99 100644
--- a/app/views/recordings/show.rhtml
+++ b/app/views/recordings/show.rhtml
@@ -1,3 +1,4 @@
+<% @heading = "Show recording" %>
 <% for column in Recording.content_columns %>
 <p>
   <b><%= column.human_name %>:</b> <%=h @recording.send(column.name) %>
diff --git a/app/views/users/edit.rhtml b/app/views/users/edit.rhtml
index b02e6f2..d782e2f 100644
--- a/app/views/users/edit.rhtml
+++ b/app/views/users/edit.rhtml
@@ -1,4 +1,4 @@
-<h1>Editing user</h1>
+<% @heading = "Editing user" %>
 
 <%= start_form_tag :action => 'update', :id => @user %>
   <%= render :partial => 'form' %>
diff --git a/app/views/users/list.rhtml b/app/views/users/list.rhtml
index be88e00..9871c78 100644
--- a/app/views/users/list.rhtml
+++ b/app/views/users/list.rhtml
@@ -1,4 +1,4 @@
-<h1>Listing users</h1>
+<% @heading = "Listing users" %>
 
 <table>
   <tr>
diff --git a/app/views/users/login.rhtml b/app/views/users/login.rhtml
index b71cdf8..bee1f51 100644
--- a/app/views/users/login.rhtml
+++ b/app/views/users/login.rhtml
@@ -1,4 +1,4 @@
-<h1>Login</h1>
+<% @heading = "Login" %>
 
 <p>Welcome!  Who are you?</p>
 
diff --git a/app/views/users/new.rhtml b/app/views/users/new.rhtml
index 3144e59..1f41174 100644
--- a/app/views/users/new.rhtml
+++ b/app/views/users/new.rhtml
@@ -1,4 +1,4 @@
-<h1>New user</h1>
+<% @heading = "New user" %>
 
 <%= start_form_tag :action => 'create' %>
   <%= render :partial => 'form' %>
diff --git a/app/views/users/show.rhtml b/app/views/users/show.rhtml
index 562ade0..393f12e 100644
--- a/app/views/users/show.rhtml
+++ b/app/views/users/show.rhtml
@@ -1,3 +1,4 @@
+<% @heading = "Show user" %>
 <% for column in User.content_columns %>
 <p>
   <b><%= column.human_name %>:</b> <%=h @user.send(column.name) %>
-- 
GitLab