Skip to content

Commit

Permalink
[mms] Do autocomplete search on browser, if sufficient data exists, t…
Browse files Browse the repository at this point in the history
…o save calls to contacts backend.
  • Loading branch information
slusarz committed Oct 14, 2014
1 parent 016f630 commit 0398e48
Show file tree
Hide file tree
Showing 6 changed files with 907 additions and 2 deletions.
2 changes: 2 additions & 0 deletions imp/docs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
v6.3.0-git
----------

[mms] Do autocomplete search on browser, if sufficient data exists, to save
calls to contacts backend.
[mms] Removed minimal view.
[mms] Allow auto-completed e-mail groups to be expanded on the dynamic compose
page.
Expand Down
10 changes: 9 additions & 1 deletion imp/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var IMP_Autocompleter = Class.create({
maxItemSize: 50,
minChars: 3,
onAdd: Prototype.emptyFunction,
onBeforeServerRequest: Prototype.emptyFunction,
onEntryClick: Prototype.emptyFunction,
onServerSuggestion: Prototype.emptyFunction,
processValueCallback: Prototype.emptyFunction,
Expand Down Expand Up @@ -366,11 +367,18 @@ var IMP_Autocompleter = Class.create({
return;
}

var c = this.cache.get(t);
var c = this.cache.get(t), tmp;

if (c) {
this.updateAutocomplete(t, c);
} else if (t.length >= this.p.minChars) {
tmp = this.p.onBeforeServerRequest(t, this.cache);
if (tmp) {
this.cache.set(t, tmp);
this.updateAutocomplete(t, tmp);
return;
}

DimpCore.doAction(
'autocompleteSearch',
Object.extend(this.p.autocompleterParams, { search: t }),
Expand Down
23 changes: 23 additions & 0 deletions imp/js/compose-dimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,28 @@ var DimpCompose = {
}, this);
},

autocompleteServerRequest: function(t, data)
{
var d, i, re;

for (i = t.length - 1; i > 0; --i) {
d = data.get(t.substr(0, i));
if (d) {
if (d.size() >= this.ac_limit) {
return false;
}

re = new RegExp(latinize(t), "i");

return d.findAll(function(a) {
return latinize(a.v).match(re);
});
}
}

return false;
},

autocompleteServerSuggestion: function(e, elt)
{
if (e.g) {
Expand Down Expand Up @@ -1320,6 +1342,7 @@ var DimpCompose = {
listClass: 'hordeACList impACList',
minChars: DimpCore.conf.ac_minchars,
onAdd: this.autocompleteOnAdd.bind(this),
onBeforeServerRequest: this.autocompleteServerRequest.bind(this),
onEntryClick: this.autocompleteOnEntryClick.bind(this),
onServerSuggestion: this.autocompleteServerSuggestion.bind(this),
processValueCallback: this.autocompleteValue.bind(this),
Expand Down

0 comments on commit 0398e48

Please sign in to comment.