Hello,
I am looking at adding address book 'quick search'/auto-complete functionality, amongst other enhancements, to the advanced_search plugin for the email relevant fields (To, From, etc). This will allow for quick and easy entry of email addresses that are in the address book.
Looking at the functionality in the compose, simply adding this JS snippit to the input seems to work:
<code> var ac_props; rcmail.init_address_input_events(row_input, ac_props); </code>
The problem being that this wraps the email address with "<>", prepends the display name and appends ", " to the data. Trying to just use this and filtering the email our with a regex in the backend is problematic due to the "<email>" being removed via the XSS HTML tag filtering protection. Disabling this is also not desirable.
What I would like is to have the same type of functionality but choosing only to place the email address in the field. I have done a little digging through the JS code but did not quickly find something that matched my requirements.
Can someone point me in the right direction or do I need to try to trace what is happening all through app.js.src. I would like to reuse as much of the core code as possible.
Regards,
Chris
Hello,
Well I did spend a bit of time following the function calls in app.js.src and that lead me to: program/steps/mail/autocomplete.inc
It looks like this search was not intended to be used outside of email composition, which is OK but does not fit this use case.
As a simple but inelegant workaround, a simple regex on the data seems to work:
rcmail.init_address_input_events(row_input, ""); row_input.blur(function() { row_input.val(function(e, val) { return val.replace(/.*<(\S*)>.*/, "$1"); }); });
Is there a better approach, that is obvious to anyone versed in this part of Rouncdube, to solve this in a cleaner fashion?
Regards,
Chris
On 19/02/13 14:02, Chris Moules wrote:
Hello,
I am looking at adding address book 'quick search'/auto-complete functionality, amongst other enhancements, to the advanced_search plugin for the email relevant fields (To, From, etc). This will allow for quick and easy entry of email addresses that are in the address book.
Looking at the functionality in the compose, simply adding this JS snippit to the input seems to work:
<code> var ac_props; rcmail.init_address_input_events(row_input, ac_props); </code>
The problem being that this wraps the email address with "<>", prepends the display name and appends ", " to the data. Trying to just use this and filtering the email our with a regex in the backend is problematic due to the "<email>" being removed via the XSS HTML tag filtering protection. Disabling this is also not desirable.
What I would like is to have the same type of functionality but choosing only to place the email address in the field. I have done a little digging through the JS code but did not quickly find something that matched my requirements.
Can someone point me in the right direction or do I need to try to trace what is happening all through app.js.src. I would like to reuse as much of the core code as possible.
Regards,
Chris
On Wed, Feb 20, 2013 at 10:04 AM, Chris Moules christopher@gms.lu wrote:
Hello,
Well I did spend a bit of time following the function calls in app.js.src and that lead me to: program/steps/mail/autocomplete.inc
It looks like this search was not intended to be used outside of email composition, which is OK but does not fit this use case.
As a simple but inelegant workaround, a simple regex on the data seems to work:
rcmail.init_address_input_events(row_input, ""); row_input.blur(function() { row_input.val(function(e, val) { return val.replace(/.*<(\S*)>.*/, "$1"); }); });
Is there a better approach, that is obvious to anyone versed in this part of Rouncdube, to solve this in a cleaner fashion?
We already use autocompletion in some plugins. For example in the ACL plugin: https://github.com/roundcube/roundcubemail/blob/master/plugins/acl/acl.js#L1... or in the Kolab calendar plugin: http://git.kolab.org/roundcubemail-plugins-kolab/tree/plugins/calendar/calen...
After initializing the input field with rcmail.init_address_input_events() you can catch the selected address using an event listener: rcmail.addEventListener('autocomplete_insert', function(e){ /* do something with e.insert */ });
However, you still have to post-process the value with some regex to fit the purpose of your plugin.
Regards, Thomas