2012-03-28 14:37:03 +02:00
/ * *
* EGroupware clientside API : opening of windows , popups or application entries
*
* @ 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 ( as AT stylite . de )
* @ author Ralf Becker < RalfBecker @ outdoor - training . de >
* @ version $Id$
* /
/ * e g w : u s e s
egw _core ;
egw _links ;
* /
2021-06-05 20:39:39 +02:00
import './egw_core.js' ;
2012-03-28 14:37:03 +02:00
2013-08-16 11:16:40 +02:00
/ * *
* @ augments Class
2014-10-09 11:34:24 +02:00
* @ param { object } _egw
* @ param { DOMwindow } _wnd
2013-08-16 11:16:40 +02:00
* /
2014-10-09 11:34:24 +02:00
egw . extend ( 'open' , egw . MODULE _WND _LOCAL , function ( _egw , _wnd )
{
"use strict" ;
2014-01-13 18:37:46 +01:00
2013-10-07 12:09:08 +02:00
/ * *
* Magic handling for mailto : uris using mail application .
2014-01-13 18:37:46 +01:00
*
2013-10-07 12:09:08 +02:00
* We check for open compose windows and add the address in as specified in
* the URL . If there are no open compose windows , a new one is opened . If
* there are more than one open compose window , we prompt for which one to
* use .
2014-01-13 18:37:46 +01:00
*
2013-10-07 12:09:08 +02:00
* The user must have set the 'Open EMail addresses in external mail program' preference
* to No , otherwise the browser will handle it .
2014-01-13 18:37:46 +01:00
*
2013-10-07 12:09:08 +02:00
* @ param { String } uri
* /
function mailto ( uri )
{
// Parse uri into a map
2014-01-13 18:37:46 +01:00
var match = [ ] , index ;
var mailto = uri . match ( /^mailto:([^?]+)/ ) || [ ] ;
var hashes = uri . slice ( uri . indexOf ( '?' ) + 1 ) . split ( '&' ) ;
for ( var i = 0 ; i < hashes . length ; i ++ )
2013-10-07 12:09:08 +02:00
{
2018-07-05 11:28:12 +02:00
index = hashes [ i ] . replace ( /__AMPERSAND__/g , '&' ) . split ( '=' ) ;
2014-01-13 18:37:46 +01:00
match . push ( index [ 0 ] ) ;
match [ index [ 0 ] ] = index [ 1 ] ;
}
2018-07-05 14:29:49 +02:00
if ( mailto [ 1 ] ) mailto [ 1 ] = mailto [ 1 ] . replace ( /__AMPERSAND__/g , '&' ) ;
2014-01-13 18:37:46 +01:00
var content = {
to : mailto [ 1 ] || [ ] ,
cc : match [ 'cc' ] || [ ] ,
2014-10-09 11:34:24 +02:00
bcc : match [ 'bcc' ] || [ ]
} ;
2016-10-27 11:07:44 +02:00
2015-12-03 12:07:03 +01:00
// Encode html entities in the URI, otheerwise server XSS protection wont
// allow it to pass, because it may get mistaken for some forbiden tags,
// e.g., "Mathias <mathias@example.com>" the first part of email "<mathias"
// including "<" would get mistaken for <math> tag, and server will cut it off.
uri = uri . replace ( /</g , '<' ) . replace ( />/g , '>' ) ;
2016-10-27 11:07:44 +02:00
2018-03-09 17:48:09 +01:00
egw . openWithinWindow ( "mail" , "setCompose" , content , { 'preset[mailto]' : uri } , /mail_compose.compose/ ) ;
2018-06-07 14:45:42 +02:00
for ( var index in content )
{
if ( content [ index ] . length > 0 )
{
var cLen = content [ index ] . split ( ',' ) ;
egw . message ( egw . lang ( '%1 email(s) added into %2' , cLen . length , egw . lang ( index ) ) ) ;
return ;
}
}
2013-10-07 12:09:08 +02:00
}
2012-03-28 14:37:03 +02:00
return {
/ * *
* View an EGroupware entry : opens a popup of correct size or redirects window . location to requested url
2014-01-13 18:37:46 +01:00
*
* Examples :
2012-03-28 14:37:03 +02:00
* - egw . open ( 123 , 'infolog' ) or egw . open ( 'infolog:123' ) opens popup to edit or view ( if no edit rights ) infolog entry 123
* - egw . open ( 'infolog:123' , 'timesheet' , 'add' ) opens popup to add new timesheet linked to infolog entry 123
* - egw . open ( 123 , 'addressbook' , 'view' ) opens addressbook view for entry 123 ( showing linked infologs )
* - egw . open ( '' , 'addressbook' , 'view_list' , { search : 'Becker' } ) opens list of addresses containing 'Becker'
2014-01-13 18:37:46 +01:00
*
2014-10-09 11:34:24 +02:00
* @ param { string } | int | object id _data either just the id or if app == "" "app:id" or object with all data
2012-03-28 14:37:03 +02:00
* to be able to open files you need to give : ( mine - ) type , path or id , app2 and id2 ( path = / a p p s / a p p 2 / i d 2 / i d "
2014-10-09 11:34:24 +02:00
* @ param { string } app app - name or empty ( app is part of id )
* @ param { string } type default "edit" , possible "view" , "view_list" , "edit" ( falls back to "view" ) and "add"
* @ param { object | string } extra extra url parameters to append as object or string
* @ param { string } target target of window to open
* @ param { string } target _app target application to open in that tab
2015-03-18 11:36:47 +01:00
* @ param { boolean } _check _popup _blocker TRUE check if browser pop - up blocker is on / off , FALSE no check
* - This option only makes sense to be enabled when the open _link requested without user interaction
2013-08-16 11:16:40 +02:00
* @ memberOf egw
2020-09-24 16:19:56 +02:00
*
* @ return { object | void } returns object for given specific target like '_tab'
2012-03-28 14:37:03 +02:00
* /
2015-03-18 11:36:47 +01:00
open : function ( id _data , app , type , extra , target , target _app , _check _popup _blocker )
2012-03-28 14:37:03 +02:00
{
2014-01-21 10:21:46 +01:00
// Log for debugging purposes - special log tag 'navigation' always
// goes in user log, if user log is enabled
2014-02-07 15:04:12 +01:00
egw . debug ( "navigation" ,
2014-01-21 10:21:46 +01:00
"egw.open(id_data=%o, app=%s, type=%s, extra=%o, target=%s, target_app=%s)" ,
id _data , app , type , extra , target , target _app
) ;
2012-03-28 14:37:03 +02:00
var id ;
2012-04-25 18:23:27 +02:00
if ( typeof target === 'undefined' )
{
target = '_blank' ;
}
2012-03-28 14:37:03 +02:00
if ( ! app )
{
if ( typeof id _data != 'object' )
{
2012-05-17 11:26:25 +02:00
var app _id = id _data . split ( ':' , 2 ) ;
2012-03-28 14:37:03 +02:00
app = app _id [ 0 ] ;
id = app _id [ 1 ] ;
}
else
{
app = id _data . app ;
id = id _data . id ;
2013-12-07 00:12:05 +01:00
if ( typeof id _data . type != 'undefined' )
{
type = id _data . type ;
}
2012-03-28 14:37:03 +02:00
}
}
else if ( app != 'file' )
{
2012-05-17 11:26:25 +02:00
id = id _data ;
2012-03-28 14:37:03 +02:00
id _data = { 'id' : id , 'app' : app , 'extra' : extra } ;
}
var url ;
var popup ;
var params ;
if ( app == 'file' )
{
url = this . mime _open ( id _data ) ;
if ( typeof url == 'object' )
{
if ( typeof url . mime _popup != 'undefined' )
{
popup = url . mime _popup ;
delete url . mime _popup ;
}
2012-03-28 15:01:37 +02:00
if ( typeof url . mime _target != 'undefined' )
{
target = url . mime _target ;
delete url . mime _target ;
}
2015-03-25 18:48:24 +01:00
if ( typeof url . url == 'string' )
{
url = url . url ;
}
else
{
params = url ;
url = '/index.php' ;
}
2012-03-28 14:37:03 +02:00
}
}
else
{
var app _registry = this . link _get _registry ( app ) ;
2014-01-13 18:37:46 +01:00
2012-03-28 14:37:03 +02:00
if ( ! app || ! app _registry )
{
alert ( 'egw.open() app "' + app + '" NOT defined in link registry!' ) ;
2014-01-13 18:37:46 +01:00
return ;
2012-03-28 14:37:03 +02:00
}
if ( typeof type == 'undefined' ) type = 'edit' ;
if ( type == 'edit' && typeof app _registry . edit == 'undefined' ) type = 'view' ;
if ( typeof app _registry [ type ] == 'undefined' )
{
alert ( 'egw.open() type "' + type + '" is NOT defined in link registry for app "' + app + '"!' ) ;
2014-01-13 18:37:46 +01:00
return ;
2012-03-28 14:37:03 +02:00
}
url = '/index.php' ;
2019-01-10 22:58:40 +01:00
if ( typeof app _registry [ type ] === 'object' )
{
// Copy, not get a reference, or we'll change the registry
params = jQuery . extend ( { } , app _registry [ type ] ) ;
}
2021-03-04 10:49:45 +01:00
else if ( typeof app _registry [ type ] === 'string' &&
( app _registry [ type ] . substr ( 0 , 11 ) === 'javascript:' || app _registry [ type ] . substr ( 0 , 4 ) === 'app.' ) )
2019-01-10 22:58:40 +01:00
{
// JavaScript, just pass it on
url = app _registry [ type ] ;
params = { } ;
}
2012-03-28 14:37:03 +02:00
if ( type == 'view' || type == 'edit' ) // add id parameter for type view or edit
{
params [ app _registry [ type + '_id' ] ] = id ;
}
else if ( type == 'add' && id ) // add add_app and app_id parameters, if given for add
{
var app _id = id . split ( ':' , 2 ) ;
params [ app _registry . add _app ] = app _id [ 0 ] ;
params [ app _registry . add _id ] = app _id [ 1 ] ;
}
2014-01-13 18:37:46 +01:00
2012-03-28 14:37:03 +02:00
if ( typeof extra == 'string' )
{
url += '?' + extra ;
}
else if ( typeof extra == 'object' )
{
2016-06-02 16:51:15 +02:00
jQuery . extend ( params , extra ) ;
2012-03-28 14:37:03 +02:00
}
popup = app _registry [ type + '_popup' ] ;
}
2021-03-04 10:49:45 +01:00
if ( url . substr ( 0 , 11 ) === 'javascript:' )
2019-01-10 22:58:40 +01:00
{
// Add parameters into javascript
url = 'javascript:var params = ' + JSON . stringify ( params ) + '; ' + url . substr ( 11 ) ;
}
2021-03-04 10:49:45 +01:00
// app.<appname>.<method>: call app method direct with parameter object as first parameter
else if ( url . substr ( 0 , 4 ) === 'app.' )
{
return this . callFunc ( url , params ) ;
}
2019-01-10 22:58:40 +01:00
else
{
url = this . link ( url , params ) ;
}
2020-09-24 16:19:56 +02:00
if ( target == '_tab' ) return { url : url } ;
2020-11-03 11:47:26 +01:00
if ( type == 'view' && params && params . target == 'tab' ) {
2020-10-29 11:47:16 +01:00
return this . openTab ( params [ app _registry [ 'view_id' ] ] , app , type , params , {
id : params [ app _registry [ 'view_id' ] ] + '-' + this . appName ,
icon : params [ 'icon' ] ,
displayName : id _data [ 'title' ] + " (" + egw . lang ( this . appName ) + ")" ,
} ) ;
}
2019-01-10 22:58:40 +01:00
return this . open _link ( url , target , popup , target _app , _check _popup _blocker ) ;
2012-03-28 14:37:03 +02:00
} ,
2014-01-13 18:37:46 +01:00
2020-09-24 16:19:56 +02:00
/ * *
* View an EGroupware entry : opens a framework tab for the given app entry
*
* @ param { string } | int | object _id either just the id or if app == "" "app:id" or object with all data
* @ param { string } _app app - name or empty ( app is part of id )
* @ param { string } _type default "edit" , possible "view" , "view_list" , "edit" ( falls back to "view" ) and "add"
* @ param { object | string } _extra extra url parameters to append as object or string
* @ param { object } _framework _app framework app attributes e . g . title or displayName
2021-03-02 20:00:59 +01:00
* @ return { string } appname of new tab
2020-09-24 16:19:56 +02:00
* /
openTab : function ( _id , _app , _type , _extra , _framework _app )
{
if ( _wnd . framework && _wnd . framework . tabLinkHandler )
{
var data = this . open ( _id , _app , _type , _extra , "_tab" , false ) ;
// Use framework's link handler
2021-03-02 20:00:59 +01:00
return _wnd . framework . tabLinkHandler ( data . url , _framework _app ) ;
2020-09-24 16:19:56 +02:00
}
else
{
this . open ( _id , _app , _type , _extra ) ;
}
} ,
2012-03-28 14:37:03 +02:00
/ * *
* Open a link , which can be either a menuaction , a EGroupware relative url or a full url
2014-01-13 18:37:46 +01:00
*
2014-10-09 11:34:24 +02:00
* @ param { string } _link menuaction , EGroupware relative url or a full url ( incl . "mailto:" or "javascript:" )
* @ param { string } _target optional target / window name
* @ param { string } _popup widthxheight , if a popup should be used
* @ param { string } _target _app app - name for opener
* @ param { boolean } _check _popup _blocker TRUE check if browser pop - up blocker is on / off , FALSE no check
2014-08-04 16:02:05 +02:00
* - This option only makes sense to be enabled when the open _link requested without user interaction
2015-03-24 10:43:38 +01:00
* @ param { string } _mime _type if given , we check if any app has registered a mime - handler for that type and use it
2012-03-28 14:37:03 +02:00
* /
2015-03-24 10:43:38 +01:00
open _link : function ( _link , _target , _popup , _target _app , _check _popup _blocker , _mime _type )
2012-03-28 14:37:03 +02:00
{
2014-01-21 10:21:46 +01:00
// Log for debugging purposes - don't use navigation here to avoid
// flooding log with details already captured by egw.open()
egw . debug ( "log" ,
"egw.open_link(_link=%s, _target=%s, _popup=%s, _target_app=%s)" ,
_link , _target , _popup , _target _app
) ;
2014-08-04 16:02:05 +02:00
//Check browser pop-up blocker
if ( _check _popup _blocker )
{
if ( this . _check _popupBlocker ( _link , _target , _popup , _target _app ) ) return ;
2014-10-09 11:34:24 +02:00
}
2012-03-28 14:37:03 +02:00
var url = _link ;
if ( url . indexOf ( 'javascript:' ) == 0 )
{
2021-07-02 15:27:46 +02:00
( new Function ( url . substr ( 11 ) ) ) ( ) ;
2012-03-28 14:37:03 +02:00
return ;
}
2013-10-07 12:09:08 +02:00
if ( url . indexOf ( 'mailto:' ) == 0 )
{
return mailto ( url ) ;
}
2012-03-28 14:37:03 +02:00
// link is not necessary an url, it can also be a menuaction!
if ( url . indexOf ( '/' ) == - 1 && url . split ( '.' ) . length >= 3 &&
! ( url . indexOf ( 'mailto:' ) == 0 || url . indexOf ( '/index.php' ) == 0 || url . indexOf ( '://' ) != - 1 ) )
{
url = "/index.php?menuaction=" + url ;
}
// append the url to the webserver url, if not already contained or empty
if ( url [ 0 ] == '/' && this . webserverUrl && this . webserverUrl != '/' && url . indexOf ( this . webserverUrl + '/' ) != 0 )
{
url = this . webserverUrl + url ;
}
2015-03-24 10:43:38 +01:00
var mime _info = _mime _type ? this . get _mime _info ( _mime _type ) : undefined ;
2015-03-25 18:48:24 +01:00
if ( mime _info && ( mime _info . mime _url || mime _info . mime _data ) )
2015-03-24 10:43:38 +01:00
{
2015-03-25 18:48:24 +01:00
var data = { } ;
for ( var attr in mime _info )
2015-03-24 10:43:38 +01:00
{
2015-03-25 18:48:24 +01:00
switch ( attr )
{
case 'mime_popup' :
_popup = mime _info . mime _popup ;
break ;
case 'mime_target' :
_target = mime _info . mime _target ;
break ;
case 'mime_type' :
data [ mime _info . mime _type ] = _mime _type ;
break ;
case 'mime_data' :
data [ mime _info [ attr ] ] = _link ;
break ;
case 'mime_url' :
data [ mime _info [ attr ] ] = url ;
break ;
default :
data [ attr ] = mime _info [ attr ] ;
break ;
}
2015-03-24 10:43:38 +01:00
}
2015-03-25 18:48:24 +01:00
url = egw . link ( '/index.php' , data ) ;
}
else if ( mime _info )
{
if ( mime _info . mime _popup ) _popup = mime _info . mime _popup ;
if ( mime _info . mime _target ) _target = mime _info . mime _target ;
2015-03-24 10:43:38 +01:00
}
2016-10-27 11:07:44 +02:00
2016-10-27 14:17:42 +02:00
if ( _popup && _popup . indexOf ( 'x' ) > 0 )
2012-03-28 14:37:03 +02:00
{
var w _h = _popup . split ( 'x' ) ;
2019-10-17 23:05:55 +02:00
var popup _window = this . openPopup ( url , w _h [ 0 ] , w _h [ 1 ] , _target && _target != _target _app ? _target : '_blank' , _target _app , true ) ;
2014-01-13 18:37:46 +01:00
2013-10-05 11:28:12 +02:00
// Remember which windows are open
2013-10-10 11:37:21 +02:00
egw ( ) . storeWindow ( _target _app , popup _window ) ;
2014-01-13 18:37:46 +01:00
2013-10-05 11:38:22 +02:00
return popup _window ;
2012-03-28 14:37:03 +02:00
}
2020-09-24 16:19:56 +02:00
else if ( ( typeof _target == 'undefined' || _target == '_self' || typeof this . link _app _list ( ) [ _target ] != "undefined" ) )
2013-06-12 18:56:12 +02:00
{
2013-07-15 18:03:37 +02:00
if ( _target == '_self' )
{
// '_self' isn't allowed, but we can handle it
_target = undefined ;
}
2013-06-12 18:56:12 +02:00
// Use framework's link handler, if present
2014-02-07 15:04:12 +01:00
return this . link _handler ( url , _target ) ;
}
else
{
2015-03-26 14:41:16 +01:00
// No mime type registered, set target properly based on browsing environment
2015-03-27 11:13:57 +01:00
if ( _target == '_browser' )
2015-03-26 14:41:16 +01:00
{
_target = egwIsMobile ( ) ? '_self' : '_blank' ;
}
2016-10-27 14:17:42 +02:00
_target = _target == '_phonecall' && _popup && _popup . indexOf ( 'x' ) < 0 ? _popup : _target ;
2014-02-07 15:04:12 +01:00
return _wnd . open ( url , _target ) ;
2013-06-12 18:56:12 +02:00
}
2014-02-07 15:04:12 +01:00
} ,
2014-12-01 11:44:51 +01:00
/ * *
* Open a ( centered ) popup window with given size and url
*
* @ param { string } _url
* @ param { number } _width
* @ param { number } _height
* @ param { string } _windowName or "_blank"
* @ param { string | boolean } _app app - name for framework to set correct opener or false for current app
* @ param { boolean } _returnID true : return window , false : return undefined
* @ param { string } _status "yes" or "no" to display status bar of popup
* @ param { boolean } _skip _framework
* @ returns { DOMWindow | undefined }
* /
openPopup : function ( _url , _width , _height , _windowName , _app , _returnID , _status , _skip _framework )
{
// Log for debugging purposes
egw . debug ( "navigation" , "openPopup(%s, %s, %s, %o, %s, %s)" , _url , _windowName , _width , _height , _status , _app ) ;
2015-02-06 17:43:36 +01:00
if ( _height == 'availHeight' ) _height = this . availHeight ( ) ;
2014-12-01 11:44:51 +01:00
// if we have a framework and we use mobile template --> let framework deal with opening popups
if ( ! _skip _framework && _wnd . framework )
{
return _wnd . framework . openPopup ( _url , _width , _height , _windowName , _app , _returnID , _status , _wnd ) ;
}
if ( typeof ( _app ) == 'undefined' ) _app = false ;
if ( typeof ( _returnID ) == 'undefined' ) _returnID = false ;
2020-05-18 20:55:57 +02:00
var $wnd = jQuery ( egw . top ) ;
2014-12-01 11:44:51 +01:00
var positionLeft = ( $wnd . outerWidth ( ) / 2 ) - ( _width / 2 ) + _wnd . screenX ;
var positionTop = ( $wnd . outerHeight ( ) / 2 ) - ( _height / 2 ) + _wnd . screenY ;
// IE fails, if name contains eg. a dash (-)
if ( navigator . userAgent . match ( /msie/i ) ) _windowName = ! _windowName ? '_blank' : _windowName . replace ( /[^a-zA-Z0-9_]+/ , '' ) ;
var windowID = _wnd . open ( _url , _windowName || '_blank' , "width=" + _width + ",height=" + _height +
",screenX=" + positionLeft + ",left=" + positionLeft + ",screenY=" + positionTop + ",top=" + positionTop +
",location=no,menubar=no,directories=no,toolbar=no,scrollbars=yes,resizable=yes,status=" + _status ) ;
// inject egw object
2015-03-18 11:36:47 +01:00
if ( windowID ) windowID . egw = _wnd . egw ;
2014-12-01 11:44:51 +01:00
// returning something, replaces whole window in FF, if used in link as "javascript:egw_openWindowCentered2()"
if ( _returnID !== false ) return windowID ;
} ,
2014-11-10 11:41:23 +01:00
/ * *
* Get available height of screen
* /
availHeight : function ( )
{
2016-10-27 11:07:44 +02:00
return screen . availHeight < screen . height ?
2015-12-18 14:14:09 +01:00
( navigator . userAgent . match ( /windows/ig ) ? screen . availHeight - 100 : screen . availHeight ) // Seems chrome not counting taskbar in available height
: screen . height - 100 ;
2014-11-10 11:41:23 +01:00
} ,
2014-02-07 15:04:12 +01:00
/ * *
* Use frameworks ( framed template ) link handler to open a url
*
* @ param { string } _url
* @ param { string } _target
* /
link _handler : function ( _url , _target )
{
2015-02-11 10:43:29 +01:00
// if url is supposed to open in admin, use admins loader to open it in it's own iframe
// (otherwise there's no tree and sidebox!)
if ( _target === 'admin' && ! _url . match ( /menuaction=admin\.admin_ui\.index/ ) )
{
_url = _url . replace ( /menuaction=([^&]+)/ , 'menuaction=admin.admin_ui.index&load=$1' ) ;
}
2014-02-07 15:04:12 +01:00
if ( _wnd . framework )
2013-09-02 15:25:00 +02:00
{
2014-02-07 15:04:12 +01:00
_wnd . framework . linkHandler ( _url , _target ) ;
2013-09-02 15:25:00 +02:00
}
2012-03-28 14:37:03 +02:00
else
{
2014-02-07 15:04:12 +01:00
_wnd . location . href = _url ;
2012-03-28 14:37:03 +02:00
}
2014-08-04 16:02:05 +02:00
} ,
2014-10-09 11:34:24 +02:00
2014-11-27 18:01:47 +01:00
/ * *
* Close current window / popup
* /
close : function ( )
{
if ( _wnd . framework && typeof _wnd . framework . popup _close == "function" )
{
_wnd . framework . popup _close ( _wnd ) ;
}
else
{
2015-01-30 16:25:47 +01:00
_wnd . close ( ) ;
2014-11-27 18:01:47 +01:00
}
} ,
2014-08-04 16:02:05 +02:00
/ * *
* Check if browser pop - up blocker is on / off
2014-10-09 11:34:24 +02:00
*
* @ param { string } _link menuaction , EGroupware relative url or a full url ( incl . "mailto:" or "javascript:" )
* @ param { string } _target optional target / window name
* @ param { string } _popup widthxheight , if a popup should be used
* @ param { string } _target _app app - name for opener
*
2014-08-04 16:02:05 +02:00
* @ return boolean returns false if pop - up blocker is off
2014-10-09 11:34:24 +02:00
* - returns true if pop - up blocker is on ,
* - and re - call the open _link with provided parameters , after user interaction .
2014-08-04 16:02:05 +02:00
* /
_check _popupBlocker : function ( _link , _target , _popup , _target _app )
{
var popup = window . open ( "" , "" , 'top=' + ( screen . height / 2 ) + ',left=' + ( screen . width / 2 ) + ',width=1,height=1,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,dependent=yes' ) ;
if ( ! popup || popup == 'undefined' || popup == null )
{
2022-03-17 23:18:39 +01:00
Et2Dialog . show _dialog ( function ( )
{
window . egw . open _link ( _link , _target , _popup , _target _app ) ;
} , egw . lang ( "The browser popup blocker is on. Please click on OK button to see the pop-up.\n\nIf you would like to not see this message for the next time, allow your browser pop-up blocker to open popups from %1" , window . location . hostname ) ,
"Popup Blocker Warning" , { } , Et2Dialog . BUTTONS _OK , Et2Dialog . WARNING _MESSAGE ) ;
2014-08-04 16:02:05 +02:00
return true ;
}
else
{
popup . close ( ) ;
return false ;
}
2018-03-09 17:48:09 +01:00
} ,
/ * *
* This function helps to append content / run commands into an already
2022-03-17 23:18:39 +01:00
* opened popup window . Popup windows now are getting stored in framework
* object and can be retrieved / closed from framework .
2018-03-09 17:48:09 +01:00
*
* @ param { string } _app name of application to be requested its popups
* @ param { string } _method application method implemented in app . js
* @ param { object } _content content to be passed to method
* @ param { string | object } _extra url or object of extra
* @ param { regex } _regexp regular expression to get specific popup with matched url
2021-05-17 16:27:51 +02:00
* @ param { boolean } _check _popup _blocker TRUE check if browser pop - up blocker is on / off , FALSE no check
2018-03-09 17:48:09 +01:00
* /
2021-05-17 16:27:51 +02:00
openWithinWindow : function ( _app , _method , _content , _extra , _regexp , _check _popup _blocker )
2018-03-09 17:48:09 +01:00
{
var popups = window . framework . popups _get ( _app , _regexp ) ;
2018-04-09 16:42:08 +02:00
var openUp = function ( _app , _extra ) {
var len = 0 ;
if ( typeof _extra == "string" )
{
len = _extra . length ;
}
else if ( typeof _extra == "object" )
{
for ( var i in _extra )
{
if ( jQuery . isArray ( _extra [ i ] ) )
{
var tmp = '' ;
for ( var j in _extra [ i ] )
{
tmp += i + '[]=' + _extra [ i ] [ j ] + '&' ;
}
len += tmp . length ;
}
2018-07-11 14:39:28 +02:00
else if ( _extra [ i ] )
2018-04-09 16:42:08 +02:00
{
len += _extra [ i ] . length ;
}
}
}
// Accoring to microsoft, IE 10/11 can only accept a url with 2083 caharacters
// therefore we need to send request to compose window with POST method
// instead of GET. We create a temporary <Form> and will post emails.
// ** WebServers and other browsers also have url length limit:
// Firefox:~ 65k, Safari:80k, Chrome: 2MB, Apache: 4k, Nginx: 4k
if ( len > 2083 )
{
2021-05-17 16:27:51 +02:00
var popup = egw . open ( '' , 'mail' , 'add' , '' , 'compose__' , 'mail' , _check _popup _blocker ) ;
2018-04-09 16:42:08 +02:00
var $tmpForm = jQuery ( document . createElement ( 'form' ) ) ;
var $tmpSubmitInput = jQuery ( document . createElement ( 'input' ) ) . attr ( { type : "submit" } ) ;
for ( var i in _extra )
{
if ( jQuery . isArray ( _extra [ i ] ) )
{
$tmpForm . append ( jQuery ( document . createElement ( 'input' ) ) . attr ( { name : i , type : "text" , value : JSON . stringify ( _extra [ i ] ) } ) ) ;
}
else
{
$tmpForm . append ( jQuery ( document . createElement ( 'input' ) ) . attr ( { name : i , type : "text" , value : _extra [ i ] } ) ) ;
}
}
// Set the temporary form's attributes
$tmpForm . attr ( { target : popup . name , action : "index.php?menuaction=mail.mail_compose.compose" , method : "post" } )
. append ( $tmpSubmitInput ) . appendTo ( 'body' ) ;
$tmpForm . submit ( ) ;
// Remove the form after submit
$tmpForm . remove ( ) ;
}
else
{
2021-05-17 16:27:51 +02:00
egw . open ( '' , _app , 'add' , _extra , _app , _app , _check _popup _blocker ) ;
2018-04-09 16:42:08 +02:00
}
} ;
2018-03-09 17:48:09 +01:00
for ( var i = 0 ; i < popups . length ; i ++ )
{
if ( popups [ i ] . closed )
{
window . framework . popups _grabage _collector ( ) ;
}
}
if ( popups . length == 1 )
{
try {
popups [ 0 ] . app [ _app ] [ _method ] ( popups [ 0 ] , _content ) ;
}
catch ( e ) {
window . setTimeout ( function ( ) {
2018-04-09 16:42:08 +02:00
openUp ( _app , _extra ) ;
2018-03-09 17:48:09 +01:00
} ) ;
}
}
else if ( popups . length > 1 )
{
var buttons = [
2022-03-17 23:18:39 +01:00
{ label : this . lang ( "Add" ) , id : "add" , "class" : "ui-priority-primary" , "default" : true } ,
{ label : this . lang ( "Cancel" ) , id : "cancel" }
2018-03-09 17:48:09 +01:00
] ;
var c = [ ] ;
2022-03-17 23:18:39 +01:00
for ( var i = 0 ; i < popups . length ; i ++ )
2018-03-09 17:48:09 +01:00
{
2022-03-17 23:18:39 +01:00
c . push ( { label : popups [ i ] . document . title || this . lang ( _app ) , index : i } ) ;
2018-03-09 17:48:09 +01:00
}
2022-03-17 23:18:39 +01:00
let dialog = new Et2Dialog ( this . app _name ( ) ) ;
dialog . transformAttributes ( {
callback : function ( _button _id , _value )
{
2018-03-09 17:48:09 +01:00
if ( _value && _value . grid )
{
switch ( _button _id )
{
case "add" :
popups [ _value . grid . index ] . app [ _app ] [ _method ] ( popups [ _value . grid . index ] , _content ) ;
return ;
case "cancel" :
}
}
} ,
title : this . lang ( "Select an opened dialog" ) ,
buttons : buttons ,
2022-03-17 23:18:39 +01:00
value : { content : { grid : c } } ,
template : this . webserverUrl + '/api/templates/default/promptOpenedDialog.xet?1' ,
2018-03-09 17:48:09 +01:00
resizable : false
2022-03-17 23:18:39 +01:00
} ) ;
document . body . appendChild ( dialog ) ;
2018-03-09 17:48:09 +01:00
}
else
{
2018-04-09 16:42:08 +02:00
openUp ( _app , _extra ) ;
2018-03-09 17:48:09 +01:00
}
2012-03-28 14:37:03 +02:00
}
} ;
} ) ;
2013-10-07 12:09:08 +02:00
// Add protocol handler as an option if mail handling is not forced so mail can handle mailto:
/ * N o t w o r k i n g c o n s i s t a n t l y y e t
2016-06-02 16:51:15 +02:00
jQuery ( function ( ) {
2013-10-07 12:09:08 +02:00
try {
if ( egw . user ( 'apps' ) . mail && ( egw . preference ( 'force_mailto' , 'addressbook' ) || true ) != '0' )
{
var params = egw . link _get _registry ( 'mail' , 'add' ) ;
if ( params )
{
params [ 'preset[mailto]' ] = '' ; // %s, but egw.link will encode it
navigator . registerProtocolHandler ( "mailto" , egw . link ( '/index.php' , params ) + '%s' , egw . lang ( 'mail' ) ) ;
}
}
} catch ( e ) { }
} ) ;
2014-11-27 18:01:47 +01:00
* /