Branch 'dev/new-foldernav' - 3 commits - plugins/calendar plugins/kolab_auth plugins/kolab_delegation plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Fri May 16 10:38:46 CEST 2014


 plugins/calendar/calendar.php                        |    4 ++
 plugins/calendar/drivers/kolab/kolab_driver.php      |    8 ++++
 plugins/kolab_auth/kolab_auth_ldap.php               |    6 ++-
 plugins/kolab_delegation/kolab_delegation_engine.php |    6 +--
 plugins/libkolab/js/folderlist.js                    |   31 +++++++++++++++++--
 plugins/libkolab/lib/kolab_storage.php               |   15 +++++++--
 6 files changed, 59 insertions(+), 11 deletions(-)

New commits:
commit 0fbfff3349d487eac1e5a379c23e1728340d408b
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Fri May 16 10:38:37 2014 +0200

    Limit the user search results and display message if list is truncated

diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index f910b2b..15c81f9 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -746,6 +746,10 @@ class calendar extends rcube_plugin
 
           $results[] = $cal;
         }
+        // report more results available
+        if ($this->driver->search_more_results)
+          $this->rc->output->show_message('autocompletemore', 'info');
+
         $this->rc->output->command('multi_thread_http_response', $results, get_input_value('_reqid', RCUBE_INPUT_GPC));
         return;
     }
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 8126339..8f1af0c 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -409,6 +409,7 @@ class kolab_driver extends calendar_driver
       return array();
 
     $this->calendars = array();
+    $this->search_more_results = false;
 
     // find unsubscribed IMAP folders that have "event" type
     if ($source == 'folders') {
@@ -419,7 +420,8 @@ class kolab_driver extends calendar_driver
     }
     // find other user's virtual calendars
     else if ($source == 'users') {
-      foreach (kolab_storage::search_users($query, 0) as $user) {
+      $limit = $this->rc->config->get('autocomplete_max', 15) * 2;  // we have slightly more space, so display twice the number
+      foreach (kolab_storage::search_users($query, 0, array(), $limit, $count) as $user) {
         $calendar = new kolab_user_calendar($user, $this->cal);
         $this->calendars[$calendar->id] = $calendar;
 
@@ -431,6 +433,10 @@ class kolab_driver extends calendar_driver
           }
         }
       }
+
+      if ($count > $limit) {
+        $this->search_more_results = true;
+      }
     }
 
     // don't list the birthday calendar


commit 7d5fe4c7942bb26b3c91353fbb19e71aea4320c4
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Fri May 16 10:36:57 2014 +0200

    Fix LDAP search calls and return the number of matches

diff --git a/plugins/libkolab/js/folderlist.js b/plugins/libkolab/js/folderlist.js
index 274d57f..00882a8 100644
--- a/plugins/libkolab/js/folderlist.js
+++ b/plugins/libkolab/js/folderlist.js
@@ -36,6 +36,7 @@ function kolab_folderlist(node, p)
     var search_results_widget;
     var search_results_container;
     var listsearch_request;
+    var search_messagebox;
 
     var Q = rcmail.quote_html;
 
@@ -164,8 +165,29 @@ function kolab_folderlist(node, p)
         }
         search_results = {};
 
+        if (search_messagebox)
+            rcmail.hide_message(search_messagebox);
+
         // send search request(s) to server
         if (search.query && search.execute) {
+            // require a minimum length for the search string
+            if (rcmail.env.autocomplete_min_length && search.query.length < rcmail.env.autocomplete_min_length) {
+                search_messagebox = rcmail.display_message(
+                    rcmail.get_label('autocompletechars').replace('$min', rcmail.env.autocomplete_min_length));
+                return;
+            }
+
+            if (listsearch_request) {
+                // ignore, let the currently runnung sequest finish
+                if (listsearch_request.query == search.query) {
+                    return;
+                }
+                else { // cancel previous search request
+                    rcmail.multi_thread_request_abort(listsearch_request.id);
+                    listsearch_request = null;
+                }
+            }
+
             var sources = p.search_sources || [ 'folders' ];
             var reqid = rcmail.multi_thread_http_request({
                 items: sources,
@@ -173,10 +195,15 @@ function kolab_folderlist(node, p)
                 action:  p.search_action || 'listsearch',
                 postdata: { action:'search', q:search.query, source:'%s' },
                 lock: rcmail.display_message(rcmail.get_label('searching'), 'loading'),
-                onresponse: render_search_results
+                onresponse: render_search_results,
+                whendone: function(e){ listsearch_request = null; }
             });
 
-            listsearch_request = { id:reqid, sources:sources.slice(), num:sources.length };
+            listsearch_request = { id:reqid, query:search.query };
+        }
+        else if (!search.query && listsearch_request) {
+            rcmail.multi_thread_request_abort(listsearch_request.id);
+            listsearch_request = null;
         }
     });
 
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index 1cbdd76..74c0ed3 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -1318,11 +1318,12 @@ class kolab_storage
      * @param mixed   $query    Search value (or array of field => value pairs)
      * @param int     $mode     Matching mode: 0 - partial (*abc*), 1 - strict (=), 2 - prefix (abc*)
      * @param array   $required List of fields that shall ot be empty
