mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-27 00:58:55 +01:00
* Api - Check if email address is known before offering 'Add as contact' button
This commit is contained in:
parent
9c3882b4e8
commit
c67560049c
@ -354,49 +354,69 @@ 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();
|
||||
if(typeof et2_url_ro.email_cache[this.value] === 'undefined')
|
||||
{
|
||||
event.stopImmediatePropagation();
|
||||
var self = this;
|
||||
jQuery(this).tooltip({
|
||||
items: 'a.et2_email',
|
||||
position: {my:"right top", at:"left top", collision:"flipfit"},
|
||||
tooltipClass: "et2_email_popup",
|
||||
content: function()
|
||||
{
|
||||
// Here we could do all sorts of things
|
||||
var extra = {
|
||||
'presets[email]': jQuery(this).attr('title') ? jQuery(this).attr('title') : jQuery(this).text()
|
||||
};
|
||||
|
||||
return jQuery('<a href="#" class= "et2_url_email_contactPlus" title="'+egw.lang('Add a new contact')+'"><img src="'
|
||||
+egw.image("new") +'"/></a>')
|
||||
.on('click', function() {
|
||||
egw.open('','addressbook','add',extra);
|
||||
});
|
||||
},
|
||||
close: function( event, ui )
|
||||
{
|
||||
ui.tooltip.hover(
|
||||
function () {
|
||||
jQuery(this).stop(true).fadeTo(400, 1);
|
||||
//.fadeIn("slow"); // doesn't work because of stop()
|
||||
},
|
||||
function () {
|
||||
jQuery(this).fadeOut("400", function(){ jQuery(this).remove();});
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
.tooltip("open");
|
||||
// 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",
|
||||
content: function()
|
||||
{
|
||||
// Here we could do all sorts of things
|
||||
var extra = {
|
||||
'presets[email]': jQuery(this).attr('title') ? jQuery(this).attr('title') : jQuery(this).text()
|
||||
};
|
||||
|
||||
return jQuery('<a href="#" class= "et2_url_email_contactPlus" title="'+egw.lang('Add a new contact')+'"><img src="'
|
||||
+egw.image("new") +'"/></a>')
|
||||
.on('click', function() {
|
||||
egw.open('','addressbook','add',extra);
|
||||
});
|
||||
},
|
||||
close: function( event, ui )
|
||||
{
|
||||
ui.tooltip.hover(
|
||||
function () {
|
||||
jQuery(this).stop(true).fadeTo(400, 1);
|
||||
//.fadeIn("slow"); // doesn't work because of stop()
|
||||
},
|
||||
function () {
|
||||
jQuery(this).fadeOut("400", function(){ jQuery(this).remove();});
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
.tooltip("open");
|
||||
},
|
||||
|
||||
/**
|
||||
* Code for implementing et2_IDetachedDOM
|
||||
*
|
||||
@ -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"]);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user