2011-08-16 14:31:18 +02:00
/ * *
2013-04-13 21:00:13 +02:00
* EGroupware eTemplate2 - JS widget class with value attribute and auto loading
2011-08-16 14:31:18 +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-16 14:56:55 +02:00
"use strict" ;
2011-08-16 14:31:18 +02:00
/ * e g w : u s e s
jquery . jquery ;
2011-08-24 12:18:07 +02:00
et2 _core _baseWidget ;
2011-08-16 14:31:18 +02:00
* /
/ * *
* et2 _valueWidget is the base class for et2 _inputWidget - valueWidget introduces
* the "value" attribute and automatically loads it from the "content" array
* after loading from XML .
2013-04-13 21:00:13 +02:00
*
* @ augments et2 _baseWidget
2011-08-16 14:31:18 +02:00
* /
2013-04-13 21:00:13 +02:00
var et2 _valueWidget = et2 _baseWidget . extend (
{
2011-08-16 14:31:18 +02:00
attributes : {
2012-07-11 22:08:32 +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)." ,
"translate" : true
} ,
2011-08-16 14:31:18 +02:00
"value" : {
"name" : "Value" ,
"description" : "The value of the widget" ,
"type" : "string" ,
"default" : et2 _no _init
}
} ,
2013-04-13 21:00:13 +02:00
/ * *
*
*
* @ memberOf et2 _valueWidget
* @ param _attrs
* /
2011-08-21 17:22:00 +02:00
transformAttributes : function ( _attrs ) {
2011-08-23 17:27:34 +02:00
this . _super . apply ( this , arguments ) ;
2011-08-16 14:31:18 +02:00
2011-08-23 19:05:05 +02:00
if ( this . id )
2011-08-16 14:31:18 +02:00
{
// Set the value for this element
var contentMgr = this . getArrayMgr ( "content" ) ;
2011-08-19 18:00:44 +02:00
if ( contentMgr != null ) {
2011-09-08 20:36:09 +02:00
var val = contentMgr . getEntry ( this . id ) ;
2011-08-16 23:18:26 +02:00
if ( val !== null )
{
2011-08-19 18:00:44 +02:00
_attrs [ "value" ] = val ;
2011-08-16 23:18:26 +02:00
}
2011-08-16 14:31:18 +02:00
}
2013-05-22 20:13:37 +02:00
// Check for already inside namespace
if ( this . createNamespace && this . getArrayMgr ( "content" ) . perspectiveData . owner == this )
{
_attrs [ "value" ] = this . getArrayMgr ( "content" ) . data ;
}
2011-08-16 14:31:18 +02:00
}
2013-07-04 22:42:21 +02:00
} ,
set _label : function ( _value ) {
// Abort if ther was no change in the label
if ( _value == this . label )
{
return ;
}
if ( _value )
{
// Create the label container if it didn't exist yet
if ( this . _labelContainer == null )
{
this . _labelContainer = $j ( document . createElement ( "label" ) )
. addClass ( "et2_label" ) ;
this . getSurroundings ( ) . insertDOMNode ( this . _labelContainer [ 0 ] ) ;
}
// Clear the label container.
this . _labelContainer . empty ( ) ;
// Create the placeholder element and set it
var ph = document . createElement ( "span" ) ;
this . getSurroundings ( ) . setWidgetPlaceholder ( ph ) ;
// Split the label at the "%s"
var parts = et2 _csvSplit ( _value , 2 , "%s" ) ;
// Update the content of the label container
for ( var i = 0 ; i < parts . length ; i ++ )
{
if ( parts [ i ] )
{
this . _labelContainer . append ( document . createTextNode ( parts [ i ] ) ) ;
}
if ( i == 0 )
{
this . _labelContainer . append ( ph ) ;
}
}
}
else
{
// Delete the labelContainer from the surroundings object
if ( this . _labelContainer )
{
this . getSurroundings ( ) . removeDOMNode ( this . _labelContainer [ 0 ] ) ;
}
this . _labelContainer = null ;
}
// Update the surroundings in order to reflect the change in the label
this . getSurroundings ( ) . update ( ) ;
2011-08-16 14:31:18 +02:00
2013-07-04 22:42:21 +02:00
// Copy the given value
this . label = _value ;
}
2011-08-16 14:31:18 +02:00
} ) ;