2011-09-09 10:29:31 +02:00
/ * *
* EGroupware eTemplate2 - JS Progrss object
*
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ package etemplate
* @ subpackage api
* @ link http : //www.egroupware.org
* @ author Ralf Becker
* @ version $Id$
* /
"use strict" ;
/ * e g w : u s e s
jquery . jquery ;
et2 _core _interfaces ;
2011-09-09 14:17:16 +02:00
et2 _core _valueWidget ;
2011-09-09 10:29:31 +02:00
* /
/ * *
2013-04-13 21:00:13 +02:00
* Class which implements the "progress" XET - Tag
*
* @ augments et2 _valueWidget
2011-09-09 10:29:31 +02:00
* /
2012-03-05 22:40:44 +01:00
var et2 _progress = et2 _valueWidget . extend ( [ et2 _IDetachedDOM ] ,
2011-09-09 14:17:16 +02:00
{
2011-09-09 10:29:31 +02:00
attributes : {
"href" : {
"name" : "Link Target" ,
"type" : "string" ,
"description" : "Link URL, empty if you don't wan't to display a link."
} ,
"extra_link_target" : {
"name" : "Link target" ,
"type" : "string" ,
"default" : "_self" ,
"description" : "Link target descriptor"
} ,
"extra_link_popup" : {
"name" : "Popup" ,
"type" : "string" ,
"description" : "widthxheight, if popup should be used, eg. 640x480"
} ,
"label" : {
2011-09-28 01:44:07 +02:00
"name" : "Label" ,
"default" : "" ,
"type" : "string" ,
"description" : "The label is displayed as the title. 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-09-09 10:29:31 +02:00
}
} ,
legacyOptions : [ "href" , "extra_link_target" , "imagemap" , "extra_link_popup" , "id" ] ,
2013-04-13 21:00:13 +02:00
/ * *
* Constructor
*
* @ memberOf et2 _progress
* /
2011-09-09 10:29:31 +02:00
init : function ( )
{
this . _super . apply ( this , arguments ) ;
2011-09-09 14:17:16 +02:00
var outer = document . createElement ( "div" ) ;
outer . className = "et2_progress" ;
this . progress = document . createElement ( "div" ) ;
this . progress . style . width = "0" ;
outer . appendChild ( this . progress ) ;
2011-09-09 10:29:31 +02:00
if ( this . options . href )
{
2011-09-09 14:17:16 +02:00
outer . className += ' et2_clickable' ;
2011-09-09 10:29:31 +02:00
}
if ( this . options [ "class" ] )
{
2011-09-09 14:17:16 +02:00
outer . className += ' ' + this . options [ "class" ] ;
2011-09-09 10:29:31 +02:00
}
2011-09-09 14:17:16 +02:00
this . setDOMNode ( outer ) ; // set's this.node = outer
2011-09-09 10:29:31 +02:00
} ,
click : function ( )
{
2011-09-09 14:17:16 +02:00
this . _super . apply ( this , arguments ) ;
2011-09-09 10:29:31 +02:00
if ( this . options . href )
{
2012-03-28 14:37:03 +02:00
this . egw ( ) . open _link ( this . options . href , this . options . extra _link _target , this . options . extra _link _popup ) ;
2011-09-09 14:17:16 +02:00
}
2011-09-09 10:29:31 +02:00
} ,
2011-09-09 14:17:16 +02:00
// setting the value as width of the progress-bar
2011-09-09 10:29:31 +02:00
set _value : function ( _value )
{
2011-09-09 14:17:16 +02:00
_value = parseInt ( _value ) + "%" ; // make sure we have percent attached
this . progress . style . width = _value ;
2011-09-09 10:29:31 +02:00
if ( ! this . options . label ) this . set _label ( _value ) ;
} ,
// set's label as title of this.node
set _label : function ( _value )
{
2011-09-09 14:17:16 +02:00
this . node . title = _value ;
} ,
2011-09-09 10:29:31 +02:00
2013-10-18 11:47:29 +02:00
// set's class of this.node; preserve baseclasses et2_progress and if this.options.href is set et2_clickable
2013-10-18 10:50:53 +02:00
set _class : function ( _value )
{
2013-10-18 11:47:29 +02:00
var baseClass = "et2_progress"
if ( this . options . href )
{
baseClass += ' et2_clickable' ;
}
this . node . setAttribute ( 'class' , baseClass + ' ' + _value ) ;
2013-10-18 10:50:53 +02:00
} ,
2011-09-09 10:29:31 +02:00
/ * *
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
* /
2011-09-09 14:17:16 +02:00
2011-09-09 10:29:31 +02:00
getDetachedAttributes : function ( _attrs ) {
2012-03-05 22:40:44 +01:00
_attrs . push ( "value" , "label" , "onclick" ) ;
2011-09-09 10:29:31 +02:00
} ,
getDetachedNodes : function ( ) {
2012-03-13 00:18:46 +01:00
return [ this . node , this . progress ] ;
2011-09-09 10:29:31 +02:00
} ,
setDetachedAttributes : function ( _nodes , _values ) {
// Set the given DOM-Nodes
2011-09-09 14:17:16 +02:00
this . node = _nodes [ 0 ] ;
2012-03-13 00:18:46 +01:00
this . progress = _nodes [ 1 ] ;
2011-09-09 10:29:31 +02:00
// Set the attributes
if ( _values [ "label" ] )
{
this . set _label ( _values [ "label" ] ) ;
}
2011-09-09 14:17:16 +02:00
if ( _values [ "value" ] )
{
this . set _value ( _values [ "value" ] ) ;
}
2012-04-05 22:19:32 +02:00
else if ( _values [ "label" ] )
{
this . set _value ( _values [ "label" ] ) ;
}
2011-09-09 14:17:16 +02:00
}
2011-09-09 10:29:31 +02:00
} ) ;
et2 _register _widget ( et2 _progress , [ "progress" ] ) ;