ViewPort data tweaks.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 16 Dec 2009 06:06:32 +0000 (23:06 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 16 Dec 2009 19:45:58 +0000 (12:45 -0700)
Send some data only once per mailbox; other data needs to be sent every
request because the server status may change over the course of the
session.

imp/ajax.php
imp/js/ViewPort.js
imp/lib/Views/ListMessages.php

index 240930b..5c9ea69 100644 (file)
@@ -73,7 +73,9 @@ function _getListMessages($mbox, $change)
         'qsearch' => Horde_Util::getPost('qsearch'),
         'qsearchflag' => Horde_Util::getPost('qsearchflag'),
         'qsearchmbox' => Horde_Util::getPost('qsearchmbox'),
-        'qsearchflagnot' => Horde_Util::getPost('qsearchflagnot')
+        'qsearchflagnot' => Horde_Util::getPost('qsearchflagnot'),
+        'sortby' => Horde_Util::getPost('sortby'),
+        'sortdir' => Horde_Util::getPost('sortdir'),
     );
 
     $search = Horde_Util::getPost('search');
index d4578d2..ada91ec 100644 (file)
@@ -11,7 +11,7 @@
  * ajax_url: (string) The URL to send the viewport requests to.
  *           This URL should return its response in an object named
  *           'ViewPort' (other information can be returned in the response and
- *           will be ignored by the viewport object).
+ *           will be ignored by this class).
  * container: (Element/string) A DOM element/ID of the container that holds
  *            the viewport. This element should be empty and have no children.
  * onContent: (function) A function that takes 2 arguments - the data object
  *   cache: (string) The list of uids cached on the browser.
  *   cacheid: (string) A unique string that changes whenever the viewport
  *            list changes.
- *   initial: (integer) TODO
+ *   initial: (integer) This is the initial browser request for this view.
  *   requestid: (integer) A unique identifier for this AJAX request.
  *   view: (string) The view of the request.
  *
  *       the viewable rows. Keys are a unique ID (see also the 'rowlist'
  *       entry). Values are the data objects. Internal keys for these data
  *       objects must NOT begin with the string 'vp'.
- * label: (string) The label to use for the current view.
- * metadata [optional]: (object) TODO
- * rangelist: TODO
+ * label: (string) [REQUIRED when initial is true] The label to use for the
+ *        view.
+ * metadata [optional]: (object) Metadata for the view. Entries in buffer are
+ *                      updated with these entries (unless resetmd is set).
+ * rangelist [optional]: TODO
  * requestid: (string) The request ID sent in the outgoing AJAX request.
  * reset [optional]: (integer) If set, purges all cached data.
  * resetmd [optional]: (integer) If set, purges all user metadata.
@@ -567,9 +569,13 @@ var ViewPort = Class.create({
                 type = 'search';
                 value = opts.search;
                 params.set('search', Object.toJSON(value));
-            } else if (opts.initial) {
+            }
+
+            if (opts.initial) {
                 params.set('initial', 1);
-            } else {
+            }
+
+            if (opts.purge) {
                 b.resetRowlist();
             }
 
@@ -784,7 +790,7 @@ var ViewPort = Class.create({
         this.isbusy = true;
         this._clearWait();
 
-        var callback, offset,
+        var callback, offset, tmp,
             buffer = this._getBuffer(r.view),
             llist = buffer.getMetaData('llist') || $H();
 
@@ -792,12 +798,15 @@ var ViewPort = Class.create({
 
         llist.unset(r.requestid);
 
-        buffer.setMetaData({
+        tmp = {
             cacheid: r.cacheid,
-            label: r.label,
             llist: llist,
             total_rows: r.totalrows
-        }, true);
+        };
+        if (r.label) {
+            tmp.label = r.label;
+        }
+        buffer.setMetaData(tmp, true);
 
         this.opts.container.fire('ViewPort:cacheUpdate', r.view);
 
index 76aa515..99e7a06 100644 (file)
@@ -70,6 +70,8 @@ class IMP_Views_ListMessages
             if ($is_search) {
                 $GLOBALS['imp_search']->createSearchQuery($query, array($args['qsearchmbox']), array(), _("Search Results"), $mbox);
             }
+        } else {
+            $is_search = $GLOBALS['imp_search']->isSearchMbox($mbox);
         }
 
         /* Set the current time zone. */
@@ -94,25 +96,34 @@ class IMP_Views_ListMessages
         $result = $this->getBaseOb($mbox);
         $result->cacheid = $imp_mailbox->getCacheID();
         $result->totalrows = $msgcount;
+        if (!$args['initial']) {
+            unset($result->label);
+        }
 
         /* Mail-specific viewport information. */
         $md = &$result->metadata;
         if (!IMP::threadSortAvailable($mbox)) {
             $md->nothread = 1;
         }
-        $md->sortby = intval($sortpref['by']);
-        $md->sortdir = intval($sortpref['dir']);
-        if ($sortpref['limit']) {
-            $md->sortlimit = 1;
+        if ($args['initial'] || !is_null($args['sortby'])) {
+            $md->sortby = intval($sortpref['by']);
+        }
+        if ($args['initial'] || !is_null($args['sortdir'])) {
+            $md->sortdir = intval($sortpref['dir']);
         }
-        if (IMP::isSpecialFolder($mbox)) {
+        if ($args['initial'] && IMP::isSpecialFolder($mbox)) {
             $md->special = 1;
         }
-        if ($is_search || $GLOBALS['imp_search']->isSearchMbox($mbox)) {
+        if ($args['initial'] && $is_search) {
             $md->search = 1;
         }
-        if ($GLOBALS['imp_imap']->isReadOnly($mbox)) {
-            $md->readonly = 1;
+
+        /* These entries may change during a session, so always need to
+         * update them. */
+        $md->readonly = intval($GLOBALS['imp_imap']->isReadOnly($mbox));
+        if (!$is_search &&
+            !empty($GLOBALS['conf']['server']['sort_limit'])) {
+            $md->sortlimit = $sortpref['limit'] ? 1 : 0;
         }
 
         /* Check for mailbox existence now. If there are no messages, there
@@ -363,7 +374,7 @@ class IMP_Views_ListMessages
     }
 
     /**
-     * Prepare the base object used by the ViewPort javascript object.
+     * Prepare the base object used by the ViewPort javascript class.
      *
      * @param string $mbox  The mailbox name.
      *