2011-08-05 16:53:54 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Description object
|
2011-08-05 16:53:54 +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 Andreas Stöckel
|
|
|
|
* @copyright Stylite 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2011-08-07 15:43:46 +02:00
|
|
|
"use strict";
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_baseWidget;
|
2011-08-05 16:53:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "description" XET-Tag
|
2013-04-13 21:00:13 +02:00
|
|
|
*
|
|
|
|
* @augments et2_baseWidget
|
2011-08-05 16:53:54 +02:00
|
|
|
*/
|
2013-04-13 21:00:13 +02:00
|
|
|
var et2_description = et2_baseWidget.extend([et2_IDetachedDOM],
|
|
|
|
{
|
2011-08-10 16:36:31 +02:00
|
|
|
attributes: {
|
|
|
|
"value": {
|
2013-02-13 10:23:33 +01:00
|
|
|
"name": "Value",
|
2011-08-10 16:36:31 +02:00
|
|
|
"type": "string",
|
2011-08-23 19:05:05 +02:00
|
|
|
"description": "Displayed text",
|
2013-04-09 09:22:35 +02:00
|
|
|
"translate": "!no_lang",
|
|
|
|
"default": ""
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Options converted from the "options"-attribute.
|
|
|
|
*/
|
|
|
|
"font_style": {
|
|
|
|
"name": "Font Style",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Style may be a compositum of \"b\" and \"i\" which " +
|
|
|
|
" renders the text bold and/or italic."
|
|
|
|
},
|
|
|
|
"href": {
|
|
|
|
"name": "Link Target",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Link URL, empty if you don't wan't to display a link."
|
|
|
|
},
|
|
|
|
"activate_links": {
|
|
|
|
"name": "Replace URLs",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "If set, URLs in the text are automatically replaced " +
|
|
|
|
"by links"
|
|
|
|
},
|
2011-08-23 19:05:05 +02:00
|
|
|
"for": {
|
2011-08-10 16:36:31 +02:00
|
|
|
"name": "Label for widget",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Marks the text as label for the given widget."
|
|
|
|
},
|
|
|
|
"extra_link_target": {
|
|
|
|
"name": "Link target",
|
|
|
|
"type": "string",
|
|
|
|
"default": "_self",
|
|
|
|
"description": "Link target descriptor"
|
|
|
|
},
|
|
|
|
"extra_link_popup": {
|
|
|
|
"name": "Popup",
|
|
|
|
"type": "string",
|
2011-09-08 22:44:53 +02:00
|
|
|
"description": "widthxheight, if popup should be used, eg. 640x480"
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
"extra_link_title": {
|
|
|
|
"name": "Link Title",
|
|
|
|
"type": "string",
|
2011-08-24 09:18:59 +02:00
|
|
|
"description": "Link title which is displayed on mouse over.",
|
|
|
|
"translate": true
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-23 19:05:05 +02:00
|
|
|
legacyOptions: ["font_style", "href", "activate_links", "for",
|
2011-08-10 16:36:31 +02:00
|
|
|
"extra_link_target", "extra_link_popup", "extra_link_title"],
|
2011-08-05 16:53:54 +02:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @memberOf et2_description
|
|
|
|
*/
|
2011-08-24 12:05:52 +02:00
|
|
|
init: function() {
|
2011-08-10 16:36:31 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-08-22 12:50:55 +02:00
|
|
|
// Create the span/label tag which contains the label text
|
2011-08-23 19:05:05 +02:00
|
|
|
this.span = $j(document.createElement(this.options["for"] ? "label" : "span"))
|
2011-08-07 15:43:46 +02:00
|
|
|
.addClass("et2_label");
|
2011-08-05 16:53:54 +02:00
|
|
|
|
2011-08-23 19:05:05 +02:00
|
|
|
if (this.options["for"])
|
2011-08-22 10:58:20 +02:00
|
|
|
{
|
|
|
|
// TODO: Get the real id of the widget in the doLoadingFinished method.
|
2011-08-23 19:05:05 +02:00
|
|
|
this.span.attr("for", this.options["for"]);
|
2011-08-22 10:58:20 +02:00
|
|
|
}
|
|
|
|
|
2011-09-06 18:50:38 +02:00
|
|
|
et2_insertLinkText(this._parseText(this.options.value), this.span[0],
|
|
|
|
this.options.extra_link_target);
|
2011-08-22 12:50:55 +02:00
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
this.setDOMNode(this.span[0]);
|
2011-08-05 16:53:54 +02:00
|
|
|
},
|
|
|
|
|
2011-09-08 20:36:09 +02:00
|
|
|
transformAttributes: function(_attrs) {
|
2012-03-02 13:13:20 +01:00
|
|
|
this._super.apply(this, arguments);
|
2011-09-08 20:36:09 +02:00
|
|
|
|
|
|
|
if (this.id)
|
|
|
|
{
|
|
|
|
var val = this.getArrayMgr("content").getEntry(this.id);
|
|
|
|
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
_attrs["value"] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-02-13 10:23:33 +01:00
|
|
|
set_value: function(_value) {
|
2013-02-13 10:49:43 +01:00
|
|
|
if(!_value) _value = "";
|
2013-05-03 13:46:26 +02:00
|
|
|
else
|
|
|
|
if (!this.options.no_lang) _value = this.egw().lang(_value);
|
2013-02-13 10:04:17 +01:00
|
|
|
et2_insertLinkText(this._parseText(_value),
|
|
|
|
this.span[0],
|
|
|
|
this.options.extra_link_target
|
|
|
|
);
|
|
|
|
if(this.options.extra_link_popup)
|
|
|
|
{
|
|
|
|
var href = this.options.href;
|
|
|
|
var title = this.options.extra_link_title;
|
|
|
|
var popup = this.options.extra_link_popup;
|
2013-03-13 19:36:01 +01:00
|
|
|
jQuery('a',this.span)
|
2013-02-13 10:04:17 +01:00
|
|
|
.click(function(e) {
|
|
|
|
egw.open_link(href, title,popup);
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-09-06 18:50:38 +02:00
|
|
|
_parseText: function(_value) {
|
2011-08-22 12:50:55 +02:00
|
|
|
if (this.options.href)
|
|
|
|
{
|
2013-02-06 16:05:31 +01:00
|
|
|
var href = this.options.href;
|
|
|
|
if (href.indexOf('/')==-1 && href.split('.').length >= 3 &&
|
|
|
|
!(href.indexOf('mailto:')!=-1 || href.indexOf('://') != -1 || href.indexOf('javascript:') != -1)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
href = "/index.php?menuaction="+href;
|
|
|
|
}
|
|
|
|
if (href.charAt(0) == '/') // link relative to eGW
|
|
|
|
{
|
|
|
|
href = egw.link(href);
|
|
|
|
}
|
2011-08-22 12:50:55 +02:00
|
|
|
return [{
|
2013-02-06 16:05:31 +01:00
|
|
|
"href": href,
|
2011-09-06 18:50:38 +02:00
|
|
|
"text": _value
|
2011-08-22 12:50:55 +02:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
else if (this.options.activate_links)
|
|
|
|
{
|
2011-09-06 18:50:38 +02:00
|
|
|
return et2_activateLinks(_value);
|
2011-08-22 12:50:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-06 18:50:38 +02:00
|
|
|
return [_value];
|
2011-08-22 12:50:55 +02:00
|
|
|
}
|
2011-08-05 16:53:54 +02:00
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
set_font_style: function(_value) {
|
2011-08-16 14:31:18 +02:00
|
|
|
this.font_style = _value;
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2011-08-16 14:31:18 +02:00
|
|
|
this.span.toggleClass("et2_bold", _value.indexOf("b") >= 0);
|
|
|
|
this.span.toggleClass("et2_italic", _value.indexOf("i") >= 0);
|
2011-09-06 18:50:38 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code for implementing et2_IDetachedDOM
|
|
|
|
*/
|
|
|
|
|
|
|
|
getDetachedAttributes: function(_attrs)
|
|
|
|
{
|
2011-10-25 00:56:50 +02:00
|
|
|
_attrs.push("value", "class", "href");
|
2011-09-06 18:50:38 +02:00
|
|
|
},
|
2011-08-05 16:53:54 +02:00
|
|
|
|
2011-09-06 18:50:38 +02:00
|
|
|
getDetachedNodes: function()
|
|
|
|
{
|
|
|
|
return [this.span[0]];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values)
|
|
|
|
{
|
2012-03-12 14:19:13 +01:00
|
|
|
// Update the properties
|
|
|
|
var updateLink = false;
|
2011-10-25 00:56:50 +02:00
|
|
|
if (typeof _values["href"] != "undefined")
|
|
|
|
{
|
2012-03-12 14:19:13 +01:00
|
|
|
updateLink = true;
|
2011-10-25 00:56:50 +02:00
|
|
|
this.options.href = _values["href"];
|
|
|
|
}
|
2012-03-02 13:13:20 +01:00
|
|
|
|
2012-07-11 01:13:05 +02:00
|
|
|
if (typeof _values["value"] != "undefined" || (updateLink && (_values["value"] || this.options.value)))
|
2011-09-06 18:50:38 +02:00
|
|
|
{
|
2013-02-13 10:04:17 +01:00
|
|
|
this.span = jQuery(_nodes[0]);
|
2013-02-13 10:23:33 +01:00
|
|
|
this.set_value(_values["value"]);
|
2011-09-06 18:50:38 +02:00
|
|
|
}
|
2011-09-08 20:36:09 +02:00
|
|
|
|
|
|
|
if (typeof _values["class"] != "undefined")
|
|
|
|
{
|
2012-03-12 14:19:13 +01:00
|
|
|
_nodes[0].setAttribute("class", _values["class"]);
|
2011-09-08 20:36:09 +02:00
|
|
|
}
|
2011-09-06 18:50:38 +02:00
|
|
|
}
|
2011-08-05 16:53:54 +02:00
|
|
|
});
|
2011-08-06 16:36:44 +02:00
|
|
|
et2_register_widget(et2_description, ["description", "label"]);
|
2011-08-05 16:53:54 +02:00
|
|
|
|