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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2011-09-08 20:36:09 +02:00
|
|
|
et2_core_interfaces;
|
2011-08-30 22:56:01 +02:00
|
|
|
et2_core_baseWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
var et2_image = 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"
|
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
|
2011-10-24 23:58:42 +02:00
|
|
|
this.image = $j(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;
|
|
|
|
this.image.parent().click(function(e)
|
|
|
|
{
|
|
|
|
egw.open_link(href,target,popup);
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2011-09-08 21:36:48 +02:00
|
|
|
this.image = $j(_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
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
var et2_appicon = et2_image.extend(
|
|
|
|
{
|
|
|
|
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:50 +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'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_appicon, ["appicon"]);
|