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
2011-08-16 15:12:39 +02:00
* @ version $Id$
2011-08-10 16:36:31 +02:00
* /
"use strict" ;
/ * e g w : u s e s
jquery . jquery ;
2011-08-16 14:31:18 +02:00
et2 _valueWidget ;
2011-08-10 16:36:31 +02:00
* /
/ * *
* 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-16 14:31:18 +02:00
var et2 _inputWidget = et2 _valueWidget . extend ( et2 _IInput , {
2011-08-10 16:36:31 +02:00
2011-08-16 23:18:26 +02:00
attributes : {
"required" : {
"name" : "Required" ,
"default" : false ,
"type" : "boolean" ,
"description" : "If required, the user must enter a value before the form can be submitted"
2011-08-18 00:56:49 +02:00
} ,
"label" : {
"name" : "Label" ,
"default" : "" ,
"type" : "string" ,
"description" : "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables)."
2011-08-16 23:18:26 +02:00
}
} ,
2011-08-10 16:36:31 +02:00
init : function ( ) {
this . _super . apply ( this , arguments ) ;
this . _oldValue = "" ;
} ,
2011-08-17 23:36:08 +02:00
attachToDOM : function ( ) {
this . _super . apply ( this , arguments ) ;
$j ( this . getInputNode ( ) ) . attr ( "novalidate" , "novalidate" ) ; // Stop browser from getting involved
$j ( this . getInputNode ( ) ) . validator ( ) ;
} ,
2011-08-19 18:00:44 +02:00
2011-08-17 23:36:08 +02:00
detatchFromDOM : function ( ) {
if ( this . getInputNode ( ) ) {
$j ( this . getInputNode ( ) ) . data ( "validator" ) . destroy ( ) ;
}
this . _super . apply ( this , arguments ) ;
} ,
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 ) ;
2011-08-17 23:36:08 +02:00
node . setAttribute ( "name" , _value ) ;
2011-08-12 17:26:08 +02:00
}
else
{
node . removeAttribute ( "id" ) ;
2011-08-17 23:36:08 +02:00
node . removeAttribute ( "name" ) ;
2011-08-12 17:26:08 +02:00
}
}
2011-08-10 19:44:22 +02:00
} ,
2011-08-18 00:56:49 +02:00
set _label : function ( _label ) {
if ( _label != this . label )
{
2011-08-18 01:26:01 +02:00
this . label = ( typeof _label == 'undefined' ? "" : _label ) ;
var label = et2 _csvSplit ( _label , 2 , '%s' ) ;
if ( label [ 0 ] ) $j ( this . getInputNode ( ) ) . before ( "<span class='et2_label'>" + label [ 0 ] + "</span>" ) ;
if ( label [ 1 ] ) $j ( this . getInputNode ( ) ) . after ( "<span class='et2_label'>" + label [ 1 ] + "</span>" ) ;
2011-08-18 00:56:49 +02:00
}
} ,
2011-08-16 19:02:09 +02:00
set _required : function ( _value ) {
var node = this . getInputNode ( ) ;
if ( node )
{
if ( _value ) {
$j ( node ) . attr ( "required" , "required" ) ;
} else {
node . removeAttribute ( "required" ) ;
}
}
2011-08-16 23:18:26 +02:00
2011-08-16 19:02:09 +02:00
} ,
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 ( ) ;
}
} ) ;