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
2021-06-07 17:33:53 +02:00
* @ link https : //www.egroupware.org
2011-09-09 10:29:31 +02:00
* @ author Ralf Becker
* /
/ * e g w : u s e s
2020-02-10 15:00:48 +01:00
/ v e n d o r / b o w e r - a s s e t / j q u e r y / d i s t / j q u e r y . j s ;
et2 _core _interfaces ;
et2 _core _valueWidget ;
2011-09-09 10:29:31 +02:00
* /
2021-06-07 17:33:53 +02:00
import { et2 _register _widget } from "./et2_core_widget" ;
import { et2 _valueWidget } from "./et2_core_valueWidget" ;
import { ClassWithAttributes } from "./et2_core_inheritance" ;
import { egw } from "../jsapi/egw_global" ;
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
* /
2021-06-07 17:33:53 +02:00
export class et2 _progress extends et2 _valueWidget {
2020-02-10 15:00:48 +01:00
/ * *
* Constructor
*
* @ memberOf et2 _progress
* /
2021-06-07 17:33:53 +02:00
constructor ( _parent , _attrs , _child ) {
2020-02-10 15:00:48 +01:00
// Call the inherited constructor
2021-06-07 17:33:53 +02:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2 _progress . _attributes , _child || { } ) ) ;
this . progress = null ;
let outer = document . createElement ( "div" ) ;
2020-02-10 15:00:48 +01:00
outer . className = "et2_progress" ;
2021-06-07 17:33:53 +02:00
this . progress = document . createElement ( "div" ) ;
this . progress . style . width = "0" ;
outer . appendChild ( this . progress ) ;
if ( this . options . href ) {
2020-02-10 15:00:48 +01:00
outer . className += ' et2_clickable' ;
}
2021-06-07 17:33:53 +02:00
if ( this . options [ "class" ] ) {
outer . className += ' ' + this . options [ "class" ] ;
2020-02-10 15:00:48 +01:00
}
2021-06-07 17:33:53 +02:00
this . setDOMNode ( outer ) ; // set's this.node = outer
2020-02-10 15:00:48 +01:00
}
2021-06-07 17:33:53 +02:00
click ( e ) {
super . click ( e ) ;
2020-02-10 15:00:48 +01:00
if ( this . options . href ) {
this . egw ( ) . open _link ( this . options . href , this . options . extra _link _target , this . options . extra _link _popup ) ;
}
2021-06-07 17:33:53 +02:00
}
2020-02-10 15:00:48 +01:00
// setting the value as width of the progress-bar
2021-06-07 17:33:53 +02:00
set _value ( _value ) {
super . set _value ( _value ) ;
2020-02-10 15:00:48 +01:00
_value = parseInt ( _value ) + "%" ; // make sure we have percent attached
this . progress . style . width = _value ;
if ( ! this . options . label )
this . set _label ( _value ) ;
2021-06-07 17:33:53 +02:00
}
2020-02-10 15:00:48 +01:00
// set's label as title of this.node
2021-06-07 17:33:53 +02:00
set _label ( _value ) {
2020-02-10 15:00:48 +01:00
this . node . title = _value ;
2021-06-07 17:33:53 +02:00
}
2020-02-10 15:00:48 +01:00
// set's class of this.node; preserve baseclasses et2_progress and if this.options.href is set et2_clickable
2021-06-07 17:33:53 +02:00
set _class ( _value ) {
let baseClass = "et2_progress" ;
2020-02-10 15:00:48 +01:00
if ( this . options . href ) {
baseClass += ' et2_clickable' ;
}
this . node . setAttribute ( 'class' , baseClass + ' ' + _value ) ;
2021-06-07 17:33:53 +02:00
}
set _href ( _value ) {
2020-02-10 15:00:48 +01:00
if ( ! this . isInTree ( ) ) {
return false ;
}
this . options . href = _value ;
if ( _value ) {
jQuery ( this . node ) . addClass ( 'et2_clickable' )
. wrapAll ( '<a href="' + _value + '"></a>"' ) ;
2021-06-07 17:33:53 +02:00
let href = this . options . href ;
let popup = this . options . extra _link _popup ;
let target = this . options . extra _link _target ;
2020-02-10 15:00:48 +01:00
jQuery ( this . node ) . parent ( ) . click ( function ( e ) {
2021-06-07 17:33:53 +02:00
egw . open _link ( href , target , popup ) ;
2020-02-10 15:00:48 +01:00
e . preventDefault ( ) ;
return false ;
} ) ;
}
else if ( jQuery ( this . node ) . parent ( 'a' ) . length ) {
jQuery ( this . node ) . removeClass ( 'et2_clickable' )
. unwrap ( ) ;
}
return true ;
2021-06-07 17:33:53 +02:00
}
2020-02-10 15:00:48 +01:00
/ * *
* Implementation of "et2_IDetachedDOM" for fast viewing in gridview
*
* * @ param { array } _attrs array to add further attributes to
* /
2021-06-07 17:33:53 +02:00
getDetachedAttributes ( _attrs ) {
2020-02-10 15:00:48 +01:00
_attrs . push ( "value" , "label" , "href" ) ;
2021-06-07 17:33:53 +02:00
}
getDetachedNodes ( ) {
2020-02-10 15:00:48 +01:00
return [ this . node , this . progress ] ;
2021-06-07 17:33:53 +02:00
}
setDetachedAttributes ( _nodes , _values ) {
2020-02-10 15:00:48 +01:00
// Set the given DOM-Nodes
this . node = _nodes [ 0 ] ;
this . progress = _nodes [ 1 ] ;
// Set the attributes
if ( _values [ "label" ] ) {
this . set _label ( _values [ "label" ] ) ;
}
if ( _values [ "value" ] ) {
this . set _value ( _values [ "value" ] ) ;
}
else if ( _values [ "label" ] ) {
this . set _value ( _values [ "label" ] ) ;
}
if ( _values [ "href" ] ) {
jQuery ( this . node ) . addClass ( 'et2_clickable' ) ;
this . set _href ( _values [ "href" ] ) ;
}
2021-06-07 17:33:53 +02:00
}
}
et2 _progress . _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" : {
"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
}
} ;
et2 _progress . legacyOptions = [ "href" , "extra_link_target" , "imagemap" , "extra_link_popup" , "id" ] ;
et2 _register _widget ( et2 _progress , [ "progress" ] ) ;
2020-02-10 15:00:48 +01:00
//# sourceMappingURL=et2_widget_progress.js.map