From 0213f8d4dddf88b1a3eec91ff0f95832ebac3008 Mon Sep 17 00:00:00 2001 From: alecpl Date: Mon, 25 Jul 2011 10:49:39 +0000 Subject: - Added optional "multithreading" autocomplete feature --- program/js/app.js | 167 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 49 deletions(-) (limited to 'program/js/app.js') diff --git a/program/js/app.js b/program/js/app.js index 35136bf1a..0ec920b3a 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -2871,12 +2871,21 @@ function rcube_webmail() input_subject = $("input[name='_subject']"), input_message = $("[name='_message']").get(0), html_mode = $("input[name='_is_html']").val() == '1', - ac_fields = ['cc', 'bcc', 'replyto', 'followupto']; + ac_fields = ['cc', 'bcc', 'replyto', 'followupto'], + ac_props; + + // configure parallel autocompletion + if (this.env.autocomplete_threads > 0) { + ac_props = { + threads: this.env.autocomplete_threads, + sources: this.env.autocomplete_sources, + }; + } // init live search events - this.init_address_input_events(input_to); + this.init_address_input_events(input_to, ac_props); for (var i in ac_fields) { - this.init_address_input_events($("[name='_"+ac_fields[i]+"']")); + this.init_address_input_events($("[name='_"+ac_fields[i]+"']"), ac_props); } if (!html_mode) { @@ -2904,9 +2913,9 @@ function rcube_webmail() this.auto_save_start(); }; - this.init_address_input_events = function(obj, action) + this.init_address_input_events = function(obj, props) { - obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, action); }) + obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, props); }) .attr('autocomplete', 'off'); }; @@ -3441,7 +3450,7 @@ function rcube_webmail() /*********************************************************/ // handler for keyboard events on address-fields - this.ksearch_keydown = function(e, obj, action) + this.ksearch_keydown = function(e, obj, props) { if (this.ksearch_timer) clearTimeout(this.ksearch_timer); @@ -3471,8 +3480,8 @@ function rcube_webmail() if (mod == SHIFT_KEY) break; - case 13: // enter - if (this.ksearch_selected === null || !this.ksearch_input || !this.ksearch_value) + case 13: // enter + if (this.ksearch_selected === null || !this.ksearch_value) break; // insert selected address and hide ksearch pane @@ -3492,7 +3501,7 @@ function rcube_webmail() } // start timer - this.ksearch_timer = window.setTimeout(function(){ ref.ksearch_get_results(action); }, 200); + this.ksearch_timer = window.setTimeout(function(){ ref.ksearch_get_results(props); }, 200); this.ksearch_input = obj; return true; @@ -3522,11 +3531,12 @@ function rcube_webmail() p = inp_value.lastIndexOf(this.ksearch_value, cpos), trigger = false, insert = '', - // replace search string with full address pre = inp_value.substring(0, p), end = inp_value.substring(p+this.ksearch_value.length, inp_value.length); + this.ksearch_destroy(); + // insert all members of a group if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].id) { insert += this.env.contacts[id].name + ', '; @@ -3560,7 +3570,7 @@ function rcube_webmail() }; // address search processor - this.ksearch_get_results = function(action) + this.ksearch_get_results = function(props) { var inp_value = this.ksearch_input ? this.ksearch_input.value : null; @@ -3605,59 +3615,102 @@ function rcube_webmail() if (old_value && old_value.length && this.env.contacts && !this.env.contacts.length && q.indexOf(old_value) == 0) return; - var lock = this.display_message(this.get_label('searching'), 'loading'); - this.http_post(action ? action : 'mail/autocomplete', '_search='+urlencode(q), lock); + this.ksearch_destroy(); + + var i, lock, source, xhr, reqid = new Date().getTime(), + threads = props && props.threads ? props.threads : 1, + sources = props && props.sources ? props.sources : [], + action = props && props.action ? props.action : 'mail/autocomplete'; + + this.ksearch_data = {id: reqid, sources: sources.slice(), action: action, locks: [], requests: []}; + + for (i=0; i 1 && source === null) + break; + + lock = this.display_message(this.get_label('searching'), 'loading'); + xhr = this.http_post(action, '_search='+urlencode(q)+'&_id='+reqid + + (source ? '&_source='+urlencode(source) : ''), lock); + + this.ksearch_data.locks.push(lock); + this.ksearch_data.requests.push(xhr); + } }; - this.ksearch_query_results = function(results, search) + this.ksearch_query_results = function(results, search, reqid) { // ignore this outdated search response - if (this.ksearch_value && search != this.ksearch_value) + if (this.ksearch_input && this.ksearch_value && search != this.ksearch_value) return; - this.env.contacts = results ? results : []; - this.ksearch_display_results(this.env.contacts); - }; - - this.ksearch_display_results = function (a_results) - { // display search results - if (a_results.length && this.ksearch_input && this.ksearch_value) { - var p, ul, li, text, s_val = this.ksearch_value; - - // create results pane if not present - if (!this.ksearch_pane) { - ul = $('