2011-08-30 22:56:01 +02:00
|
|
|
/**
|
2011-09-09 10:28:40 +02:00
|
|
|
* EGroupware eTemplate2 - JS Description object
|
2011-08-30 22:56:01 +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
|
2016-06-06 17:38:20 +02:00
|
|
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
2011-09-08 20:36:09 +02:00
|
|
|
et2_core_interfaces;
|
2011-08-30 22:56:01 +02:00
|
|
|
et2_core_baseWidget;
|
2016-03-19 14:48:07 +01:00
|
|
|
expose;
|
2016-09-12 16:23:57 +02:00
|
|
|
/vendor/bower-asset/cropper/dist/cropper.min.js;
|
2011-08-30 22:56:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "image" XET-Tag
|
2014-01-14 18:08:41 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_baseWidget
|
2014-01-14 18:08:41 +01:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_image = (function(){ "use strict"; return expose(et2_baseWidget.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2011-08-30 22:56:01 +02:00
|
|
|
attributes: {
|
|
|
|
"src": {
|
|
|
|
"name": "Image",
|
|
|
|
"type": "string",
|
2011-08-31 08:29:51 +02:00
|
|
|
"description": "Displayed image"
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
2014-01-31 15:12:09 +01:00
|
|
|
default_src: {
|
|
|
|
name: "Default image",
|
|
|
|
type: "string",
|
|
|
|
description: "Image to use if src is not found"
|
|
|
|
},
|
2011-09-08 22:44:53 +02:00
|
|
|
"href": {
|
|
|
|
"name": "Link Target",
|
|
|
|
"type": "string",
|
2014-01-20 16:19:38 +01:00
|
|
|
"description": "Link URL, empty if you don't wan't to display a link.",
|
|
|
|
"default": et2_no_init
|
2011-09-08 22:44:53 +02:00
|
|
|
},
|
|
|
|
"extra_link_target": {
|
|
|
|
"name": "Link target",
|
|
|
|
"type": "string",
|
|
|
|
"default": "_self",
|
|
|
|
"description": "Link target descriptor"
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
2011-09-08 22:44:53 +02:00
|
|
|
"extra_link_popup": {
|
|
|
|
"name": "Popup",
|
|
|
|
"type": "string",
|
|
|
|
"description": "widthxheight, if popup should be used, eg. 640x480"
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
|
|
|
"imagemap":{
|
2011-09-28 01:44:07 +02:00
|
|
|
// TODO: Do something with this
|
|
|
|
"name": "Image map",
|
|
|
|
"description": "Currently not implemented"
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
2011-09-08 22:44:53 +02:00
|
|
|
"label": {
|
2011-09-28 01:44:07 +02:00
|
|
|
"name": "Label",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Label for image"
|
2014-09-29 18:29:17 +02:00
|
|
|
},
|
2015-01-20 12:56:51 +01:00
|
|
|
"expose_view":{
|
|
|
|
name: "Expose view",
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Clicking on an image with href value would popup an expose view, and will show image referenced by href."
|
2011-08-30 22:56:01 +02:00
|
|
|
}
|
|
|
|
},
|
2011-09-09 10:28:40 +02:00
|
|
|
legacyOptions: ["href", "extra_link_target", "imagemap", "extra_link_popup", "id"],
|
2011-08-30 22:56:01 +02:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-01-14 18:08:41 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_image
|
|
|
|
*/
|
2011-08-30 22:56:01 +02:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Create the image or a/image tag
|
2016-06-02 16:51:15 +02:00
|
|
|
this.image = jQuery(document.createElement("img"));
|
2011-09-08 22:44:53 +02:00
|
|
|
if (this.options.label)
|
|
|
|
{
|
|
|
|
this.image.attr("alt", this.options.label).attr("title", this.options.label);
|
|
|
|
}
|
2014-01-14 18:08:41 +01:00
|
|
|
if (this.options.href)
|
2011-08-30 22:56:01 +02:00
|
|
|
{
|
2011-09-08 22:44:53 +02:00
|
|
|
this.image.addClass('et2_clickable');
|
2011-08-30 22:56:01 +02:00
|
|
|
}
|
2011-09-02 18:23:26 +02:00
|
|
|
if(this.options["class"])
|
2011-08-31 18:00:45 +02:00
|
|
|
{
|
2011-10-24 23:58:42 +02:00
|
|
|
this.image.addClass(this.options["class"]);
|
2011-09-08 20:36:09 +02:00
|
|
|
}
|
2011-10-24 23:58:42 +02:00
|
|
|
this.setDOMNode(this.image[0]);
|
2011-09-08 20:36:09 +02:00
|
|
|
},
|
2014-01-14 18:08:41 +01:00
|
|
|
|
2011-09-08 22:44:53 +02:00
|
|
|
click: function()
|
|
|
|
{
|
|
|
|
if(this.options.href)
|
|
|
|
{
|
2012-03-28 14:37:03 +02:00
|
|
|
this.egw().open_link(this.options.href, this.options.extra_link_target, this.options.extra_link_popup);
|
2012-03-26 17:28:02 +02:00
|
|
|
}
|
2012-07-24 23:16:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this._super.apply(this,arguments);
|
|
|
|
}
|
2011-09-08 22:44:53 +02:00
|
|
|
},
|
2011-09-08 20:36:09 +02:00
|
|
|
|
|
|
|
transformAttributes: function(_attrs) {
|
|
|
|
this._super.apply(arguments);
|
|
|
|
|
|
|
|
// Check to expand name
|
|
|
|
if (typeof _attrs["src"] != "undefined")
|
|
|
|
{
|
2011-09-14 02:04:54 +02:00
|
|
|
var manager = this.getArrayMgr("content");
|
|
|
|
if(manager) {
|
|
|
|
var src = manager.getEntry(_attrs["src"]);
|
2014-01-14 18:08:41 +01:00
|
|
|
if (typeof src != "undefined" && src !== null)
|
2011-09-14 02:04:54 +02:00
|
|
|
{
|
2012-07-24 23:16:44 +02:00
|
|
|
if(typeof src == "object")
|
|
|
|
{
|
|
|
|
src = egw().link('/index.php', src);
|
|
|
|
}
|
2011-09-14 02:04:54 +02:00
|
|
|
_attrs["src"] = src;
|
|
|
|
}
|
2011-09-08 20:36:09 +02:00
|
|
|
}
|
2011-08-31 18:00:45 +02:00
|
|
|
}
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set_label: function(_value) {
|
|
|
|
this.options.label = _value;
|
2014-02-03 11:15:47 +01:00
|
|
|
_value = this.egw().lang(_value);
|
2011-08-31 08:29:51 +02:00
|
|
|
// label is NOT the alt attribute in eTemplate, but the title/tooltip
|
2011-09-08 22:44:53 +02:00
|
|
|
this.image.attr("alt", _value).attr("title", _value);
|
2011-08-30 22:56:01 +02:00
|
|
|
},
|
|
|
|
|
2011-09-06 21:53:14 +02:00
|
|
|
setValue: function(_value) {
|
|
|
|
// Value is src, images don't get IDs
|
|
|
|
this.set_src(_value);
|
|
|
|
},
|
|
|
|
|
2014-01-17 16:58:58 +01:00
|
|
|
set_href: function (_value)
|
|
|
|
{
|
|
|
|
if (!this.isInTree())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.options.href = _value;
|
|
|
|
this.image.wrapAll('<a href="'+_value+'"></a>"');
|
|
|
|
|
|
|
|
var href = this.options.href;
|
|
|
|
var popup = this.options.extra_link_popup;
|
|
|
|
var target = this.options.extra_link_target;
|
2014-09-29 18:29:17 +02:00
|
|
|
var self = this;
|
2015-04-09 12:52:05 +02:00
|
|
|
this.image.click(function(e)
|
2014-01-17 16:58:58 +01:00
|
|
|
{
|
2015-01-20 12:56:51 +01:00
|
|
|
if (self.options.expose_view)
|
2014-09-29 18:29:17 +02:00
|
|
|
{
|
2015-02-25 12:12:47 +01:00
|
|
|
self._init_blueimp_gallery(e,_value);
|
2015-04-09 12:52:05 +02:00
|
|
|
e.stopImmediatePropagation();
|
2014-09-29 18:29:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.open_link(href,target,popup);
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2014-01-17 16:58:58 +01:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
2014-01-31 15:12:09 +01:00
|
|
|
|
2014-01-17 16:58:58 +01:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2014-01-31 15:12:09 +01:00
|
|
|
/**
|
|
|
|
* Set image src
|
|
|
|
*
|
|
|
|
* @param {string} _value image, app/image or url
|
|
|
|
* @return {boolean} true if image was found, false if not (image is either not displayed or default_src is used)
|
|
|
|
*/
|
2011-08-30 22:56:01 +02:00
|
|
|
set_src: function(_value) {
|
2011-08-31 18:00:45 +02:00
|
|
|
if(!this.isInTree())
|
|
|
|
{
|
2011-09-22 23:23:30 +02:00
|
|
|
return false;
|
2011-08-31 18:00:45 +02:00
|
|
|
}
|
2011-09-06 21:53:14 +02:00
|
|
|
|
2011-08-30 22:56:01 +02:00
|
|
|
this.options.src = _value;
|
2012-03-06 17:29:18 +01:00
|
|
|
|
2012-03-08 17:57:23 +01:00
|
|
|
var src = this.egw().image(_value);
|
2012-03-26 17:28:02 +02:00
|
|
|
if (src)
|
2011-08-31 18:00:45 +02:00
|
|
|
{
|
2011-09-08 21:36:48 +02:00
|
|
|
this.image.attr("src", src).show();
|
2011-09-14 20:37:38 +02:00
|
|
|
return true;
|
2011-08-31 18:00:45 +02:00
|
|
|
}
|
2011-09-08 22:44:53 +02:00
|
|
|
// allow url's too
|
|
|
|
else if (_value[0] == '/' || _value.substr(0,4) == 'http')
|
|
|
|
{
|
|
|
|
this.image.attr('src', _value).show();
|
2011-09-14 20:37:38 +02:00
|
|
|
return true;
|
2011-09-08 22:44:53 +02:00
|
|
|
}
|
2014-01-31 15:12:09 +01:00
|
|
|
src = null;
|
|
|
|
if (this.options.default_src)
|
|
|
|
{
|
|
|
|
src = this.egw().image(this.options.default_src);
|
|
|
|
}
|
|
|
|
if (src)
|
|
|
|
{
|
|
|
|
this.image.attr("src", src).show();
|
|
|
|
}
|
2011-08-31 18:00:45 +02:00
|
|
|
else
|
|
|
|
{
|
2011-09-08 21:36:48 +02:00
|
|
|
this.image.css("display","none");
|
2011-09-08 20:36:09 +02:00
|
|
|
}
|
2014-01-31 15:12:09 +01:00
|
|
|
return false;
|
2011-09-08 20:36:09 +02:00
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2015-01-20 12:56:51 +01:00
|
|
|
/**
|
|
|
|
* Function to get media content to feed the expose
|
|
|
|
* @param {type} _value
|
|
|
|
* @returns {Array|Array.getMedia.mediaContent}
|
|
|
|
*/
|
|
|
|
getMedia: function (_value)
|
|
|
|
{
|
2015-01-20 19:47:08 +01:00
|
|
|
var base_url = egw.webserverUrl.match(/^\//,'ig')?egw(window).window.location.origin + egw.webserverUrl + '/':egw.webserverUrl + '/';
|
2015-01-20 12:56:51 +01:00
|
|
|
var mediaContent = [];
|
|
|
|
if (_value)
|
|
|
|
{
|
|
|
|
mediaContent = [{
|
|
|
|
title: this.options.label,
|
|
|
|
href: base_url + _value,
|
|
|
|
type: this.options.type + "/*",
|
|
|
|
thumbnail: base_url + _value
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
return mediaContent;
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2011-09-08 20:36:09 +02:00
|
|
|
/**
|
|
|
|
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
|
2014-01-31 15:12:09 +01:00
|
|
|
*
|
|
|
|
* @param {array} _attrs
|
2011-09-08 20:36:09 +02:00
|
|
|
*/
|
2011-09-08 21:36:48 +02:00
|
|
|
getDetachedAttributes: function(_attrs) {
|
2011-09-14 22:52:59 +02:00
|
|
|
_attrs.push("src", "label", "href");
|
2011-09-08 20:36:09 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function() {
|
2011-09-08 21:36:48 +02:00
|
|
|
return [this.image[0]];
|
2011-09-08 20:36:09 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values) {
|
|
|
|
// Set the given DOM-Nodes
|
2016-06-02 16:51:15 +02:00
|
|
|
this.image = jQuery(_nodes[0]);
|
2011-09-08 20:36:09 +02:00
|
|
|
|
|
|
|
// Set the attributes
|
|
|
|
if (_values["src"])
|
|
|
|
{
|
|
|
|
this.set_src(_values["src"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_values["label"])
|
|
|
|
{
|
|
|
|
this.set_label(_values["label"]);
|
2011-08-31 18:00:45 +02:00
|
|
|
}
|
2011-09-14 22:52:59 +02:00
|
|
|
if(_values["href"])
|
|
|
|
{
|
|
|
|
this.image.addClass('et2_clickable');
|
2014-01-17 16:58:58 +01:00
|
|
|
this.set_href(_values["href"]);
|
2011-09-14 22:52:59 +02:00
|
|
|
}
|
2011-09-08 21:36:48 +02:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
}));}).call(this);
|
2011-08-30 22:56:01 +02:00
|
|
|
|
|
|
|
et2_register_widget(et2_image, ["image"]);
|
|
|
|
|
2014-03-03 17:50:01 +01:00
|
|
|
/**
|
|
|
|
* Widget displaying an application icon
|
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_appicon = (function(){ "use strict"; return et2_image.extend(
|
2014-03-03 17:50:01 +01:00
|
|
|
{
|
|
|
|
attributes: {
|
|
|
|
default_src: {
|
|
|
|
name: "Default image",
|
|
|
|
type: "string",
|
|
|
|
default: "nonav",
|
|
|
|
description: "Image to use if there is no application icon"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
set_src: function(_app)
|
|
|
|
{
|
2014-03-06 08:50:06 +01:00
|
|
|
if (!_app) _app = this.egw().app_name();
|
2014-08-21 11:47:30 +02:00
|
|
|
this.image.addClass('et2_appicon');
|
2014-03-03 17:50:01 +01:00
|
|
|
this._super.call(this, _app == 'sitemgr-link' ? 'sitemgr/sitemgr-link' : // got removed from jdots
|
|
|
|
(this.egw().app(_app, 'icon_app') || _app)+'/'+(this.egw().app(_app, 'icon') || 'navbar'));
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2016-09-05 17:21:14 +02:00
|
|
|
et2_register_widget(et2_appicon, ["appicon"]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Avatar widget to display user profile picture or
|
|
|
|
* user letter avatar based on user's firstname lastname.
|
|
|
|
*
|
|
|
|
* @augments et2_baseWidget
|
|
|
|
*/
|
|
|
|
|
|
|
|
var et2_avatar = (function(){ "use strict"; return et2_image.extend(
|
|
|
|
{
|
|
|
|
attributes: {
|
|
|
|
"contact_id": {
|
|
|
|
name: "Contact id",
|
|
|
|
type: "string",
|
|
|
|
default: "",
|
|
|
|
description: "Contact id should be either user account_id {account:number} or contact_id {contact:number or number}"
|
|
|
|
},
|
|
|
|
"default_src": {
|
|
|
|
"ignore": true
|
|
|
|
},
|
|
|
|
"frame": {
|
|
|
|
name: "Avatar frame",
|
|
|
|
type: "string",
|
|
|
|
default: "circle",
|
|
|
|
description: "Define the shape of frame that avatar will be shown inside it. it can get {circle,rectangle} values which default value is cicle."
|
2016-09-07 17:27:47 +02:00
|
|
|
},
|
|
|
|
editable: {
|
|
|
|
name: "Edit avatar",
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Make avatar widget editable to be able to crop profile picture or upload a new photo"
|
2016-09-12 16:23:57 +02:00
|
|
|
},
|
|
|
|
crop: {
|
|
|
|
name: "Crop avatar",
|
|
|
|
type: "boolean",
|
|
|
|
default: false,
|
|
|
|
description: "Create crop container and cropping feature"
|
2016-09-05 17:21:14 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function ()
|
|
|
|
{
|
|
|
|
this._super.apply(this,arguments);
|
|
|
|
if (this.options.frame == 'circle')
|
|
|
|
{
|
|
|
|
this.image.attr('style', 'border-radius:50%');
|
|
|
|
}
|
|
|
|
if (this.options.contact_id) this.setValue(this.options.contact_id);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to set contact id
|
|
|
|
* contact id could be in one of these formats:
|
|
|
|
* 'number', will be consider as contact_id
|
|
|
|
* 'contact:number', similar to above
|
|
|
|
* 'account:number', will be consider as account id
|
|
|
|
* @example: contact_id = "account:4"
|
|
|
|
*
|
|
|
|
* @param {string} _contact_id contact id could be as above mentioned formats
|
|
|
|
*/
|
|
|
|
set_contact_id: function(_contact_id)
|
|
|
|
{
|
2018-10-31 14:41:36 +01:00
|
|
|
var params = {};
|
2016-09-05 17:21:14 +02:00
|
|
|
var id = 'contact_id';
|
|
|
|
|
2019-02-20 17:08:40 +01:00
|
|
|
this.image.addClass('et2_avatar');
|
|
|
|
|
2016-09-05 17:21:14 +02:00
|
|
|
if (!_contact_id)
|
|
|
|
{
|
|
|
|
_contact_id = this.egw().user('account_id');
|
|
|
|
}
|
|
|
|
else if(_contact_id.match(/account\:/))
|
|
|
|
{
|
|
|
|
id = 'account_id';
|
|
|
|
_contact_id = _contact_id.replace('account:','');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id = 'contact_id';
|
|
|
|
_contact_id = _contact_id.replace('contact:', '');
|
|
|
|
}
|
|
|
|
|
2019-02-20 17:08:40 +01:00
|
|
|
// if our src (incl. cache-buster) already includes the correct id, use that one
|
|
|
|
if (this.options.src && this.options.src.match("(&|\\?)contact_id="+_contact_id+"(&|\\$)"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we have only the id, so we need to bypass caching with a cache-buster
|
2016-09-05 17:21:14 +02:00
|
|
|
params[id] = _contact_id;
|
2019-02-20 17:08:40 +01:00
|
|
|
params._cache = (new Date).getTime();
|
2016-09-05 17:21:14 +02:00
|
|
|
|
2018-10-31 13:49:51 +01:00
|
|
|
var url = egw.link('/api/avatar.php',params);
|
2016-09-05 17:21:14 +02:00
|
|
|
this.set_src(url);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to set value
|
|
|
|
* @param {string} _value
|
|
|
|
*/
|
|
|
|
setValue: function(_value)
|
|
|
|
{
|
|
|
|
this.set_contact_id(_value);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
|
|
|
|
*
|
|
|
|
* @param {array} _attrs
|
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs) {
|
|
|
|
_attrs.push("contact_id", "label", "href");
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function (_nodes, _values)
|
|
|
|
{
|
|
|
|
// Set the given DOM-Nodes
|
|
|
|
this.image = jQuery(_nodes[0]);
|
|
|
|
|
|
|
|
if (_values["contact_id"])
|
|
|
|
{
|
|
|
|
this.set_contact_id(_values["contact_id"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_values["label"])
|
|
|
|
{
|
|
|
|
this.set_label(_values["label"]);
|
|
|
|
}
|
|
|
|
if(_values["href"])
|
|
|
|
{
|
|
|
|
this.image.addClass('et2_clickable');
|
|
|
|
this.set_href(_values["href"]);
|
|
|
|
}
|
2016-09-07 17:27:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build Editable Mask Layer (EML) in order to show edit/delete actions
|
|
|
|
* on top of profile picture.
|
2017-11-29 02:58:36 +01:00
|
|
|
* @param {boolean} _noDelete disable delete button in initialization
|
2016-09-07 17:27:47 +02:00
|
|
|
*/
|
2017-11-13 12:15:54 +01:00
|
|
|
_buildEditableLayer: function (_noDelete)
|
2016-09-07 17:27:47 +02:00
|
|
|
{
|
|
|
|
var self = this;
|
|
|
|
// editable mask layer (eml)
|
|
|
|
var eml = jQuery(document.createElement('div'))
|
|
|
|
.addClass('eml')
|
|
|
|
.insertAfter(this.image);
|
|
|
|
|
|
|
|
// edit button
|
|
|
|
var edit = jQuery(document.createElement('div'))
|
|
|
|
.addClass('emlEdit')
|
|
|
|
.click(function(){
|
2016-09-12 16:23:57 +02:00
|
|
|
var buttons = [
|
2017-11-29 17:58:01 +01:00
|
|
|
{"button_id": 1,"text": self.egw().lang('save'), id: 'save', image: 'check', "default":true},
|
|
|
|
{"button_id": 0,"text": self.egw().lang('cancel'), id: 'cancel', image: 'cancelled'}
|
2016-09-12 16:23:57 +02:00
|
|
|
];
|
|
|
|
var dialog = function(_title, _value, _buttons, _egw_or_appname)
|
|
|
|
{
|
|
|
|
return et2_createWidget("dialog",
|
|
|
|
{
|
|
|
|
callback: function(_buttons, _value)
|
|
|
|
{
|
|
|
|
if (_buttons == 'save')
|
|
|
|
{
|
|
|
|
var canvas = jQuery('#_cropper_image').cropper('getCroppedCanvas');
|
|
|
|
self.image.attr('src', canvas.toDataURL("image/jpeg", 1.0));
|
2017-11-29 02:58:36 +01:00
|
|
|
self.egw().json('addressbook.addressbook_ui.ajax_update_photo',
|
2017-11-29 09:25:08 +01:00
|
|
|
[self.getInstanceManager().etemplate_exec_id, canvas.toDataURL('image/jpeg',1.0)],
|
2017-11-29 02:58:36 +01:00
|
|
|
function(res)
|
2017-11-13 12:15:54 +01:00
|
|
|
{
|
2017-11-29 02:58:36 +01:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
del.show();
|
|
|
|
}
|
|
|
|
}).sendRequest();
|
2016-09-12 16:23:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
title: _title||egw.lang('Input required'),
|
|
|
|
buttons: _buttons||et2_dialog.BUTTONS_OK_CANCEL,
|
|
|
|
value: {
|
|
|
|
content: _value
|
|
|
|
},
|
|
|
|
width: "90%",
|
|
|
|
height:"90%",
|
|
|
|
resizable: false,
|
|
|
|
position:"top+10",
|
|
|
|
template: egw.webserverUrl+'/api/templates/default/avatar_edit.xet?2'
|
|
|
|
}, et2_dialog._create_parent(_egw_or_appname));
|
|
|
|
};
|
|
|
|
|
|
|
|
dialog(egw.lang('Edit avatar'),{photo:self.options.contact_id},buttons);
|
2016-09-07 17:27:47 +02:00
|
|
|
})
|
|
|
|
.appendTo(eml);
|
|
|
|
|
|
|
|
// delete button
|
|
|
|
var del = jQuery(document.createElement('div'))
|
|
|
|
.addClass('emlDelete')
|
|
|
|
.click(function(){
|
|
|
|
et2_dialog.show_dialog(function(_btn){
|
|
|
|
if (_btn == et2_dialog.YES_BUTTON)
|
|
|
|
{
|
2017-11-29 02:58:36 +01:00
|
|
|
self.egw().json('addressbook.addressbook_ui.ajax_update_photo',
|
2017-11-29 09:25:08 +01:00
|
|
|
[self.getInstanceManager().etemplate_exec_id, null],
|
2017-11-29 02:58:36 +01:00
|
|
|
function(res)
|
2016-09-13 17:30:39 +02:00
|
|
|
{
|
2017-11-29 02:58:36 +01:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
self.image.attr('src','');
|
|
|
|
del.hide();
|
2016-09-13 17:30:39 +02:00
|
|
|
egw.refresh('Avatar Deleted.', egw.app_name());
|
2017-11-29 02:58:36 +01:00
|
|
|
}
|
|
|
|
}).sendRequest();
|
2016-09-07 17:27:47 +02:00
|
|
|
}
|
2018-09-13 22:26:54 +02:00
|
|
|
}, egw.lang('Delete this photo?'), egw.lang('Delete'), null, et2_dialog.BUTTONS_YES_NO);
|
2016-09-07 17:27:47 +02:00
|
|
|
})
|
|
|
|
.appendTo(eml);
|
2017-11-13 12:15:54 +01:00
|
|
|
if (_noDelete) del.hide();
|
2016-09-07 17:27:47 +02:00
|
|
|
// invisible the mask
|
|
|
|
eml.css('opacity','0');
|
|
|
|
|
|
|
|
eml.parent().css('position', "relative");
|
|
|
|
|
|
|
|
// bind handler for activating actions on editable mask
|
|
|
|
eml.on({
|
|
|
|
mouseover:function(){eml.css('opacity','0.9');},
|
2016-09-13 17:30:39 +02:00
|
|
|
mouseout: function (){eml.css('opacity','0');}
|
2016-09-07 17:27:47 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We need to build the Editable Mask Layer after widget gets loaded
|
|
|
|
*/
|
|
|
|
doLoadingFinished: function ()
|
|
|
|
{
|
|
|
|
this._super.apply(this,arguments);
|
2017-11-13 12:15:54 +01:00
|
|
|
var self = this;
|
2019-01-28 10:01:12 +01:00
|
|
|
if (this.options.contact_id && this.options.editable)
|
2016-09-07 17:27:47 +02:00
|
|
|
{
|
2017-11-13 12:15:54 +01:00
|
|
|
egw(window).json(
|
|
|
|
'addressbook.addressbook_ui.ajax_noPhotoExists',
|
|
|
|
[this.options.contact_id],
|
|
|
|
function(noPhotoExists)
|
|
|
|
{
|
|
|
|
if (noPhotoExists) self.image.attr('src','');
|
|
|
|
self._buildEditableLayer(noPhotoExists);
|
|
|
|
}
|
|
|
|
).sendRequest(true);
|
2016-09-07 17:27:47 +02:00
|
|
|
}
|
2016-09-12 16:23:57 +02:00
|
|
|
if (this.options.crop)
|
|
|
|
{
|
|
|
|
var cropped = jQuery(this.image).cropper({
|
|
|
|
aspectRatio: 1/1,
|
|
|
|
crop: function (e){
|
|
|
|
console.log (e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-09-05 17:21:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});}).call(this);
|
2016-09-13 17:30:39 +02:00
|
|
|
et2_register_widget(et2_avatar, ["avatar"]);
|
|
|
|
|
2016-11-18 14:50:42 +01:00
|
|
|
/**
|
|
|
|
* Avatar readonly widget to only display user profile picture or
|
|
|
|
* user letter avatar based on user's firstname lastname.
|
|
|
|
*
|
|
|
|
* @augments et2_baseWidget
|
|
|
|
*/
|
|
|
|
var et2_avatar_ro = (function(){ "use strict"; return et2_avatar.extend(
|
|
|
|
{
|
|
|
|
init: function ()
|
|
|
|
{
|
|
|
|
this._super.apply(this,arguments);
|
|
|
|
this.options.editable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});}).call(this);
|
|
|
|
et2_register_widget(et2_avatar_ro, ["avatar_ro"]);
|
|
|
|
|
2016-09-13 17:30:39 +02:00
|
|
|
jQuery.extend(et2_avatar,
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Function runs after uplaod in avatar dialog is finished and it tries to
|
|
|
|
* update image and cropper container.
|
2016-11-18 14:50:42 +01:00
|
|
|
*
|
2016-09-13 17:30:39 +02:00
|
|
|
* @param {type} e
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
uploadAvatar_onFinish: function (e){
|
|
|
|
var file = e.data.resumable.files[0].file;
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function (e)
|
|
|
|
{
|
|
|
|
jQuery('#_cropper_image').attr('src', e.target.result);
|
|
|
|
jQuery('#_cropper_image').cropper('replace',e.target.result);
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
}
|
|
|
|
});
|