* Api - Check if email address is known before offering 'Add as contact' button

This commit is contained in:
nathangray 2018-02-08 13:19:26 -07:00
parent 9c3882b4e8
commit c67560049c
2 changed files with 69 additions and 36 deletions

View File

@ -354,12 +354,37 @@ var et2_url_ro = (function(){ "use strict"; return et2_valueWidget.extend([et2_I
if(!egw.app('addressbook')) return;
// Bind onmouseenter event on <a> tag in order to add contact plus
this.span.on ({
mouseenter: function (event)
{
this.span.on ('mouseenter', jQuery.proxy(function (event) {
event.stopImmediatePropagation();
var self = this;
jQuery(this).tooltip({
if(typeof et2_url_ro.email_cache[this.value] === 'undefined')
{
// Ask server if we know this email
this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Url::ajax_contact',
this.value, this._add_contact_tooltip, this
);
}
else
{
this._add_contact_tooltip(et2_url_ro.email_cache[this.value]);
}
},this));
}
break;
}
},
/**
* Add a button to add the email address as a contact
*
* @param {boolean} email_exists True, or else nothing happens
*/
_add_contact_tooltip: function(email_exists)
{
et2_url_ro.email_cache[this.value] = email_exists;
if(email_exists) return;
this.span.tooltip({
items: 'a.et2_email',
position: {my:"right top", at:"left top", collision:"flipfit"},
tooltipClass: "et2_email_popup",
@ -390,11 +415,6 @@ var et2_url_ro = (function(){ "use strict"; return et2_valueWidget.extend([et2_I
}
})
.tooltip("open");
}
});
}
break;
}
},
/**
@ -429,4 +449,5 @@ var et2_url_ro = (function(){ "use strict"; return et2_valueWidget.extend([et2_I
this.span.attr('title',_values.statustext ? _values.statustext : this.options.statustext);
}
});}).call(this);
et2_url_ro.email_cache = [];
et2_register_widget(et2_url_ro, ["url_ro", "url-email_ro", "url-phone_ro"]);

View File

@ -128,4 +128,16 @@ class Url extends Etemplate\Widget
//error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value));
}
}
/**
* Handle ajax searches for existing contact based on email
*
* @return boolean email exists or not
*/
public static function ajax_contact($email)
{
$result = $GLOBALS['egw']->contacts->search($email);
\EGroupware\Api\Json\Response::data($result ? true : false);
}
}