-     * @param int     $limit    Number of records
+     * @param int     $limit    Maximum number of records
+     * @param int     $count    Returns the number of records found
      *
      * @return array List or false on error
      */
-    public static function search_users($query, $mode = 1, $required = array(), $limit = 0)
+    public static function search_users($query, $mode = 1, $required = array(), $limit = 0, &$count = 0)
     {
         // requires a working LDAP setup
         if (!self::ldap()) {
@@ -1330,7 +1331,12 @@ class kolab_storage
         }
 
         // search users using the configured attributes
-        $results = self::$ldap->search(self::$config->get('kolab_users_search_attrib', array('cn','mail','alias')), $query, $mode, $required, $limit);
+        $results = self::$ldap->dosearch(self::$config->get('kolab_users_search_attrib', array('cn','mail','alias')), $query, $mode, $required, $limit, $count);
+
+        // exclude myself
+        if ($_SESSION['kolab_dn']) {
+            unset($results[$_SESSION['kolab_dn']]);
+        }
 
         // resolve to IMAP folder name
         $root = self::namespace_root('other');
@@ -1391,6 +1397,9 @@ class kolab_storage
             $path_len = count(explode($delimiter, $other_ns));
 
             foreach ((array)self::list_folders($other_ns, '*', '', $subscribed) as $foldername) {
+                if ($foldername == 'INBOX')  // skip INBOX which is added by default
+                    continue;
+
                 // truncate folder path to top-level folders of the 'other' namespace
                 $path = explode($delimiter, $foldername);
                 $foldername = join($delimiter, array_slice($path, 0, $path_len + 1));


commit 115c4c54b75791d80f7ab620003f89f4b12501fb
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Fri May 16 10:34:32 2014 +0200

    Rename kolab_auth_ldap::search() method because its signature doesn't match rcube_ldap_generic::search() and fails recursive calls in VLV search mode + add return parameter for results count

diff --git a/plugins/kolab_auth/kolab_auth_ldap.php b/plugins/kolab_auth/kolab_auth_ldap.php
index 7044ebf..40237ac 100644
--- a/plugins/kolab_auth/kolab_auth_ldap.php
+++ b/plugins/kolab_auth/kolab_auth_ldap.php
@@ -215,10 +215,11 @@ class kolab_auth_ldap extends rcube_ldap_generic
      *                          2 - prefix (abc*)
      * @param array   $required List of fields that cannot be empty
      * @param int     $limit    Number of records
+     * @param int     $count    Returns the number of records found
      *
      * @return array List or false on error
      */
-    function search($fields, $value, $mode=1, $required = array(), $limit = 0)
+    function dosearch($fields, $value, $mode=1, $required = array(), $limit = 0, &$count = 0)
     {
         if (empty($fields)) {
             return array();
@@ -295,7 +296,8 @@ class kolab_auth_ldap extends rcube_ldap_generic
         $attrs   = array_values($this->fieldmap);
         $list    = array();
 
-        if ($result = parent::search($base_dn, $filter, $scope, $attrs)) {
+        if ($result = $this->search($base_dn, $filter, $scope, $attrs)) {
+            $count = $result->count();
             $i = 0;
             foreach ($result as $entry) {
                 if ($limit && $limit <= $i) {
diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php
index ad96831..3d3bd33 100644
--- a/plugins/kolab_delegation/kolab_delegation_engine.php
+++ b/plugins/kolab_delegation/kolab_delegation_engine.php
@@ -202,7 +202,7 @@ class kolab_delegation_engine
             return array();
         }
 
-        $list = $ldap->search($this->ldap_login_field, $login, 1);
+        $list = $ldap->dosearch($this->ldap_login_field, $login, 1);
 
         if (count($list) == 1) {
             $dn   = key($list);
@@ -288,7 +288,7 @@ class kolab_delegation_engine
             return array();
         }
 
-        $list = $ldap->search($this->ldap_delegate_field, $this->ldap_dn, 1);
+        $list = $ldap->dosearch($this->ldap_delegate_field, $this->ldap_dn, 1);
 
         foreach ($list as $dn => $delegator) {
             $delegator = $this->parse_ldap_record($delegator, $dn);
@@ -424,7 +424,7 @@ class kolab_delegation_engine
         $fields = array_unique(array_filter(array_merge((array)$this->ldap_name_field, (array)$this->ldap_login_field)));
         $users  = array();
 
-        $result = $ldap->search($fields, $search, $mode, (array)$this->ldap_login_field, $max);
+        $result = $ldap->dosearch($fields, $search, $mode, (array)$this->ldap_login_field, $max);
 
         foreach ($result as $record) {
             // skip self




More information about the commits mailing list