Skip to content

Commit

Permalink
Support separate short display for keeping autocomplete box more tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Oct 2, 2014
1 parent 8ebd75a commit f65cc7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions imp/js/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var IMP_Autocompleter = Class.create({

this.input.up('LI').insert({ before:
v.elt
.insert(v.label.truncate(this.p.maxItemSize).escapeHTML())
.insert(v.short_d.truncate(this.p.maxItemSize).escapeHTML())
.insert(this.deleteImg().clone(true).show())
.store('itemid', v.id)
});
Expand Down Expand Up @@ -354,7 +354,7 @@ var IMP_Autocompleter = Class.create({
}

r.each(function(e) {
obs.push(new IMP_Autocompleter_Elt(e.v, e.l));
obs.push(new IMP_Autocompleter_Elt(e.v, e.l, e.s));
});

obs = this.filterChoices(obs);
Expand Down Expand Up @@ -404,12 +404,14 @@ IMP_Autocompleter_Elt = Class.create({
// elt,
// id,
// label,
// short_d,
// value,

initialize: function(value, label)
initialize: function(value, label, short_d)
{
this.value = value;
this.label = label || value;
this.short_d = short_d || value;
}

});
14 changes: 12 additions & 2 deletions imp/lib/Ajax/Application/Handler/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,10 @@ public function mailboxSize()
* - type: (string) Autocomplete search type.
*
* @return object An object with the following properties:
* - results: (array)
* - results: (array) Array with the following keys for each result:
* - l: (string) Full label.
* - s: (string) Short display string.
* - v: (string) Value.
*/
public function autocompleteSearch()
{
Expand All @@ -1293,11 +1296,18 @@ public function autocompleteSearch()
);

foreach ($addr as $val) {
$l = $val->writeAddress(array('noquote' => true));
$tmp = array('v' => strval($val));

$l = $val->writeAddress(array('noquote' => true));
if ($l !== $tmp['v']) {
$tmp['l'] = $l;
}

$s = $val->label;
if ($s !== $tmp['v']) {
$tmp['s'] = $s;
}

$out->results[] = $tmp;
}
break;
Expand Down

0 comments on commit f65cc7d

Please sign in to comment.