From 635fa701ffcd672b976939ead9278793d635a761 Mon Sep 17 00:00:00 2001 From: robert schouten Date: Thu, 16 Feb 2017 14:13:28 +0800 Subject: [PATCH] communication composer recipient lookup improvements --- frappe/email/__init__.py | 5 +-- .../public/js/frappe/views/communication.js | 33 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/frappe/email/__init__.py b/frappe/email/__init__.py index e911493de9..f8af08e6df 100644 --- a/frappe/email/__init__.py +++ b/frappe/email/__init__.py @@ -16,8 +16,9 @@ def get_contact_list(txt): return filter(None, frappe.db.sql_list('select email from tabUser where email like %s', ('%' + txt + '%'))) try: - out = filter(None, frappe.db.sql_list("""select email_id from `tabContact` - where `email_id` like %(txt)s order by + out = filter(None, frappe.db.sql_list("""select distinct email_id from `tabContact` + where email_id like %(txt)s or concat(first_name, " ", last_name) like %(txt)s order by + if (locate( %(_txt)s, concat(first_name, " ", last_name)), locate( %(_txt)s, concat(first_name, " ", last_name)), 99999), if (locate( %(_txt)s, email_id), locate( %(_txt)s, email_id), 99999)""", {'txt': "%%%s%%" % frappe.db.escape(txt), '_txt': txt.replace("%", "") diff --git a/frappe/public/js/frappe/views/communication.js b/frappe/public/js/frappe/views/communication.js index 40a204bde1..5d2e56566b 100755 --- a/frappe/public/js/frappe/views/communication.js +++ b/frappe/public/js/frappe/views/communication.js @@ -88,7 +88,7 @@ frappe.views.CommunicationComposer = Class.extend({ if(frappe.boot.email_accounts && frappe.boot.email_accounts.length > 1) { fields = [ {label: __("From"), fieldtype: "Select", reqd: 1, fieldname: "sender", - options: frappe.boot.email_accounts.map(function(d) { return e.email_id; }) } + options: frappe.boot.email_accounts.map(function(e) { return e.email_id; }) } ].concat(fields); } @@ -564,28 +564,29 @@ frappe.views.CommunicationComposer = Class.extend({ item: function(item, input) { return $('
  • ').text(item.value).get(0); }, - filter: function(text, input) { - return Awesomplete.FILTER_CONTAINS(text, input.match(/[^,]*$/)[0]); - }, + filter: function(text, input) { return true }, replace: function(text) { var before = this.input.value.match(/^.+,\s*|/)[0]; this.input.value = before + text + ", "; } }); - + var delay_timer; var $input = $(input); $input.on("input", function(e) { - var term = e.target.value; - frappe.call({ - method:'frappe.email.get_contact_list', - args: { - 'txt': extractLast(term) || '%' - }, - quiet: true, - callback: function(r) { - awesomplete.list = r.message; - } - }); + clearTimeout(delay_timer); + delay_timer = setTimeout(function() { + var term = e.target.value; + frappe.call({ + method:'frappe.email.get_contact_list', + args: { + 'txt': extractLast(term) || '%' + }, + quiet: true, + callback: function(r) { + awesomplete.list = r.message || []; + } + }); + },250); }); } });