- simplified code for serverside autocomplete + set rows limit on server side only

release-0.6
alecpl 16 years ago
parent 8b961eef04
commit 80e2278594

@ -2543,22 +2543,13 @@ function rcube_webmail()
this.hide_message(); this.hide_message();
this.env.contacts = results ? results : []; this.env.contacts = results ? results : [];
this.ksearch_display_results(this.env.contacts);
var result_ids = new Array();
var c=0;
for (var i=0; i < this.env.contacts.length; i++) {
result_ids[c++] = i;
if (c == 15) // limit search results
break;
}
this.ksearch_display_results(this.env.contacts, result_ids, c);
}; };
this.ksearch_display_results = function (a_results, a_result_ids, c) this.ksearch_display_results = function (a_results)
{ {
// display search results // display search results
if (c && a_results.length && this.ksearch_input) { if (a_results.length && this.ksearch_input) {
var p, ul, li; var p, ul, li;
// create results pane if not present // create results pane if not present
@ -2580,27 +2571,14 @@ function rcube_webmail()
li.innerHTML = a_results[i].replace(new RegExp('('+this.ksearch_value+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>'); li.innerHTML = a_results[i].replace(new RegExp('('+this.ksearch_value+')', 'ig'), '##$1%%').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/##([^%]+)%%/g, '<b>$1</b>');
li.onmouseover = function(){ ref.ksearch_select(this); }; li.onmouseover = function(){ ref.ksearch_select(this); };
li.onmouseup = function(){ ref.ksearch_click(this) }; li.onmouseup = function(){ ref.ksearch_click(this) };
li._rcm_id = a_result_ids[i]; li._rcm_id = i;
ul.appendChild(li); ul.appendChild(li);
} }
// check if last selected item is still in result list // select the first
if (this.ksearch_selected !== null) { ul.firstChild.setAttribute('id', 'rcmksearchSelected');
p = find_in_array(this.ksearch_selected, a_result_ids); this.set_classname(ul.firstChild, 'selected', true);
if (p >= 0 && ul.childNodes) { this.ksearch_selected = 0;
ul.childNodes[p].setAttribute('id', 'rcmksearchSelected');
this.set_classname(ul.childNodes[p], 'selected', true);
}
else
this.ksearch_selected = null;
}
// if no item selected, select the first one
if (this.ksearch_selected === null) {
ul.firstChild.setAttribute('id', 'rcmksearchSelected');
this.set_classname(ul.firstChild, 'selected', true);
this.ksearch_selected = a_result_ids[0];
}
// move the results pane right under the input box and make it visible // move the results pane right under the input box and make it visible
var pos = rcube_get_object_pos(this.ksearch_input); var pos = rcube_get_object_pos(this.ksearch_input);

@ -19,7 +19,7 @@
*/ */
$MAXNUM = 15; // same limit as in app.js $MAXNUM = 15;
$contacts = array(); $contacts = array();
$book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql'); $book_types = (array) $RCMAIL->config->get('autocomplete_addressbooks', 'sql');
@ -33,12 +33,11 @@ if ($book_types && $search = get_input_value('_search', RCUBE_INPUT_POST)) {
while ($sql_arr = $result->iterate()) { while ($sql_arr = $result->iterate()) {
if (stripos((string)$sql_arr['email'], $search) !== false || stripos((string)$sql_arr['name'], $search) !== false) { if (stripos((string)$sql_arr['email'], $search) !== false || stripos((string)$sql_arr['name'], $search) !== false) {
$contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']); $contacts[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
if (count($contacts) >= $MAXNUM)
break 2;
} }
} }
} }
if (count($contacts) >= $MAXNUM)
break;
} }
sort($contacts); sort($contacts);

Loading…
Cancel
Save