2020-01-21 12:15:46 +01:00
"use strict" ;
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$
* /
2020-01-21 12:15:46 +01:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2021-03-22 18:42:50 +01:00
exports . et2 _valueWidget = void 0 ;
2011-08-16 14:31:18 +02:00
/ * e g w : u s e s
2020-01-21 12:15:46 +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 _baseWidget ;
2011-08-16 14:31:18 +02:00
* /
2020-01-21 12:48:48 +01:00
var et2 _core _baseWidget _1 = require ( "./et2_core_baseWidget" ) ;
2020-01-21 12:15:46 +01:00
require ( "./et2_core_common" ) ;
2020-01-22 18:38:33 +01:00
var et2 _core _inheritance _1 = require ( "./et2_core_inheritance" ) ;
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 .
* /
2020-01-21 12:15:46 +01:00
var et2 _valueWidget = /** @class */ ( function ( _super ) {
_ _extends ( et2 _valueWidget , _super ) ;
2020-01-22 18:38:33 +01:00
/ * *
* Constructor
* /
function et2 _valueWidget ( _parent , _attrs , _child ) {
var _this =
// Call the inherited constructor
_super . call ( this , _parent , _attrs , et2 _core _inheritance _1 . ClassWithAttributes . extendAttributes ( et2 _valueWidget . _attributes , _child || { } ) ) || this ;
2020-01-21 12:48:48 +01:00
_this . label = '' ;
_this . _labelContainer = null ;
return _this ;
2020-01-21 12:15:46 +01:00
}
/ * *
*
* @ param _attrs
* /
et2 _valueWidget . prototype . transformAttributes = function ( _attrs ) {
_super . prototype . transformAttributes . call ( this , _attrs ) ;
if ( this . id ) {
// Set the value for this element
var contentMgr = this . getArrayMgr ( "content" ) ;
if ( contentMgr != null ) {
var val = contentMgr . getEntry ( this . id , false , true ) ;
if ( val !== null ) {
_attrs [ "value" ] = val ;
}
}
// Check for already inside namespace
2020-02-11 23:19:33 +01:00
if ( this . _createNamespace ( ) && this . getArrayMgr ( "content" ) . perspectiveData . owner == this ) {
2020-01-21 12:15:46 +01:00
_attrs [ "value" ] = this . getArrayMgr ( "content" ) . data ;
}
}
} ;
et2 _valueWidget . prototype . set _label = function ( _value ) {
// Abort if there 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 = jQuery ( 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 ) ;
}
}
// add class if label is empty
this . _labelContainer . toggleClass ( 'et2_label_empty' , ! _value || ! parts [ 0 ] ) ;
}
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 ( ) ;
// Copy the given value
this . label = _value ;
} ;
et2 _valueWidget . _attributes = {
"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
} ,
"value" : {
"name" : "Value" ,
"description" : "The value of the widget" ,
"type" : "rawstring" ,
"default" : et2 _no _init
}
} ;
return et2 _valueWidget ;
2020-01-21 12:48:48 +01:00
} ( et2 _core _baseWidget _1 . et2 _baseWidget ) ) ;
exports . et2 _valueWidget = et2 _valueWidget ;
2020-01-21 19:45:21 +01:00
//# sourceMappingURL=et2_core_valueWidget.js.map