Skip to content

Commit

Permalink
Simplify autocompletion
Browse files Browse the repository at this point in the history
At this point, there is little/no advantage to pre-loading the contact
list, since AJAX calls are so light.
  • Loading branch information
slusarz committed Oct 8, 2013
1 parent 432a98c commit 9a08f7e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 59 deletions.
7 changes: 0 additions & 7 deletions imp/config/conf.xml
Expand Up @@ -67,13 +67,6 @@
no limit.">200000</configinteger>

<configheader>Address Autocompletion</configheader>
<configinteger name="ac_browser" desc="For autocompletion of addresses,
the maximum number of entries present in the user's addressbook before the
queries will be handled by the server. For addressbooks with less than this
value, the entire addressbook will be transmitted to the browser in the
compose page. The latter results in faster lookups, but requires additional
processing when generating the compose page. Set to 0 to
disable.">50</configinteger>
<configinteger name="ac_threshold" desc="When autocompleting addresses on
the compose screen, the minimum number of characters required before the
the addressbook is searched.">3</configinteger>
Expand Down
4 changes: 4 additions & 0 deletions imp/docs/UPGRADING
Expand Up @@ -40,6 +40,10 @@ The following options have been added::
$conf['compose']['link_attach_size_hard']
$conf['contactsimage']['backends']

The following options have been removed::

$conf['compose']['ac_threshold']



Upgrading IMP From 6.1.x To 6.1.4
Expand Down
56 changes: 5 additions & 51 deletions imp/lib/Ajax/Imple/ContactAutoCompleter.php
Expand Up @@ -23,60 +23,14 @@
class IMP_Ajax_Imple_ContactAutoCompleter extends Horde_Core_Ajax_Imple_ContactAutoCompleter
{
/**
* Has the address book been output to the browser?
*
* @var boolean
*/
static protected $_listOutput = false;

/**
*/
protected function _getAutoCompleter()
protected function _getAutoCompleterParams()
{
global $conf, $page_output, $session;

$ac_browser = empty($conf['compose']['ac_browser'])
? 0
: $conf['compose']['ac_browser'];
$params = $this->_getAutoCompleterParams();

if ($ac_browser && !$session->get('imp', 'ac_ajax')) {
$have_fields = $use_ajax = true;
$sparams = $this->_getAddressbookSearchParams();
foreach ($sparams->fields as $val) {
array_map('strtolower', $val);
sort($val);
if ($val != array('email', 'name')) {
$have_fields = false;
break;
}
}
if ($have_fields) {
$addrlist_count = $this->getAddressList('', array('count_only' => true));
$use_ajax = $addrlist_count > $ac_browser;
}
$session->set('imp', 'ac_ajax', $use_ajax);
}

if (!$ac_browser || $session->get('imp', 'ac_ajax')) {
$params['minChars'] = intval($conf['compose']['ac_threshold'])
? $conf['compose']['ac_threshold']
: 1;
return new Horde_Core_Ajax_Imple_AutoCompleter_Ajax($params);
}

if (!self::$_listOutput) {
$addrlist = array();
foreach ($this->getAddressList() as $address) {
$addrlist[] = strval($address);
}
$page_output->addInlineJsVars(array(
'IMP_ac_list' => $addrlist
));
self::$_listOutput = true;
}
global $conf;

return new Horde_Core_Ajax_Imple_AutoCompleter_Local('IMP_ac_list', $params);
return array_merge(parent::_getAutoCompleterParams(), array(
'minChars' => intval($conf['compose']['ac_threshold']) ?: 1
));
}

/**
Expand Down
1 change: 0 additions & 1 deletion imp/lib/Prefs/Special/Sourceselect.php
Expand Up @@ -50,7 +50,6 @@ public function update(Horde_Core_Prefs_Ui $ui)

if (isset($data['sources'])) {
$prefs->setValue('search_sources', $data['sources']);
$session->remove('imp', 'ac_ajax');
$updated = true;
}

Expand Down

0 comments on commit 9a08f7e

Please sign in to comment.