From c49234bd78af8261ab687392f1fb7d69ec4963b9 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 09 Sep 2015 04:37:01 -0400
Subject: [PATCH] Fix bug where clicking date column with 'arrival' sorting would switch to sorting by 'date' (#1490126)

---
 CHANGELOG                   |    1 +
 program/steps/mail/func.inc |   15 +++++++++------
 program/js/app.js           |   12 +++++++++---
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 1810995..c429736 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -29,6 +29,7 @@
 - Plugin API: Added message_ready hook
 - Plugin API: Add special onload() method to execute plugin actions before startup (session and GUI initialization)
 - Implemented UI element to jump to specified page of the messages list (#1485235)
+- Fix bug where clicking date column with 'arrival' sorting would switch to sorting by 'date' (#1490126)
 - Fix bug where message content could overlap attachments list in Larry skin (#1490479)
 - Fix closing of nested menus (#1490443)
 - Fix so microseconds macro (u) in log_date_format works (#1490446)
diff --git a/program/js/app.js b/program/js/app.js
index 4b9f5d6..e2e3233 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -2175,10 +2175,16 @@
 
   this.set_list_sorting = function(sort_col, sort_order)
   {
+    var sort_old = this.env.sort_col == 'arrival' ? 'date' : this.env.sort_col,
+      sort_new = sort_col == 'arrival' ? 'date' : sort_col;
+
     // set table header class
-    $('#rcm'+this.env.sort_col).removeClass('sorted'+(this.env.sort_order.toUpperCase()));
-    if (sort_col)
-      $('#rcm'+sort_col).addClass('sorted'+sort_order);
+    $('#rcm' + sort_old).removeClass('sorted' + this.env.sort_order.toUpperCase());
+    if (sort_new)
+      $('#rcm' + sort_new).addClass('sorted' + sort_order);
+
+    // if sorting by 'arrival' is selected, click on date column should not switch to 'date'
+    $('#rcmdate > a').prop('rel', sort_col == 'arrival' ? 'arrival' : 'date');
 
     this.env.sort_col = sort_col;
     this.env.sort_order = sort_order;
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 3f8277c..909b870 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -453,6 +453,8 @@
         }
     }
 
+    $sort_col = $_SESSION['sort_col'];
+
     // loop through message headers
     foreach ($a_headers as $header) {
         if (empty($header))
@@ -483,7 +485,7 @@
             else if ($col == 'size')
                 $cont = $RCMAIL->show_bytes($header->$col);
             else if ($col == 'date')
-                $cont = $RCMAIL->format_date($header->date);
+                $cont = $RCMAIL->format_date($sort_col == 'arrival' ? $header->internaldate : $header->date);
             else if ($col == 'folder') {
                 if ($last_folder !== $header->folder) {
                     $last_folder      = $header->folder;
@@ -588,8 +590,9 @@
     }
 
     foreach ($a_show_cols as $col) {
-        $label = '';
+        $label    = '';
         $sortable = false;
+        $rel_col  = $col == 'date' && $sort_col == 'arrival' ? 'arrival' : $col;
 
         // get column name
         switch ($col) {
@@ -607,11 +610,11 @@
             $col_name = $list_menu;
             break;
         case 'fromto':
-            $label = $RCMAIL->gettext($smart_col);
+            $label    = $RCMAIL->gettext($smart_col);
             $col_name = rcube::Q($label);
             break;
         default:
-            $label = $RCMAIL->gettext($col);
+            $label    = $RCMAIL->gettext($col);
             $col_name = rcube::Q($label);
         }
 
@@ -621,7 +624,7 @@
             $col_name = html::a(array(
                     'href'  => "./#sort",
                     'class' => 'sortcol',
-                    'rel'   => $col,
+                    'rel'   => $rel_col,
                     'title' => $RCMAIL->gettext('sortby')
                 ), $col_name);
         }
@@ -629,7 +632,7 @@
             $col_name = '<span class="' . $col .'">' . $col_name . '</span>';
         }
 
-        $sort_class = $col == $sort_col && !$disabled_order ? " sorted$sort_order" : '';
+        $sort_class = $rel_col == $sort_col && !$disabled_order ? " sorted$sort_order" : '';
         $class_name = $col.$sort_class;
 
         // put it all together

--
Gitblit v1.9.1