2020-01-21 17:51:44 +01:00
"use strict" ;
2011-08-05 16:53:54 +02:00
/ * *
2013-04-13 21:00:13 +02:00
* EGroupware eTemplate2 - JS Description object
2011-08-05 16:53:54 +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
* /
2020-01-21 17:51:44 +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 _ _ ( ) ) ;
} ;
} ) ( ) ;
2020-02-19 17:14:44 +01:00
var _a ;
2020-01-21 17:51:44 +01:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2021-03-22 18:42:50 +01:00
exports . et2 _description = void 0 ;
2011-08-05 16:53:54 +02:00
/ * e g w : u s e s
2020-01-21 17:51:44 +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 ;
expose ;
2011-08-05 16:53:54 +02:00
* /
2020-01-21 17:51:44 +01:00
require ( "./et2_core_common" ) ;
var et2 _core _inheritance _1 = require ( "./et2_core_inheritance" ) ;
var et2 _core _widget _1 = require ( "./et2_core_widget" ) ;
var et2 _core _baseWidget _1 = require ( "./et2_core_baseWidget" ) ;
2011-08-05 16:53:54 +02:00
/ * *
* Class which implements the "description" XET - Tag
2013-11-11 15:16:18 +01:00
* /
2020-02-20 17:46:53 +01:00
var et2 _description = /** @class */ ( function ( _super ) {
_ _extends ( et2 _description , _super ) ;
function et2 _description ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
return et2 _description ;
} ( expose ( ( _a = /** @class */ ( function ( _super ) {
2020-02-19 17:14:44 +01:00
_ _extends ( et2 _description , _super ) ;
/ * *
* Constructor
* /
function et2 _description ( _parent , _attrs , _child ) {
var _this =
// Call the inherited constructor
_super . call ( this , _parent , _attrs , et2 _core _inheritance _1 . ClassWithAttributes . extendAttributes ( et2 _description . _attributes , _child || { } ) ) || this ;
_this . _labelContainer = null ;
// Create the span/label tag which contains the label text
_this . span = jQuery ( document . createElement ( _this . options [ "for" ] ? "label" : "span" ) )
. addClass ( "et2_label" ) ;
et2 _insertLinkText ( _this . _parseText ( _this . options . value ) , _this . span [ 0 ] , _this . options . href ? _this . options . extra _link _target : '_blank' ) ;
_this . setDOMNode ( _this . span [ 0 ] ) ;
return _this ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
et2 _description . prototype . transformAttributes = function ( _attrs ) {
_super . prototype . transformAttributes . call ( this , _attrs ) ;
if ( this . id ) {
var val = this . getArrayMgr ( "content" ) . getEntry ( this . id ) ;
if ( val ) {
_attrs [ "value" ] = val ;
}
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
} ;
et2 _description . prototype . doLoadingFinished = function ( ) {
_super . prototype . doLoadingFinished . call ( this ) ;
// Get the real id of the 'for' widget
var for _widget = null ;
if ( this . options [ "for" ] && ( ( for _widget = this . getParent ( ) . getWidgetById ( this . options . for ) ) ||
( for _widget = this . getRoot ( ) . getWidgetById ( this . options . for ) ) ) && for _widget && for _widget . id ) {
if ( for _widget . dom _id ) {
2020-01-21 17:51:44 +01:00
this . span . attr ( "for" , for _widget . dom _id ) ;
2020-02-19 17:14:44 +01:00
}
else {
// Target widget is not done yet, need to wait
var tab _deferred = jQuery . Deferred ( ) ;
window . setTimeout ( function ( ) {
this . span . attr ( "for" , for _widget . dom _id ) ;
tab _deferred . resolve ( ) ;
} . bind ( this ) , 0 ) ;
return tab _deferred . promise ( ) ;
}
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
return true ;
} ;
et2 _description . prototype . set _label = function ( _value ) {
// Abort if ther was no change in the label
if ( _value == this . label ) {
return ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
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 ] ) ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
// 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 ) ;
}
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
// add class if label is empty
this . _labelContainer . toggleClass ( 'et2_label_empty' , ! _value || ! parts [ 0 ] ) ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
else {
// Delete the labelContainer from the surroundings object
if ( this . _labelContainer ) {
this . getSurroundings ( ) . removeDOMNode ( this . _labelContainer [ 0 ] ) ;
}
this . _labelContainer = null ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
// Update the surroundings in order to reflect the change in the label
this . getSurroundings ( ) . update ( ) ;
// Copy the given value
this . label = _value ;
} ;
/ * *
* Function to get media content to feed the expose
* @ param { type } _value
* @ returns { Array | Array . getMedia . mediaContent }
* /
et2 _description . prototype . getMedia = function ( _value ) {
var base _url = egw . webserverUrl . match ( new RegExp ( /^\// , 'ig' ) ) ? egw ( window ) . window . location . origin : '' ;
var mediaContent = [ ] ;
if ( _value ) {
mediaContent = [ {
title : this . options . label ,
href : base _url + _value ,
type : this . options . type + "/*" ,
thumbnail : base _url + _value
} ] ;
if ( _value . match ( /\/webdav.php/ , 'ig' ) )
mediaContent [ 0 ] [ "download_href" ] = base _url + _value + '?download' ;
}
return mediaContent ;
} ;
et2 _description . prototype . set _value = function ( _value ) {
if ( ! _value )
_value = "" ;
if ( ! this . options . no _lang )
_value = this . egw ( ) . lang ( _value ) ;
if ( this . options . value && ( this . options . value + "" ) . indexOf ( '%s' ) != - 1 ) {
_value = this . options . value . replace ( /%s/g , _value ) ;
}
et2 _insertLinkText ( this . _parseText ( _value ) , this . span [ 0 ] , this . options . href ? this . options . extra _link _target : '_blank' ) ;
// Add hover action button (Edit)
if ( this . options . hover _action ) {
this . _build _hover _action ( ) ;
}
if ( this . options . extra _link _popup || this . options . mime ) {
var href = this . options . href ;
var mime _data = this . options . mime _data ;
var self = this ;
var $span = this . options . mime _data ? jQuery ( this . span ) : jQuery ( 'a' , this . span ) ;
$span . click ( function ( e ) {
if ( self . options . expose _view && typeof self . options . mime != 'undefined' && self . options . mime . match ( self . mime _regexp , 'ig' ) ) {
self . _init _blueimp _gallery ( e , href ) ;
}
else {
egw ( window ) . open _link ( mime _data || href , self . options . extra _link _target , self . options . extra _link _popup , null , null , self . options . mime ) ;
}
e . preventDefault ( ) ;
return false ;
} ) ;
}
} ;
et2 _description . prototype . _parseText = function ( _value ) {
if ( this . options . href ) {
var href = this . options . href ;
if ( href . indexOf ( '/' ) == - 1 && href . split ( '.' ) . length >= 3 &&
! ( href . indexOf ( 'mailto:' ) != - 1 || href . indexOf ( '://' ) != - 1 || href . indexOf ( 'javascript:' ) != - 1 ) ) {
href = "/index.php?menuaction=" + href ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
if ( href . charAt ( 0 ) == '/' ) // link relative to eGW
{
href = egw . link ( href ) ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
return [ {
"href" : href ,
"text" : _value
} ] ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
else if ( this . options . activate _links ) {
return et2 _activateLinks ( _value ) ;
2020-01-21 17:51:44 +01:00
}
2020-02-19 17:14:44 +01:00
else {
return [ _value ] ;
}
} ;
et2 _description . prototype . set _font _style = function ( _value ) {
this . font _style = _value ;
this . span . toggleClass ( "et2_bold" , _value . indexOf ( "b" ) >= 0 ) ;
this . span . toggleClass ( "et2_italic" , _value . indexOf ( "i" ) >= 0 ) ;
} ;
/ * *
* Code for implementing et2 _IDetachedDOM
*
* @ param { array } _attrs
* /
et2 _description . prototype . getDetachedAttributes = function ( _attrs ) {
_attrs . push ( "value" , "class" , "href" ) ;
} ;
et2 _description . prototype . getDetachedNodes = function ( ) {
return [ this . span [ 0 ] ] ;
} ;
et2 _description . prototype . setDetachedAttributes = function ( _nodes , _values , _data ) {
// Update the properties
var updateLink = false ;
if ( typeof _values [ "href" ] != "undefined" ) {
updateLink = true ;
this . options . href = _values [ "href" ] ;
}
if ( typeof _values [ "value" ] != "undefined" || ( updateLink && ( _values [ "value" ] || this . options . value ) ) ) {
this . span = jQuery ( _nodes [ 0 ] ) ;
this . set _value ( _values [ "value" ] ) ;
}
if ( typeof _values [ "class" ] != "undefined" ) {
_nodes [ 0 ] . setAttribute ( "class" , _values [ "class" ] ) ;
}
// Add hover action button (Edit), _data is nm's row data
if ( this . options . hover _action ) {
this . _build _hover _action ( _data ) ;
}
} ;
/ * *
* Builds button for hover action
* @ param { object } _data
* /
et2 _description . prototype . _build _hover _action = function ( _data ) {
var content = _data && _data . content ? _data . content : undefined ;
var widget = this ;
this . span . off ( ) . on ( 'mouseenter' , jQuery . proxy ( function ( event ) {
event . stopImmediatePropagation ( ) ;
var self = this ;
this . span . tooltip ( {
items : 'span.et2_label' ,
position : { my : "right top" , at : "left top" , collision : "flipfit" } ,
tooltipClass : "et2_email_popup" ,
content : function ( ) {
2020-04-15 18:06:09 +02:00
return jQuery ( '<a href="#" class= "et2_url_email_contactPlus" title="' + widget . egw ( ) . lang ( widget . options . hover _action _title ) + '"><img src="'
2020-02-19 17:14:44 +01:00
+ egw . image ( "edit" ) + '"/></a>' )
. on ( 'click' , function ( ) {
widget . options . hover _action . call ( self , self . widget , content ) ;
} ) ;
} ,
close : function ( event , ui ) {
ui . tooltip . hover ( function ( ) {
jQuery ( this ) . stop ( true ) . fadeTo ( 400 , 1 ) ;
} , function ( ) {
jQuery ( this ) . fadeOut ( "400" , function ( ) { jQuery ( this ) . remove ( ) ; } ) ;
} ) ;
}
} )
. tooltip ( "open" ) ;
} , { widget : this , span : this . span } ) ) ;
} ;
return et2 _description ;
} ( et2 _core _baseWidget _1 . et2 _baseWidget ) ) ,
_a . _attributes = {
2020-01-21 17:51:44 +01:00
"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" ,
"type" : "string" ,
"description" : "Displayed text" ,
"translate" : "!no_lang" ,
"default" : ""
} ,
/ * *
* Options converted from the "options" - attribute .
* /
"font_style" : {
"name" : "Font Style" ,
"type" : "string" ,
"description" : "Style may be a compositum of \"b\" and \"i\" which " +
" renders the text bold and/or italic."
} ,
"href" : {
"name" : "Link URL" ,
"type" : "string" ,
"description" : "Link URL, empty if you don't wan't to display a link."
} ,
"activate_links" : {
"name" : "Replace URLs" ,
"type" : "boolean" ,
"default" : false ,
"description" : "If set, URLs in the text are automatically replaced " +
"by links"
} ,
"for" : {
"name" : "Label for widget" ,
"type" : "string" ,
"description" : "Marks the text as label for the given widget."
} ,
"extra_link_target" : {
"name" : "Link target" ,
"type" : "string" ,
"default" : "_browser" ,
"description" : "Link target for href attribute"
} ,
"extra_link_popup" : {
"name" : "Popup" ,
"type" : "string" ,
"description" : "widthxheight, if popup should be used, eg. 640x480"
} ,
"expose_view" : {
name : "Expose view" ,
type : "boolean" ,
default : false ,
description : "Clicking on description with href value would popup an expose view, and will show content referenced by href."
} ,
mime : {
name : "Mime type" ,
type : "string" ,
default : '' ,
description : "Mime type of the registered link"
} ,
mime _data : {
name : "Mime data" ,
type : "string" ,
default : '' ,
description : "hash for data stored on service-side with egw_link::(get|set)_data()"
} ,
hover _action : {
"name" : "hover action" ,
"type" : "js" ,
"default" : et2 _no _init ,
"description" : "JS code which is executed when clicking on action button. This action is explicitly for attached nodes, like in nm."
} ,
hover _action _title : {
"name" : "hover action title" ,
"type" : "string" ,
"default" : "Edit" ,
"description" : "Text to show as tooltip of defined action"
}
2020-02-19 17:14:44 +01:00
} ,
2020-03-30 18:28:48 +02:00
_a . legacyOptions = [ "font_style" , "href" , "activate_links" , "for" ,
"extra_link_target" , "extra_link_popup" , "statustext" ] ,
2020-02-20 17:46:53 +01:00
_a ) ) ) ) ;
exports . et2 _description = et2 _description ;
;
et2 _core _widget _1 . et2 _register _widget ( et2 _description , [ "description" , "label" ] ) ;
2020-01-22 10:23:24 +01:00
//# sourceMappingURL=et2_widget_description.js.map