From 861b01852ac49e70674093febd16d6366dd213b5 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Thu, 6 Dec 2007 22:37:32 +0000
Subject: [PATCH] Remember which comment tab the user is on between the viewing
 of different requests

---
 application/controllers/RequestController.php |  8 ++++++++
 application/views/request/view.xhtml          | 18 ++++++++++++------
 document_root/css/request/view.oss            | 10 +++++-----
 document_root/javascript/request/view.js      |  2 ++
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/application/controllers/RequestController.php b/application/controllers/RequestController.php
index 772c8c0f..f36e7dcd 100755
--- a/application/controllers/RequestController.php
+++ b/application/controllers/RequestController.php
@@ -261,6 +261,7 @@ class RequestController extends Nmc_Controller_Action
         }
 
         $view = new Application_View();
+        $view->selectedCommentTab = Nmc_Registry_Session::getInstance('comments')->selectedTab;
         $view->page = 'request/view';
         $view->request = $request;
         $view->currentGeneration = $currentGeneration;
@@ -276,6 +277,13 @@ class RequestController extends Nmc_Controller_Action
         $out->setBody($view->render('unlModernWrapper.xhtml'));
     }
 
+    public function setCommentTabAction()
+    {
+        $in = $this->getRequest();
+        $tab = $in->getParam(0);
+        Nmc_Registry_Session::getInstance('comments')->selectedTab = $tab;
+    }
+
     public function addCommentAction()
     {
         $in = $this->getRequest();
diff --git a/application/views/request/view.xhtml b/application/views/request/view.xhtml
index cc00dd0a..0769e0f1 100644
--- a/application/views/request/view.xhtml
+++ b/application/views/request/view.xhtml
@@ -120,15 +120,21 @@
     </form>
     <?php } else { ?>
 
+    <?php
+    if (!in_array($this->selectedCommentTab, array('commentsTab', 'editorsCommentsTab', 'privateCommentsTab'))) {
+        $this->selectedCommentTab = 'commentsTab';
+    }
+    ?>
+
     <div id="comments">
         <div class="tabBar">
-            <a href="#" id="commentsTab" class="selected">Comments</a>
-            <a href="#" id="editorCommentsTab">Editor Comments</a>
-            <a href="#" id="privateCommentsTab">Private Comments</a>
+            <a href="#" id="commentsTab"<?php if ($this->selectedCommentTab == 'commentsTab') { ?> class="selected"<?php } ?>>Comments</a>
+            <a href="#" id="editorCommentsTab"<?php if ($this->selectedCommentTab == 'editorCommentsTab') { ?> class="selected"<?php } ?>>Editor Comments</a>
+            <a href="#" id="privateCommentsTab"<?php if ($this->selectedCommentTab == 'privateCommentsTab') { ?> class="selected"<?php } ?>>Private Comments</a>
         </div>
 
 
-        <div class="tabContent" id="commentsContent">
+        <div class="tabContent<?php if ($this->selectedCommentTab == 'commentsTab') { ?> selected<?php } ?>" id="commentsContent">
             <table class="comments">
                 <tr>
                     <th class="who">Who</th>
@@ -155,7 +161,7 @@
         </div>
 
 
-        <div class="tabContent" id="editorCommentsContent">
+        <div class="tabContent<?php if ($this->selectedCommentTab == 'editorCommentsTab') { ?> selected<?php } ?>" id="editorCommentsContent">
             <table class="comments">
                 <tr>
                     <th class="who">Who</th>
@@ -182,7 +188,7 @@
         </div>
 
 
-        <div class="tabContent" id="privateCommentsContent">
+        <div class="tabContent<?php if ($this->selectedCommentTab == 'privateCommentsTab') { ?> selected<?php } ?>" id="privateCommentsContent">
             <table class="comments">
                 <tr>
                     <th class="who">Who</th>
diff --git a/document_root/css/request/view.oss b/document_root/css/request/view.oss
index 099f22d2..5c186abc 100644
--- a/document_root/css/request/view.oss
+++ b/document_root/css/request/view.oss
@@ -82,6 +82,7 @@ div#comments {
     }
 
     .tabContent {
+        display: none;
         clear: both;
         padding: 5px;
         background-color: #ddd;
@@ -93,6 +94,10 @@ div#comments {
         }
     }
 
+    .tabContent.selected {
+        display: block
+    }
+
     table.comments {
         width: 100%;
 
@@ -122,11 +127,6 @@ div#comments {
         }
 
     }
-
-    #editorCommentsContent,
-    #privateCommentsContent {
-        display: none;
-    }
 }
 
 #prevRequestLink {
diff --git a/document_root/javascript/request/view.js b/document_root/javascript/request/view.js
index f458b12d..1789a4e1 100644
--- a/document_root/javascript/request/view.js
+++ b/document_root/javascript/request/view.js
@@ -30,6 +30,8 @@ function viewRequestSelectTab()
     privateCommentsTab.className = '';
 
     this.className = 'selected';
+    var ajax = new AjaxClient();
+    ajax.sendRequest('/Request/SetCommentTab/' + this.id);
 
     if (this.id == 'commentsTab') {
         commentsContent.style.display = 'block';
-- 
GitLab