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$
* /
/ * 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
2014-02-03 10:54:45 +01:00
*
2013-04-13 21:00:13 +02:00
* @ augments et2 _valueWidget
2014-02-03 10:54:45 +01:00
* /
2016-02-29 21:40:43 +01:00
var et2 _progress = ( function ( ) { "use strict" ; return 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
2014-02-03 10:54:45 +01:00
*
2013-04-13 21:00:13 +02:00
* @ memberOf et2 _progress
* /
2014-02-03 10:54:45 +01:00
init : function ( )
2011-09-09 10:29:31 +02:00
{
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
2014-02-03 10:54:45 +01:00
if ( this . options . href )
2011-09-09 10:29:31 +02:00
{
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
} ,
2014-02-03 10:54:45 +01:00
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
2014-02-03 10:54:45 +01:00
set _value : function ( _value )
2011-09-09 10:29:31 +02:00
{
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 ) ;
} ,
2014-02-03 10:54:45 +01:00
2011-09-09 10:29:31 +02:00
// set's label as title of this.node
2014-02-03 10:54:45 +01:00
set _label : function ( _value )
2011-09-09 10:29:31 +02:00
{
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
2014-02-03 10:54:45 +01:00
set _class : function ( _value )
2013-10-18 10:50:53 +02:00
{
2014-02-03 10:54:45 +01:00
var baseClass = "et2_progress" ;
if ( this . options . href )
2013-10-18 11:47:29 +02:00
{
baseClass += ' et2_clickable' ;
}
this . node . setAttribute ( 'class' , baseClass + ' ' + _value ) ;
2013-10-18 10:50:53 +02:00
} ,
2014-02-03 10:54:45 +01:00
set _href : function ( _value )
{
if ( ! this . isInTree ( ) )
{
return false ;
}
this . options . href = _value ;
2016-02-25 14:12:25 +01:00
if ( _value )
2014-02-03 10:54:45 +01:00
{
2016-02-25 14:12:25 +01:00
jQuery ( this . node ) . addClass ( 'et2_clickable' )
. wrapAll ( '<a href="' + _value + '"></a>"' ) ;
var href = this . options . href ;
var popup = this . options . extra _link _popup ;
var target = this . options . extra _link _target ;
jQuery ( this . node ) . parent ( ) . click ( function ( e )
{
egw . open _link ( href , target , popup ) ;
e . preventDefault ( ) ;
return false ;
} ) ;
}
else if ( jQuery ( this . node ) . parent ( 'a' ) . length )
{
jQuery ( this . node ) . removeClass ( 'et2_clickable' )
. unwrap ( ) ;
}
2014-02-03 10:54:45 +01:00
return true ;
} ,
2011-09-09 10:29:31 +02:00
/ * *
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
2014-02-03 10:54:45 +01:00
*
* * @ param { array } _attrs array to add further attributes to
2011-09-09 10:29:31 +02:00
* /
getDetachedAttributes : function ( _attrs ) {
2014-02-03 10:54:45 +01:00
_attrs . push ( "value" , "label" , "href" ) ;
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" ] ) ;
}
2014-02-03 10:54:45 +01:00
if ( _values [ "href" ] )
{
jQuery ( this . node ) . addClass ( 'et2_clickable' ) ;
this . set _href ( _values [ "href" ] ) ;
}
2011-09-09 14:17:16 +02:00
}
2016-02-29 21:40:43 +01:00
} ) ; } ) . call ( this ) ;
2011-09-09 10:29:31 +02:00
et2 _register _widget ( et2 _progress , [ "progress" ] ) ;