From 363e51d676fcec5aca78696c0b805f1d46ebec7d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 15 Dec 2009 23:06:32 -0700 Subject: [PATCH] ViewPort data tweaks. 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 | 4 +++- imp/js/ViewPort.js | 31 ++++++++++++++++++++----------- imp/lib/Views/ListMessages.php | 29 ++++++++++++++++++++--------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/imp/ajax.php b/imp/ajax.php index 240930bdc..5c9ea699f 100644 --- a/imp/ajax.php +++ b/imp/ajax.php @@ -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'); diff --git a/imp/js/ViewPort.js b/imp/js/ViewPort.js index d4578d234..ada91ecab 100644 --- a/imp/js/ViewPort.js +++ b/imp/js/ViewPort.js @@ -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 @@ -120,7 +120,7 @@ * 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. * @@ -148,9 +148,11 @@ * 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); diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php index 76aa51539..99e7a0645 100644 --- a/imp/lib/Views/ListMessages.php +++ b/imp/lib/Views/ListMessages.php @@ -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. * -- 2.11.0