Skip to content

Commit

Permalink
Autocompleter is now handled via regular AJAX calls, and wholly withi…
Browse files Browse the repository at this point in the history
…n IMP

There are several improvements coming to IMP autocompleter, which is
going to require object return to the browser (currently, we return
e-mail strings). No need to touch the Horde code.

Basic view autocomplete no longer will work in git master.

Also, Imples need to die in general.
  • Loading branch information
slusarz committed Jul 28, 2014
1 parent b7a4b47 commit ecd7a91
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 204 deletions.
12 changes: 3 additions & 9 deletions imp/js/compose-base.js
Expand Up @@ -9,6 +9,7 @@
var ImpComposeBase = {

// Vars defaulting to null: editor_on, identities, rte_sig
ac: $H(),

getSpellChecker: function()
{
Expand Down Expand Up @@ -160,16 +161,9 @@ var ImpComposeBase = {
return val;
},

autocompleteHandlers: function()
{
var handlers = {};
$(document).fire('AutoComplete:handlers', handlers);
return $H(handlers);
},

autocompleteProcess: function(r)
{
this.autocompleteHandlers().each(function(pair) {
this.ac.each(function(pair) {
var ob = $H(pair.value.toObject(true));
ob.values().each(function(v) {
v.className = pair.value.p.listClassItem;
Expand All @@ -189,7 +183,7 @@ var ImpComposeBase = {
params = $H(params);

if (ac) {
this.autocompleteHandlers().each(function(pair) {
this.ac.each(function(pair) {
$H(pair.value.toObject()).each(function(pair2) {
out.push({
addr: pair2.value,
Expand Down
20 changes: 20 additions & 0 deletions imp/js/compose-dimp.js
Expand Up @@ -1378,6 +1378,26 @@ var DimpCompose = {

onDomLoad: function()
{
/* Initialize autocompleters. */
$('to', 'cc', 'bcc', 'redirect_to').compact().each(function(a) {
ImpComposeBase.ac.set(
a.identify(),
new IMP_PrettyAutocompleter(a.identify(), {
boxClass: 'hordeACBox impACBox',
boxClassFocus: 'impACBoxFocus',
deleteIcon: DimpCore.conf.ac_delete,
displayFilter: function(t) { return t.sub(/<[^>]*>$/, "").strip().escapeHTML(); },
growingInputClass: 'hordeACTrigger impACTrigger',
listClass: 'hordeACList impACList',
minChars: DimpCore.conf.ac_minchars,
processValueCallback: ImpComposeBase.autocompleteValue.bind(ImpComposeBase),
removeClass: 'hordeACItemRemove impACItemRemove',
trigger: a.identify(),
triggerContainer: Math.random().toString()
})
);
});

/* Initialize redirect elements. */
if (DimpCore.conf.redirect) {
$('redirect').observe('submit', Event.stop);
Expand Down
48 changes: 38 additions & 10 deletions imp/js/prettyautocomplete.js
Expand Up @@ -4,7 +4,6 @@
*
* Events handled by this class:
* - AutoComplete:focus
* - AutoComplete:handlers
* - AutoComplete:reset
* - AutoComplete:update
*
Expand Down Expand Up @@ -40,7 +39,7 @@ var IMP_PrettyAutocompleter = Class.create({
listClassItem: 'hordeACListItem',
// input (created below)
// CSS class for real input field
growingInputClass: 'hordeACTrigger impACTrigger',
growingInputClass: 'hordeACTrigger',
removeClass: 'hordeACItemRemove',
// Allow for a function that filters the display value
// This function should *always* return escaped HTML
Expand Down Expand Up @@ -94,14 +93,11 @@ var IMP_PrettyAutocompleter = Class.create({
new PeriodicalExecuter(this.inputWatcher.bind(this), 0.25);

p_clone = $H(this.p).toObject();
p_clone.input = this.input;
p_clone.onSelect = this.updateElement.bind(this);
p_clone.paramName = this.elt.readAttribute('name');
p_clone.tokens = [];

ac = new Ajax.Autocompleter(this.input, this.p.uri, p_clone);
ac.getToken = function() {
return $F(this.input);
}.bind(this);
ac = new Ajax.IMP_Autocompleter(this.input, p_clone);

this.reset();

Expand All @@ -111,9 +107,6 @@ var IMP_PrettyAutocompleter = Class.create({
e.stop();
}
}.bindAsEventListener(this));
document.observe('AutoComplete:handlers', function(e) {
e.memo[this.elt.identify()] = this;
}.bind(this));
document.observe('AutoComplete:reset', this.reset.bind(this));
document.observe('AutoComplete:update', this.processInput.bind(this));
},
Expand Down Expand Up @@ -341,3 +334,38 @@ var IMP_PrettyAutocompleter = Class.create({
}

});

Ajax.IMP_Autocompleter = Class.create(Autocompleter.Base, {

initialize: function(element, opts)
{
this.baseInitialize(element, opts);
this.cache = $H();
},

getToken: function()
{
return $F(this.opts.input);
},

getUpdatedChoices: function(t)
{
var c = this.cache.get(t);

if (c) {
this.updateChoices(c);
} else {
DimpCore.doAction('autocompleteSearch', {
search: t
}, {
callback: this._onComplete.bind(this)
});
}
},

_onComplete: function(request)
{
this.updateChoices(this.cache.set(this.getToken(), request));
}

});
14 changes: 14 additions & 0 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Expand Up @@ -1285,4 +1285,18 @@ public function mailboxSize()
return $ret;
}

/**
* TODO
*/
public function autocompleteSearch()
{
return array_map(
'strval',
$GLOBALS['injector']->getInstance('IMP_Contacts')->searchEmail(
$this->vars->search,
array('levenshtein' => true)
)->base_addresses
);
}

}
9 changes: 7 additions & 2 deletions imp/lib/Ajax/Application/Handler/Smartmobile.php
Expand Up @@ -54,8 +54,13 @@ public function __construct(Horde_Core_Ajax_Application $base)
*/
public function smartmobileAutocomplete()
{
$imple = new IMP_Ajax_Imple_ContactAutoCompleter();
return array_map('htmlspecialchars', $imple->getAddressList($this->vars->search)->base_addresses);
return array_map(
'htmlspecialchars',
$GLOBALS['injector']->getInstance('IMP_Contacts')->searchEmail(
$this->vars->search,
array('levenshtein' => true)
)->base_addresses
);
}

/**
Expand Down
82 changes: 0 additions & 82 deletions imp/lib/Ajax/Imple/AutoCompleter/Pretty.php

This file was deleted.

58 changes: 0 additions & 58 deletions imp/lib/Ajax/Imple/ContactAutoCompleter.php

This file was deleted.

7 changes: 2 additions & 5 deletions imp/lib/Basic/Compose.php
Expand Up @@ -616,11 +616,8 @@ protected function _init()
/* Get the message cache ID. */
$composeCacheID = filter_var($imp_compose->getCacheId(), FILTER_SANITIZE_STRING);

/* Attach autocompleters to the compose form elements. */
if ($redirect) {
$imp_ui->attachAutoCompleter(array('to'));
} else {
$imp_ui->attachAutoCompleter(array('to', 'cc', 'bcc'));
$page_output->addScriptPackage('IMP_Script_Package_ContactAutocomplete');
if (!$redirect) {
$spellcheck = $imp_ui->attachSpellChecker();
$page_output->addScriptFile('ieescguard.js', 'horde');
}
Expand Down
20 changes: 0 additions & 20 deletions imp/lib/Compose/Ui.php
Expand Up @@ -29,26 +29,6 @@ class IMP_Compose_Ui
*/
protected $_spellInit = false;

/**
* Attach the auto-completer to the current compose form.
*
* @param array $fields The list of DOM IDs to attach the autocompleter
* to.
*/
public function attachAutoCompleter($fields)
{
/* Attach autocompleters to the compose form elements. */
if ($GLOBALS['registry']->hasMethod('contacts/search')) {
foreach ($fields as $val) {
$GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')
->create(
'IMP_Ajax_Imple_ContactAutoCompleter',
array('id' => $val)
);
}
}
}

/**
* Attach the spellchecker to the current compose form.
*
Expand Down

0 comments on commit ecd7a91

Please sign in to comment.