forked from extern/egroupware
133 lines
2.3 KiB
JavaScript
133 lines
2.3 KiB
JavaScript
/**
|
|
* 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$
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
/*egw:uses
|
|
jquery.jquery;
|
|
et2_valueWidget;
|
|
*/
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
var et2_inputWidget = et2_valueWidget.extend(et2_IInput, {
|
|
|
|
attributes: {
|
|
"required": {
|
|
"name": "Required",
|
|
"default": false,
|
|
"type": "boolean",
|
|
"description": "If required, the user must enter a value before the form can be submitted"
|
|
}
|
|
},
|
|
init: function() {
|
|
this._super.apply(this, arguments);
|
|
|
|
this._oldValue = "";
|
|
},
|
|
|
|
set_value: function(_value) {
|
|
this._oldValue = _value;
|
|
|
|
var node = this.getInputNode();
|
|
if (node)
|
|
{
|
|
$j(node).val(_value);
|
|
}
|
|
},
|
|
|
|
set_id: function(_value) {
|
|
this.id = _value;
|
|
|
|
// Set the id of the _input_ node (in contrast to the default
|
|
// implementation, which sets the base node)
|
|
var node = this.getInputNode();
|
|
if (node)
|
|
{
|
|
if (_value != "")
|
|
{
|
|
node.setAttribute("id", _value);
|
|
}
|
|
else
|
|
{
|
|
node.removeAttribute("id");
|
|
}
|
|
}
|
|
},
|
|
set_required: function(_value) {
|
|
var node = this.getInputNode();
|
|
if (node)
|
|
{
|
|
if(_value) {
|
|
$j(node).attr("required", "required");
|
|
} else {
|
|
node.removeAttribute("required");
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
get_value: function() {
|
|
return this.getValue();
|
|
},
|
|
|
|
getInputNode: function() {
|
|
return this.node;
|
|
},
|
|
|
|
getValue: function() {
|
|
var node = this.getInputNode();
|
|
if (node)
|
|
{
|
|
var val = $j(node).val();
|
|
|
|
return val;
|
|
}
|
|
|
|
return this._oldValue;
|
|
},
|
|
|
|
isDirty: function() {
|
|
return this._oldValue != this.getValue();
|
|
},
|
|
|
|
resetDirty: function() {
|
|
this._oldValue = this.getValue();
|
|
}
|
|
|
|
});
|
|
|