2011-08-26 00:42:07 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS URL object
|
2011-08-26 00:42:07 +02:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
et2_textbox;
|
|
|
|
et2_valueWidget;
|
2011-08-29 23:15:53 +02:00
|
|
|
phpgwapi.jquery.jquery.base64;
|
2011-08-26 00:42:07 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "url" XET-Tag, which covers URLs, email & phone
|
2014-01-10 17:19:05 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_textbox
|
2014-01-10 17:19:05 +01:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_url = (function(){ "use strict"; return et2_textbox.extend(
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2011-08-26 00:42:07 +02:00
|
|
|
attributes: {
|
|
|
|
"multiline": {
|
|
|
|
"ignore": true
|
|
|
|
}
|
|
|
|
},
|
2014-01-10 17:19:05 +01:00
|
|
|
|
2014-01-16 19:10:06 +01:00
|
|
|
/**
|
|
|
|
* Regexes for validating email addresses incl. email in angle-brackets eg.
|
|
|
|
* + "Ralf Becker <rb@stylite.de>"
|
|
|
|
* + "Ralf Becker (Stylite AG) <rb@stylite.de>"
|
|
|
|
* + "<rb@stylite.de>" or "rb@stylite.de"
|
|
|
|
* + '"Becker, Ralf" <rb@stylite.de>'
|
|
|
|
* + "'Becker, Ralf' <rb@stylite.de>"
|
|
|
|
* but NOT:
|
|
|
|
* - "Becker, Ralf <rb@stylite.de>" (contains comma outside " or ' enclosed block)
|
|
|
|
* - "Becker < Ralf <rb@stylite.de>" (contains < ----------- " ---------------)
|
|
|
|
*
|
|
|
|
* About umlaut or IDN domains: we currently only allow German umlauts in domain part!
|
|
|
|
*
|
|
|
|
* Using \042 instead of " to NOT stall minifyer!
|
|
|
|
*
|
2016-03-19 17:16:59 +01:00
|
|
|
* Same preg is in Etemplate\Widget\Url PHP class!
|
2014-01-16 19:10:06 +01:00
|
|
|
*/
|
2014-10-30 14:20:04 +01:00
|
|
|
EMAIL_PREG: new RegExp(/^(([^\042',<][^,<]+|\042[^\042]+\042|\'[^\']+\'|)\s?<)?[^\x00-\x20()<>@,;:\042\[\]]+@([a-z0-9ÄÖÜäöüß](|[a-z0-9ÄÖÜäöüß_-]*[a-z0-9ÄÖÜäöüß])\.)+[a-z]{2,}>?$/i),
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* @memberOf et2_url
|
|
|
|
*/
|
2011-08-26 00:42:07 +02:00
|
|
|
createInputWidget: function() {
|
|
|
|
this.input = $j(document.createElement("input"))
|
|
|
|
.blur(this,this.validate)
|
|
|
|
.blur(this,function(e){e.data.set_value(e.data.getValue());});
|
|
|
|
|
|
|
|
this._button = null;
|
|
|
|
|
|
|
|
if(this.size) {
|
|
|
|
this.set_size(this.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setDOMNode(this.input[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
|
|
|
if(this.input) {
|
|
|
|
this.input.unbind();
|
|
|
|
}
|
|
|
|
this._button = null;
|
2013-07-20 19:20:55 +02:00
|
|
|
this._super.apply(this);
|
2011-08-26 00:42:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override parent to update href of 'button'
|
2014-01-27 10:48:43 +01:00
|
|
|
*
|
|
|
|
* @param _value value to set
|
2011-08-26 00:42:07 +02:00
|
|
|
*/
|
|
|
|
set_value: function(_value) {
|
|
|
|
this.update_button(_value);
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
update_button: function(_value) {
|
|
|
|
if(this.value == _value) return;
|
|
|
|
if(_value)
|
|
|
|
{
|
|
|
|
// Create button if it doesn't exist yet
|
|
|
|
if(this._button == null)
|
|
|
|
{
|
|
|
|
this._button = $j(document.createElement("a")).addClass("et2_url");
|
2013-10-11 16:35:13 +02:00
|
|
|
this.getSurroundings().insertDOMNode(this._button[0]);
|
2011-08-26 00:42:07 +02:00
|
|
|
this.getSurroundings().update();
|
|
|
|
}
|
|
|
|
this._button.removeClass("url phone email").removeAttr("href");
|
2011-08-29 23:15:53 +02:00
|
|
|
_value = this.get_link(this._type, _value);
|
2011-08-26 00:42:07 +02:00
|
|
|
switch(this._type)
|
|
|
|
{
|
|
|
|
case "url":
|
|
|
|
// Silently use http if no protocol
|
|
|
|
this._button.attr("href", _value).attr("target", "_blank").addClass("url");
|
|
|
|
break;
|
|
|
|
case "url-phone":
|
2011-08-29 23:15:53 +02:00
|
|
|
if(_value) {
|
|
|
|
if(typeof _value == 'function')
|
|
|
|
{
|
|
|
|
this._button.click(this, _value).addClass("phone").show();
|
|
|
|
}
|
2014-01-10 17:19:05 +01:00
|
|
|
else
|
2011-08-29 23:15:53 +02:00
|
|
|
{
|
|
|
|
this._button.attr("href", _value).addClass("phone").show();
|
|
|
|
}
|
|
|
|
} else if (_value === false) {
|
2011-08-26 00:42:07 +02:00
|
|
|
// Can't make a good handler, hide button
|
|
|
|
this._button.hide();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "url-email":
|
2011-08-29 23:15:53 +02:00
|
|
|
if(typeof _value == 'function')
|
2011-08-26 00:42:07 +02:00
|
|
|
{
|
2011-08-29 23:15:53 +02:00
|
|
|
this._button.click(this, _value).addClass("email");
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
2011-08-29 23:15:53 +02:00
|
|
|
else
|
2011-08-26 00:42:07 +02:00
|
|
|
{
|
|
|
|
this._button.attr("href", _value).addClass("email");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-26 01:00:44 +02:00
|
|
|
if(this._button) this._button.hide();
|
2011-10-12 18:37:56 +02:00
|
|
|
if(this._button && this.getSurroundings && this.getSurroundings().removeDOMNode)
|
2011-08-26 00:42:07 +02:00
|
|
|
{
|
2011-10-12 18:37:56 +02:00
|
|
|
this.getSurroundings().removeDOMNode(this._button[0]);
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
|
|
|
this._button = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-29 23:15:53 +02:00
|
|
|
get_link: function(type, value) {
|
|
|
|
if(!value) return false;
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case "url":
|
|
|
|
// Silently use http if no protocol
|
|
|
|
if(value.indexOf("://") == -1) value = "http://"+value;
|
|
|
|
break;
|
|
|
|
case "url-phone":
|
|
|
|
// Clean number
|
|
|
|
value = value.replace('♥','').replace('(0)','');
|
|
|
|
value = value.replace(/[abc]/gi,2).replace(/[def]/gi,3).replace(/[ghi]/gi,4).replace(/[jkl]/gi,5).replace(/[mno]/gi,6);
|
|
|
|
value = value.replace(/[pqrs]/gi,7).replace(/[tuv]/gi,8).replace(/[wxyz]/gi,9);
|
2016-01-24 09:38:33 +01:00
|
|
|
// remove everything but numbers and plus, as telephon software might not like it
|
|
|
|
value = value.replace(/[^0-9+]/g, '');
|
2011-08-29 23:15:53 +02:00
|
|
|
|
2011-08-31 14:18:38 +02:00
|
|
|
// movile Webkit (iPhone, Android) have precedence over server configuration!
|
|
|
|
if (navigator.userAgent.indexOf('AppleWebKit') !== -1 &&
|
|
|
|
(navigator.userAgent.indexOf("iPhone") !== -1 || navigator.userAgent.indexOf("Android") !== -1) &&
|
|
|
|
value.indexOf("tel:") == -1)
|
|
|
|
{
|
2014-01-10 17:19:05 +01:00
|
|
|
value = "tel:"+value;
|
|
|
|
}
|
|
|
|
else if (this.egw().config("call_link"))
|
2011-08-31 14:18:38 +02:00
|
|
|
{
|
2014-01-18 10:29:32 +01:00
|
|
|
var link = this.egw().config("call_link")
|
|
|
|
.replace("%1", encodeURIComponent(value))
|
|
|
|
.replace("%u",this.egw().user('account_lid'))
|
|
|
|
.replace("%t",this.egw().user('account_phone'));
|
|
|
|
var popup = this.egw().config("call_popup");
|
|
|
|
value = function() { egw.open_link(link, 'phonecall', popup); };
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
2011-08-31 14:18:38 +02:00
|
|
|
else {
|
2011-08-29 23:15:53 +02:00
|
|
|
// Can't make a good handler
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "url-email":
|
2013-10-07 11:48:17 +02:00
|
|
|
if(value.indexOf("mailto:") == -1)
|
2011-08-29 23:15:53 +02:00
|
|
|
{
|
2013-10-07 11:48:17 +02:00
|
|
|
value = "mailto:"+value;
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
2014-01-10 17:19:05 +01:00
|
|
|
if((this.egw().user('apps').mail || this.egw().user('apps').felamimail) &&
|
2014-03-06 11:42:37 +01:00
|
|
|
this.egw().preference('force_mailto','addressbook') != '1' )
|
2011-08-29 23:15:53 +02:00
|
|
|
{
|
2013-10-07 11:48:17 +02:00
|
|
|
return function() {egw.open_link(value);};
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2011-08-26 00:42:07 +02:00
|
|
|
validate: function(e) {
|
|
|
|
e.data.hideMessage();
|
|
|
|
|
|
|
|
if(e.data._super) {
|
|
|
|
e.data._super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check value, and correct if possible
|
|
|
|
var value = jQuery.trim(e.data.getValue());
|
|
|
|
if(value == "") return;
|
|
|
|
switch(e.data._type) {
|
|
|
|
case "url":
|
|
|
|
if(value.indexOf("://") == -1) {
|
|
|
|
e.data.set_value("http://"+value);
|
2012-03-23 00:16:14 +01:00
|
|
|
e.data.showMessage(e.data.egw().lang("Protocol is required"), "hint", true);
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
|
|
|
break;
|
2013-07-30 16:16:47 +02:00
|
|
|
case "url-email":
|
2014-01-10 17:19:05 +01:00
|
|
|
if(!e.data.EMAIL_PREG.test(value) ||
|
2013-10-11 16:35:13 +02:00
|
|
|
// If they use Text <email>, make sure the <> match
|
|
|
|
(value.indexOf("<") > 0 && value.indexOf(">") != value.length-1) ||
|
|
|
|
(value.indexOf(">") > 0 && value.indexOf("<") < 0)
|
|
|
|
)
|
2013-07-30 16:16:47 +02:00
|
|
|
{
|
|
|
|
e.data.showMessage("Invalid email","validation_error",true);
|
|
|
|
}
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
2014-03-12 19:48:59 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
attachToDOM: function()
|
|
|
|
{
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
if (this.input[0].parentNode) jQuery(this.input[0].parentNode).addClass('et2_url_span');
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2011-08-26 00:42:07 +02:00
|
|
|
et2_register_widget(et2_url, ["url", "url-email", "url-phone"]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et2_url_ro is the readonly implementation of the url, email & phone.
|
|
|
|
* It renders things as links, when possible
|
2014-01-10 17:19:05 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_valueWidget
|
2011-08-26 00:42:07 +02:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_url_ro = (function(){ "use strict"; return et2_valueWidget.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2014-08-29 16:56:14 +02:00
|
|
|
attributes: {
|
|
|
|
"contact_plus": {
|
|
|
|
"name": "Add contact button",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "Allow to add email as contact to addressbook"
|
|
|
|
}
|
|
|
|
},
|
2014-09-09 10:31:59 +02:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-01-10 17:19:05 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_url_ro
|
|
|
|
*/
|
2011-08-26 00:42:07 +02:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.value = "";
|
|
|
|
this.span = $j(document.createElement("a"))
|
|
|
|
.addClass("et2_textbox readonly");
|
2014-03-27 00:25:43 +01:00
|
|
|
if(this._type == 'url-email')
|
|
|
|
{
|
|
|
|
this.span.addClass('et2_email');
|
|
|
|
}
|
2011-08-26 00:42:07 +02:00
|
|
|
this.setDOMNode(this.span[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
set_value: function(_value) {
|
|
|
|
this.value = _value;
|
|
|
|
|
2011-08-29 23:15:53 +02:00
|
|
|
var link = et2_url.prototype.get_link(this._type, _value);
|
|
|
|
|
2014-01-10 17:19:05 +01:00
|
|
|
if(!link)
|
2011-08-29 23:15:53 +02:00
|
|
|
{
|
|
|
|
this.span.text(_value);
|
2013-11-27 17:42:37 +01:00
|
|
|
this.span.removeAttr("href");
|
2011-08-29 23:15:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-08-26 00:42:07 +02:00
|
|
|
this.span.text(_value);
|
|
|
|
switch(this._type) {
|
|
|
|
case "url":
|
2011-08-29 23:15:53 +02:00
|
|
|
this.span.attr("href", link).attr("target", "_blank");
|
2011-08-26 00:42:07 +02:00
|
|
|
break;
|
|
|
|
case "url-phone":
|
2011-08-29 23:15:53 +02:00
|
|
|
if(typeof link == 'function')
|
|
|
|
{
|
2013-12-02 17:24:24 +01:00
|
|
|
this.span.off('click.et2_url');
|
|
|
|
this.span.on('click.et2_url', link);
|
2013-10-08 12:08:09 +02:00
|
|
|
this.span.attr("href", "#");
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
2013-02-05 13:50:20 +01:00
|
|
|
else if (link)
|
2011-08-29 23:15:53 +02:00
|
|
|
{
|
|
|
|
this.span.attr("href", link);
|
2011-08-26 00:42:07 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "url-email":
|
2011-08-29 23:15:53 +02:00
|
|
|
if(typeof link == 'function')
|
|
|
|
{
|
2013-12-02 17:24:24 +01:00
|
|
|
this.span.off('click.et2_url');
|
|
|
|
this.span.on('click.et2_url', link);
|
2013-10-07 12:05:51 +02:00
|
|
|
this.span.removeAttr("href");
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.span.attr("href", link);
|
2013-10-07 11:48:17 +02:00
|
|
|
if(!this.span.attr("target"))
|
|
|
|
{
|
|
|
|
this.span.attr("target", "_blank");
|
|
|
|
}
|
2011-08-29 23:15:53 +02:00
|
|
|
}
|
2016-03-18 17:44:51 +01:00
|
|
|
// wrap email address if there's a name
|
2016-01-26 16:36:16 +01:00
|
|
|
if (this.span.text() && this.span.text().split("<"))
|
|
|
|
{
|
|
|
|
var val = this.span.text().split("<");
|
|
|
|
val = val[0] != ""? val[0]: val[2];
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-26 16:36:16 +01:00
|
|
|
// need to preserve the original value somehow
|
|
|
|
// as it's been used for add contact plus feature
|
|
|
|
this.span.attr('title',_value);
|
2016-03-19 17:16:59 +01:00
|
|
|
|
2016-01-26 16:36:16 +01:00
|
|
|
this.span.text(val.replace(/"/g,''));
|
2016-03-18 17:44:51 +01:00
|
|
|
this.span.append("<span class='email'>"+
|
|
|
|
_value.replace(val,'')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
+"</span>");
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-26 16:36:16 +01:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-09-01 12:02:18 +02:00
|
|
|
// Add contact_plus button
|
|
|
|
if (this.options.contact_plus)
|
|
|
|
{
|
|
|
|
// If user doesn't have access to addressbook, stop
|
|
|
|
if(!egw.app('addressbook')) return;
|
|
|
|
|
|
|
|
// Bind onmouseenter event on <a> tag in order to add contact plus
|
|
|
|
this.span.on ({
|
|
|
|
mouseenter: function (event)
|
|
|
|
{
|
|
|
|
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 = {
|
2016-01-26 16:36:16 +01:00
|
|
|
'presets[email]': jQuery(this).attr('title')
|
2014-09-01 12:02:18 +02:00
|
|
|
};
|
|
|
|
|
2014-09-02 10:39:57 +02:00
|
|
|
return jQuery('<a href="#" class= "et2_url_email_contactPlus" title="'+egw.lang('Add a new contact')+'"><img src="'
|
|
|
|
+egw.image("new") +'"/></a>')
|
2014-09-01 12:02:18 +02:00
|
|
|
.on('click', function() {
|
|
|
|
egw.open('','addressbook','add',extra);
|
|
|
|
});
|
|
|
|
},
|
2014-09-09 10:31:59 +02:00
|
|
|
close: function( event, ui )
|
2014-09-01 12:02:18 +02:00
|
|
|
{
|
|
|
|
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");
|
2014-09-09 10:31:59 +02:00
|
|
|
}
|
2014-09-01 12:02:18 +02:00
|
|
|
});
|
|
|
|
}
|
2011-08-26 00:42:07 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-07-24 21:59:55 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
2014-01-27 10:48:43 +01:00
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
2012-07-24 21:59:55 +02:00
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs)
|
|
|
|
{
|
|
|
|
_attrs.push("value", "class");
|
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function()
|
|
|
|
{
|
|
|
|
return [this.span[0]];
|
|
|
|
},
|
2011-08-26 00:42:07 +02:00
|
|
|
|
2012-07-24 21:59:55 +02:00
|
|
|
setDetachedAttributes: function(_nodes, _values)
|
|
|
|
{
|
|
|
|
// Update the properties
|
|
|
|
this.span = jQuery(_nodes[0]);
|
|
|
|
if (typeof _values["value"] != "undefined")
|
|
|
|
{
|
|
|
|
this.set_value(_values["value"]);
|
|
|
|
}
|
|
|
|
if (typeof _values["class"] != "undefined")
|
2013-10-07 12:05:51 +02:00
|
|
|
{
|
2014-03-27 00:25:43 +01:00
|
|
|
_nodes[0].setAttribute("class", _values["class"]);
|
2013-10-07 12:05:51 +02:00
|
|
|
}
|
2014-09-09 10:31:59 +02:00
|
|
|
|
2012-07-24 21:59:55 +02:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
|
|
|
et2_register_widget(et2_url_ro, ["url_ro", "url-email_ro", "url-phone_ro"]);
|