2011-08-10 16:36:31 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Widget base class
|
|
|
|
*
|
|
|
|
* @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: et2_widget.js 36021 2011-08-07 13:43:46Z igel457 $
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
|
|
|
et2_baseWidget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for all widgets which support returning a value
|
|
|
|
*/
|
|
|
|
var et2_IInput = new Interface({
|
|
|
|
/**
|
|
|
|
* getValue has to return the value of the input widget
|
|
|
|
*/
|
|
|
|
getValue: function() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is dirty returns true if the value of the widget has changed since it
|
|
|
|
* was loaded.
|
|
|
|
*/
|
|
|
|
isDirty: function() {},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Causes the dirty flag to be reseted.
|
|
|
|
*/
|
|
|
|
resetDirty: function() {}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* et2_inputWidget derrives from et2_simpleWidget and implements the IInput
|
|
|
|
* interface. When derriving from this class, call setDOMNode with an input
|
|
|
|
* DOMNode.
|
|
|
|
*/
|
2011-08-10 16:39:35 +02:00
|
|
|
var et2_inputWidget = et2_baseWidget.extend(et2_IInput, {
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
attributes: {
|
|
|
|
"value": {
|
|
|
|
"name": "Value",
|
|
|
|
"description": "The value of the widget",
|
|
|
|
"type": "string",
|
2011-08-10 18:23:02 +02:00
|
|
|
"default": et2_no_init
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this._oldValue = "";
|
|
|
|
},
|
|
|
|
|
2011-08-15 16:52:45 +02:00
|
|
|
loadingFinished: function() {
|
|
|
|
this._super.call(this, arguments);
|
|
|
|
|
|
|
|
if (this.id != "")
|
|
|
|
{
|
|
|
|
// Set the value for this element
|
|
|
|
var contentMgr = this.getArrayMgr("content");
|
|
|
|
var val = contentMgr.getValueForID(this.id);
|
|
|
|
if (val !== null)
|
|
|
|
{
|
|
|
|
this.set_value(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
set_value: function(_value) {
|
|
|
|
this._oldValue = _value;
|
|
|
|
|
2011-08-11 15:53:35 +02:00
|
|
|
var node = this.getInputNode();
|
|
|
|
if (node)
|
2011-08-10 16:36:31 +02:00
|
|
|
{
|
2011-08-11 15:53:35 +02:00
|
|
|
$j(node).val(_value);
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-10 19:44:22 +02:00
|
|
|
set_id: function(_value) {
|
2011-08-12 17:26:08 +02:00
|
|
|
this.id = _value;
|
|
|
|
|
2011-08-15 16:52:45 +02:00
|
|
|
// Set the id of the _input_ node (in contrast to the default
|
|
|
|
// implementation, which sets the base node)
|
2011-08-12 17:26:08 +02:00
|
|
|
var node = this.getInputNode();
|
|
|
|
if (node)
|
|
|
|
{
|
|
|
|
if (_value != "")
|
|
|
|
{
|
|
|
|
node.setAttribute("id", _value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node.removeAttribute("id");
|
|
|
|
}
|
|
|
|
}
|
2011-08-10 19:44:22 +02:00
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
get_value: function() {
|
|
|
|
return this.getValue();
|
|
|
|
},
|
|
|
|
|
2011-08-11 15:53:35 +02:00
|
|
|
getInputNode: function() {
|
|
|
|
return this.node;
|
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
getValue: function() {
|
2011-08-11 15:53:35 +02:00
|
|
|
var node = this.getInputNode();
|
|
|
|
if (node)
|
2011-08-10 16:36:31 +02:00
|
|
|
{
|
2011-08-12 14:15:44 +02:00
|
|
|
var val = $j(node).val();
|
|
|
|
|
|
|
|
return val;
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this._oldValue;
|
|
|
|
},
|
|
|
|
|
|
|
|
isDirty: function() {
|
|
|
|
return this._oldValue != this.getValue();
|
|
|
|
},
|
|
|
|
|
|
|
|
resetDirty: function() {
|
|
|
|
this._oldValue = this.getValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|