2011-08-30 22:56:01 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Description object
|
|
|
|
*
|
|
|
|
* @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;
|
|
|
|
et2_core_baseWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "image" XET-Tag
|
|
|
|
*/
|
|
|
|
var et2_image = et2_baseWidget.extend({
|
|
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
"link": {
|
|
|
|
},
|
|
|
|
"link_target":{
|
|
|
|
},
|
|
|
|
"imagemap":{
|
|
|
|
},
|
|
|
|
"link_size":{
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
legacyOptions: ["link", "link_target", "imagemap", "link_size"],
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// Create the image or a/image tag
|
|
|
|
this.image = this.node = $j(document.createElement("img"));
|
|
|
|
if(this.options.link)
|
|
|
|
{
|
|
|
|
this.node = $j(document.createElement("a"));
|
|
|
|
this.image.appendTo(this.node);
|
|
|
|
}
|
2011-09-02 18:23:26 +02:00
|
|
|
if(this.options["class"])
|
2011-08-31 18:00:45 +02:00
|
|
|
{
|
2011-09-02 18:23:26 +02:00
|
|
|
this.node.addClass(this.options["class"]);
|
2011-08-31 18:00:45 +02:00
|
|
|
}
|
2011-08-30 22:56:01 +02:00
|
|
|
this.setDOMNode(this.node[0]);
|
|
|
|
},
|
|
|
|
|
|
|
|
set_label: function(_value) {
|
|
|
|
if(_value == this.options.label) return;
|
|
|
|
this.options.label = _value;
|
2011-08-31 08:29:51 +02:00
|
|
|
// label is NOT the alt attribute in eTemplate, but the title/tooltip
|
2011-08-30 22:56:01 +02:00
|
|
|
this.image.attr("alt", _value);
|
2011-08-31 18:00:45 +02:00
|
|
|
this.image.set_statustext(_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);
|
|
|
|
},
|
|
|
|
|
2011-08-30 22:56:01 +02:00
|
|
|
set_src: function(_value) {
|
2011-08-31 18:00:45 +02:00
|
|
|
if(!this.isInTree())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-09-06 21:53:14 +02:00
|
|
|
|
|
|
|
// Check to expand name
|
|
|
|
if(_value.indexOf("$") != -1 || _value.indexOf("@") != -1) {
|
|
|
|
var contentMgr = this.getArrayMgr("content");
|
|
|
|
if (contentMgr != null) {
|
|
|
|
var val = contentMgr.getValueForID(_value);
|
|
|
|
if (val !== null)
|
|
|
|
{
|
|
|
|
_value = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 22:56:01 +02:00
|
|
|
this.options.src = _value;
|
2011-08-31 18:00:45 +02:00
|
|
|
// Get application to use from template ID
|
|
|
|
var appname = this.getTemplateApp();
|
|
|
|
var src = egw.image(_value,appname || "phpgwapi");
|
|
|
|
if(src )
|
|
|
|
{
|
|
|
|
this.image.attr("src", src).show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.image.css("display","none");
|
|
|
|
}
|
2011-08-30 22:56:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_image, ["image"]);
|
|
|
|
|
|
|
|
|