2020-02-10 15:29:27 +01:00
"use strict" ;
2016-02-29 21:40:43 +01:00
/ *
2014-09-30 23:37:45 +02:00
* Egroupware etemplate2 JS Entry widget
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ package etemplate
* @ subpackage api
* @ link http : //www.egroupware.org
* @ author Nathan Gray
* /
2020-02-10 15:29:27 +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 } ) ;
2014-09-30 23:37:45 +02:00
/ * e g w : u s e s
2020-02-10 15:29:27 +01:00
et2 _core _valueWidget ;
2014-09-30 23:37:45 +02:00
* /
2020-02-10 15:29:27 +01:00
var et2 _core _widget _1 = require ( "./et2_core_widget" ) ;
var et2 _core _valueWidget _1 = require ( "./et2_core_valueWidget" ) ;
var et2 _core _inheritance _1 = require ( "./et2_core_inheritance" ) ;
2014-09-30 23:37:45 +02:00
/ * *
* A widget to display a value from an entry
*
2016-03-19 17:16:59 +01:00
* Since we have Etemplate \ Widget \ Transformer , this client side widget exists
2014-09-30 23:37:45 +02:00
* mostly to resolve the problem where the ID for the entry widget is the same
* as the widget where you actually set the value , which prevents transformer
* from working .
*
* Server side will find the associated entry , and load it into ~ < entry _id > to
* avoid overwriting the widget with id = "entry_id" . This widget will reverse
* that , and the modifications from transformer will be applied .
*
* @ augments et2 _valueWidget
* /
2020-02-10 15:29:27 +01:00
var et2 _entry = /** @class */ ( function ( _super ) {
_ _extends ( et2 _entry , _super ) ;
function et2 _entry ( _parent , _attrs , _child ) {
var _this =
// Call the inherited constructor
_super . call ( this , _parent , _attrs , et2 _core _inheritance _1 . ClassWithAttributes . extendAttributes ( et2 _entry . _attributes , _child || { } ) ) || this ;
_this . widget = null ;
// Often the ID conflicts, so check prefix
if ( _attrs . id && _attrs . id . indexOf ( et2 _entry . prefix ) < 0 ) {
_attrs . id = et2 _entry . prefix + _attrs . id ;
}
var value = _attrs . value ;
_this = _super . call ( this , _parent , _attrs , et2 _core _inheritance _1 . ClassWithAttributes . extendAttributes ( et2 _entry . _attributes , _child || { } ) ) || this ;
// Save value from parsing, but only if set
if ( value ) {
_this . options . value = value ;
}
_this . widget = null ;
_this . setDOMNode ( document . createElement ( 'span' ) ) ;
return _this ;
}
et2 _entry . prototype . loadFromXML = function ( _node ) {
// Load the nodes as usual
_super . prototype . loadFromXML . call ( this , _node ) ;
// Do the magic
this . loadField ( ) ;
} ;
/ * *
* Initialize widget for entry field
* /
et2 _entry . prototype . loadField = function ( ) {
// Create widget of correct type
var attrs = {
id : this . id + ( this . options . field ? '[' + this . options . field + ']' : '' ) ,
type : 'label' ,
readonly : this . options . readonly
} ;
var modifications = this . getArrayMgr ( "modifications" ) ;
if ( modifications && this . options . field ) {
jQuery . extend ( attrs , modifications . getEntry ( attrs . id ) ) ;
}
// Supress labels on templates
if ( attrs . type == 'template' && this . options . label ) {
this . egw ( ) . debug ( 'log' , "Surpressed label on <" + this . getType ( ) + ' label="' + this . options . label + '" id="' + this . id + '"...>' ) ;
this . options . label = '' ;
}
var widget = et2 _createWidget ( attrs . type , attrs , this ) ;
// If value is not set, etemplate takes care of everything
// If value was set, find the record explicitly.
if ( typeof this . options . value == 'string' ) {
widget . options . value = this . getArrayMgr ( 'content' ) . getEntry ( this . id + '[' + this . options . field + ']' ) ||
this . getRoot ( ) . getArrayMgr ( 'content' ) . getEntry ( et2 _entry . prefix + this . options . value + '[' + this . options . field + ']' ) ;
}
else if ( this . options . field && this . options . value && this . options . value [ this . options . field ] ) {
widget . options . value = this . options . value [ this . options . field ] ;
}
if ( this . options . compare ) {
widget . options . value = widget . options . value == this . options . compare ? 'X' : '' ;
}
if ( this . options . alternate _fields ) {
var sum = 0 ;
var fields = this . options . alternate _fields . split ( ':' ) ;
for ( var i = 0 ; i < fields . length ; i ++ ) {
var negate = ( fields [ i ] [ 0 ] == "-" ) ;
var value = this . getArrayMgr ( 'content' ) . getEntry ( fields [ i ] . replace ( '-' , '' ) ) ;
sum += typeof value === 'undefined' ? 0 : ( parseFloat ( value ) * ( negate ? - 1 : 1 ) ) ;
if ( value && this . options . field !== 'sum' ) {
widget . options . value = value ;
break ;
}
}
if ( this . options . field == 'sum' ) {
if ( this . options . precision && jQuery . isNumeric ( sum ) )
sum = parseFloat ( sum ) . toFixed ( this . options . precision ) ;
widget . options . value = sum ;
}
}
} ;
et2 _entry . _attributes = {
field : {
'name' : 'Fields' ,
'description' : 'Which entry field to display, or "sum" to add up the alternate_fields' ,
'type' : 'string'
} ,
compare : {
name : 'Compare' ,
description : 'if given, the selected field is compared with its value and an X is printed on equality, nothing otherwise' ,
default : et2 _no _init ,
type : 'string'
} ,
alternate _fields : {
name : 'Alternate fields' ,
description : 'colon (:) separated list of alternative fields. The first non-empty one is used if the selected field is empty, (-) used for subtraction' ,
type : 'string' ,
default : et2 _no _init
} ,
precision : {
name : 'Decimals to be shown' ,
description : 'Specifies the number of decimals for sum of alternates, the default is 2' ,
type : 'string' ,
default : '2'
} ,
regex : {
name : 'Regular expression pattern' ,
description : 'Only used server-side in a preg_replace with regex_replace to modify the value' ,
default : et2 _no _init ,
type : 'string'
} ,
regex _replace : {
name : 'Regular expression replacement pattern' ,
description : 'Only used server-side in a preg_replace with regex to modify the value' ,
default : et2 _no _init ,
type : 'string'
} ,
value : {
type : 'any'
} ,
readonly : {
default : true
}
} ;
2020-03-30 18:28:48 +02:00
et2 _entry . legacyOptions = [ "field" , "compare" , "alternate_fields" ] ;
2020-08-06 10:37:56 +02:00
et2 _entry . prefix = '~' ;
2020-02-10 15:29:27 +01:00
return et2 _entry ;
} ( et2 _core _valueWidget _1 . et2 _valueWidget ) ) ;
et2 _core _widget _1 . et2 _register _widget ( et2 _entry , [ "entry" , 'contact-value' , 'contact-account' , 'contact-template' , 'infolog-value' , 'tracker-value' , 'records-value' ] ) ;
//# sourceMappingURL=et2_widget_entry.js.map