diff --git a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts index 7cfa29f54b..3ed9c52a20 100644 --- a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts +++ b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts @@ -18,7 +18,8 @@ import {cssImage} from "../../Et2Widget/Et2Widget"; */ export class Et2EmailTag extends Et2Tag { - private static email_cache : string[] = []; + + private static email_cache : { [address : string] : ContactInfo | false } = {}; static get styles() { @@ -47,11 +48,14 @@ export class Et2EmailTag extends Et2Tag background-image: ${cssImage("loading")}; } - .tag__prefix.contact_plus_add { + .tag__prefix.contact_plus_add, .tag__prefix.contact_plus_contact { width: 16px; background-image: ${cssImage("add")}; cursor: pointer; } + .tag__prefix.contact_plus_contact { + background-image: ${cssImage("contact")} + } `]; } @@ -77,6 +81,7 @@ export class Et2EmailTag extends Et2Tag this.handleMouseEnter = this.handleMouseEnter.bind(this); this.handleMouseLeave = this.handleMouseLeave.bind(this); this.handleClick = this.handleClick.bind(this); + this.handleContactClick = this.handleContactClick.bind(this); } connectedCallback() @@ -97,7 +102,7 @@ export class Et2EmailTag extends Et2Tag this.removeEventListener("mouseleave", this.handleMouseLeave); } - public checkContact(email : string) : Promise + public checkContact(email : string) : Promise { if(typeof Et2EmailTag.email_cache[email] !== "undefined") { @@ -131,16 +136,26 @@ export class Et2EmailTag extends Et2Tag /** * We either have a contact ID, or false. If false, show the add button. - * @param {boolean | number} data + * @param {false | ContactInfo} data */ - handleContactResponse(data : boolean | number) + handleContactResponse(data : false | ContactInfo) { if(data) { - return; + this._contactPlusNode.classList.add("contact_plus_contact"); + if(data.photo) + { + this._contactPlusNode.style.backgroundImage = "url(" + data.photo + ")"; + } + this._contactPlusNode.addEventListener("click", this.handleContactClick); + this.egw().tooltipBind(this._contactPlusNode, this.egw().lang("Open existing contact") + ":\n" + data.n_fn, false, {}); + } + else + { + this._contactPlusNode.classList.add("contact_plus_add"); + this._contactPlusNode.addEventListener("click", this.handleClick); + this.egw().tooltipBind(this._contactPlusNode, this.egw().lang("Add a new contact"), false, {}); } - this._contactPlusNode.classList.add("contact_plus_add"); - this._contactPlusNode.addEventListener("click", this.handleClick); } handleClick(e : MouseEvent) @@ -154,6 +169,18 @@ export class Et2EmailTag extends Et2Tag this.egw().open('', 'addressbook', 'add', extra); } + handleContactClick(e : MouseEvent) + { + e.stopPropagation(); + this.checkContact(this.value).then((result) => + { + this.egw().open((result).id, 'addressbook', 'view', { + title: (result).n_fn, + icon: (result).photo + }); + }); + } + /** * Get the node that is shown & clicked on to add email as contact * @@ -165,4 +192,10 @@ export class Et2EmailTag extends Et2Tag } } +interface ContactInfo +{ + id : number, + n_fn : string, + photo? : string +} customElements.define("et2-email-tag", Et2EmailTag); \ No newline at end of file diff --git a/api/src/Etemplate/Widget/Url.php b/api/src/Etemplate/Widget/Url.php index c6324ee8a9..f50375e9d8 100644 --- a/api/src/Etemplate/Widget/Url.php +++ b/api/src/Etemplate/Widget/Url.php @@ -152,14 +152,17 @@ class Url extends Etemplate\Widget /** * Handle ajax searches for existing contact based on email * - * @return boolean $_email exists or not + * @return Array|boolean Contact data of first match, or false if contact does not exist */ public static function ajax_contact($_email) { $email = \EGroupware\Api\Mail::stripRFC822Addresses(array($_email)); $response = \EGroupware\Api\Json\Response::get(); - $result = $GLOBALS['egw']->contacts->search(array('contact_email'=>$email[0], 'contact_email_home' => $email[0]), array('email','email_home'), - '', '', '', false, 'OR', false); - $response->data($result ? true : false); + $result = $GLOBALS['egw']->contacts->search( + array('contact_email' => $email[0], 'contact_email_home' => $email[0]), + array('contact_id', 'email', 'email_home', 'n_fn'), + '', '', '', false, 'OR', false + ); + $response->data($result ? $result[0] : false); } }