egroupware_official/etemplate/js/et2_widget_image.js

188 lines
3.9 KiB
JavaScript
Raw Normal View History

/**
2011-09-09 10:28:40 +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_interfaces;
et2_core_baseWidget;
*/
/**
* Class which implements the "image" XET-Tag
*/
2011-10-24 23:58:42 +02:00
var et2_image = et2_baseWidget.extend([et2_IDetachedDOM], {
attributes: {
"src": {
"name": "Image",
"type": "string",
"description": "Displayed image"
},
"href": {
"name": "Link Target",
"type": "string",
"description": "Link URL, empty if you don't wan't to display a link."
},
"extra_link_target": {
"name": "Link target",
"type": "string",
"default": "_self",
"description": "Link target descriptor"
},
"extra_link_popup": {
"name": "Popup",
"type": "string",
"description": "widthxheight, if popup should be used, eg. 640x480"
},
"imagemap":{
// TODO: Do something with this
"name": "Image map",
"description": "Currently not implemented"
},
"label": {
"name": "Label",
"type": "string",
"description": "Label for image"
}
},
2011-09-09 10:28:40 +02:00
legacyOptions: ["href", "extra_link_target", "imagemap", "extra_link_popup", "id"],
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"));
if (this.options.label)
{
this.image.attr("alt", this.options.label).attr("title", this.options.label);
}
if (this.options.href)
{
this.image.addClass('et2_clickable');
}
2011-09-02 18:23:26 +02:00
if(this.options["class"])
{
2011-10-24 23:58:42 +02:00
this.image.addClass(this.options["class"]);
}
2011-10-24 23:58:42 +02:00
this.setDOMNode(this.image[0]);
},
click: function()
{
if(this.options.href)
{
egw.call_link(this.options.href, this.options.extra_link_target, this.options.extra_link_popup);
}
},
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"]);
if (src)
{
_attrs["src"] = src;
}
}
}
},
set_label: function(_value) {
if(_value == this.options.label) return;
this.options.label = _value;
// label is NOT the alt attribute in eTemplate, but the title/tooltip
this.image.attr("alt", _value).attr("title", _value);
},
2011-09-06 21:53:14 +02:00
setValue: function(_value) {
// Value is src, images don't get IDs
this.set_src(_value);
},
set_src: function(_value) {
if(!this.isInTree())
{
return false;
}
2011-09-06 21:53:14 +02:00
this.options.src = _value;
2011-09-14 02:04:54 +02:00
var app = this.getTemplateApp();
2011-09-14 02:04:54 +02:00
// Handle app/image
if(_value.indexOf("/") > 0 && _value.indexOf("/") == _value.lastIndexOf("/")) {
2011-09-14 02:04:54 +02:00
var split = et2_csvSplit(_value, 2,"/");
var app = split[0];
_value = split[1];
}
// Get application to use from template ID
2011-09-14 02:04:54 +02:00
var src = egw.image(_value, app);
if(src)
{
this.image.attr("src", src).show();
return true;
}
// allow url's too
else if (_value[0] == '/' || _value.substr(0,4) == 'http')
{
this.image.attr('src', _value).show();
return true;
}
else
{
this.image.css("display","none");
return false;
}
},
/**
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
*/
getDetachedAttributes: function(_attrs) {
2011-09-14 22:52:59 +02:00
_attrs.push("src", "label", "href");
},
getDetachedNodes: function() {
return [this.image[0]];
},
setDetachedAttributes: function(_nodes, _values) {
// Set the given DOM-Nodes
this.image = $j(_nodes[0]);
// Set the attributes
if (_values["src"])
{
this.set_src(_values["src"]);
}
if (_values["label"])
{
this.set_label(_values["label"]);
}
2011-09-14 22:52:59 +02:00
if(_values["href"])
{
this.image.addClass('et2_clickable');
}
}
});
et2_register_widget(et2_image, ["image"]);