2009-07-07 11:58:20 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare - API
|
|
|
|
* http://www.egroupware.org
|
|
|
|
*
|
|
|
|
* This file was originally created Tyamad, but their content is now completly removed!
|
|
|
|
* It still contains some commonly used javascript functions, always included by EGroupware.
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package api
|
|
|
|
* @subpackage jsapi
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-06-19 00:09:31 +02:00
|
|
|
|
|
|
|
/***********************************************\
|
|
|
|
* INITIALIZATION *
|
|
|
|
\***********************************************/
|
|
|
|
if (document.all)
|
|
|
|
{
|
|
|
|
navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false;
|
|
|
|
is_ie = true;
|
|
|
|
is_moz1_6 = false;
|
|
|
|
is_mozilla = false;
|
|
|
|
is_ns4 = false;
|
|
|
|
}
|
|
|
|
else if (document.getElementById)
|
|
|
|
{
|
|
|
|
navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false;
|
|
|
|
is_ie = false;
|
|
|
|
is_ie5 = false;
|
|
|
|
is_mozilla = true;
|
|
|
|
is_ns4 = false;
|
|
|
|
}
|
|
|
|
else if (document.layers)
|
|
|
|
{
|
|
|
|
is_ie = false;
|
2013-07-19 10:45:26 +02:00
|
|
|
is_ie5 = false;
|
2005-06-19 00:09:31 +02:00
|
|
|
is_moz1_6 = false;
|
|
|
|
is_mozilla = false;
|
|
|
|
is_ns4 = true;
|
|
|
|
}
|
2010-04-16 15:24:58 +02:00
|
|
|
|
2011-06-03 11:50:27 +02:00
|
|
|
//console.log('is_ie='+is_ie+', is_ie5='+is_ie5+', is_mozilla='+is_mozilla+', is_moz1_6='+is_moz1_6+', is_ns4='+is_ns4);
|
|
|
|
|
2010-07-01 15:52:55 +02:00
|
|
|
/**
|
|
|
|
* Check whether the console object is defined - if not, define one
|
|
|
|
*/
|
|
|
|
if (typeof window.console == 'undefined')
|
|
|
|
{
|
|
|
|
window.console = {
|
|
|
|
'log': function() {
|
|
|
|
},
|
|
|
|
'warn': function() {
|
|
|
|
},
|
|
|
|
'error': function() {
|
|
|
|
},
|
|
|
|
'info': function() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-22 16:39:27 +02:00
|
|
|
/**
|
|
|
|
* Seperates all script tags from the given html code and returns the seperately
|
2018-02-06 18:00:36 +01:00
|
|
|
*
|
2016-08-02 12:15:46 +02:00
|
|
|
* @param object _html object that the html code
|
|
|
|
* from which the script should be seperated
|
|
|
|
* The html code has to be stored in _html.html,
|
|
|
|
* the result js will be written to _html.js.
|
2010-06-22 16:39:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
egw_seperateJavaScript = function(_html)
|
|
|
|
{
|
2016-08-02 12:15:46 +02:00
|
|
|
var html = typeof _html.html == 'string'?_html.html:'';
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2010-06-22 16:39:27 +02:00
|
|
|
var in_pos = html.search(/<script/im);
|
|
|
|
var out_pos = html.search(/<\/script>/im);
|
|
|
|
while (in_pos > -1 && out_pos > -1)
|
|
|
|
{
|
|
|
|
/*Seperate the whole <script...</script> tag */
|
|
|
|
var js_str = html.substring(in_pos, out_pos+9);
|
|
|
|
|
|
|
|
/*Remove the initial tag */
|
|
|
|
/*js_str = js_str.substring(js_str.search(/>/) + 1);*/
|
|
|
|
_html.js += js_str;
|
|
|
|
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2010-06-22 16:39:27 +02:00
|
|
|
html = html.substring(0, in_pos) + html.substring(out_pos + 9);
|
|
|
|
|
|
|
|
var in_pos = html.search(/<script/im);
|
|
|
|
var out_pos = html.search(/<\/script>/im);
|
|
|
|
}
|
|
|
|
|
|
|
|
_html.html = html;
|
|
|
|
}
|
|
|
|
|
2011-03-17 19:00:24 +01:00
|
|
|
/**
|
|
|
|
* Inserts the script tags inside the given html into the dom tree
|
|
|
|
*/
|
|
|
|
function egw_insertJS(_html)
|
|
|
|
{
|
|
|
|
// Insert each script element seperately
|
|
|
|
if (_html)
|
|
|
|
{
|
|
|
|
|
|
|
|
var in_pos = -1;
|
|
|
|
var out_pos = -1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
// Search in and out position
|
|
|
|
var in_pos = _html.search(/<script/im);
|
|
|
|
var out_pos = _html.search(/<\/script>/im);
|
|
|
|
|
|
|
|
// Copy the text inside the script tags...
|
|
|
|
if (in_pos > -1 && out_pos > -1)
|
|
|
|
{
|
|
|
|
if (out_pos > in_pos)
|
|
|
|
{
|
|
|
|
var scriptStart = _html.indexOf("\>", in_pos);
|
|
|
|
if (scriptStart > in_pos)
|
|
|
|
{
|
|
|
|
var script = _html.substring(scriptStart + 1,
|
|
|
|
out_pos);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// And insert them as real script tags
|
|
|
|
var tag = document.createElement("script");
|
|
|
|
tag.setAttribute("type", "text/javascript");
|
|
|
|
tag.text = script;
|
|
|
|
document.getElementsByTagName("head")[0].appendChild(tag);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
if (typeof console != "undefined" && typeof console.log != "undefined")
|
|
|
|
{
|
|
|
|
console.log('Error while inserting JS code:', _e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_html = _html.substr(out_pos + 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (in_pos > -1 && out_pos > -1)
|
|
|
|
}
|
|
|
|
}
|
2010-06-22 16:39:27 +02:00
|
|
|
|
2010-06-09 16:41:53 +02:00
|
|
|
/**
|
|
|
|
* Returns the top window which contains the current egw_instance, even for popup windows
|
|
|
|
*/
|
|
|
|
function egw_topWindow()
|
|
|
|
{
|
2010-06-11 12:23:13 +02:00
|
|
|
if (typeof window.parent != "undefined" && typeof window.parent.top != "undefined")
|
2010-06-09 16:41:53 +02:00
|
|
|
{
|
2010-06-11 12:23:13 +02:00
|
|
|
return window.parent.top;
|
2010-06-09 16:41:53 +02:00
|
|
|
}
|
2010-06-11 12:23:13 +02:00
|
|
|
|
|
|
|
if (typeof window.opener != "undefined" && typeof window.opener.top != "undefined")
|
2010-06-09 16:41:53 +02:00
|
|
|
{
|
2010-06-11 12:23:13 +02:00
|
|
|
return window.opener.top;
|
2010-06-09 16:41:53 +02:00
|
|
|
}
|
2010-06-11 12:23:13 +02:00
|
|
|
|
|
|
|
return window.top;
|
2010-06-09 16:41:53 +02:00
|
|
|
}
|
|
|
|
|
2010-06-04 14:16:13 +02:00
|
|
|
/**
|
2013-11-19 09:36:08 +01:00
|
|
|
* Returns the window object of the current application
|
2010-06-04 14:16:13 +02:00
|
|
|
* @param string _app is the name of the application which requests the window object
|
|
|
|
*/
|
|
|
|
function egw_appWindow(_app)
|
|
|
|
{
|
2012-12-12 20:45:27 +01:00
|
|
|
var framework = egw_getFramework();
|
|
|
|
if(framework && framework.egw_appWindow) return framework.egw_appWindow(_app);
|
2010-06-04 14:16:13 +02:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-06-02 14:37:49 +02:00
|
|
|
/**
|
|
|
|
* Open _url in window of _app
|
|
|
|
* @param _app
|
|
|
|
* @param _url
|
|
|
|
*/
|
|
|
|
function egw_appWindowOpen(_app, _url)
|
|
|
|
{
|
|
|
|
if (typeof _url == "undefined") {
|
|
|
|
_url = "about:blank";
|
|
|
|
}
|
|
|
|
window.location = _url;
|
|
|
|
}
|
|
|
|
|
2011-01-20 15:11:47 +01:00
|
|
|
/**
|
|
|
|
* Returns the current egw application
|
|
|
|
* @param string _name is only used for fallback, if an onlder version of jdots is used.
|
|
|
|
*/
|
|
|
|
function egw_getApp(_name)
|
|
|
|
{
|
2011-02-04 15:28:12 +01:00
|
|
|
return window.parent.framework.getApplicationByName(_name);
|
2011-01-20 15:11:47 +01:00
|
|
|
}
|
|
|
|
|
2011-06-15 22:54:58 +02:00
|
|
|
/**
|
|
|
|
* Returns the name of the currently active application
|
2014-02-07 15:04:12 +01:00
|
|
|
*
|
|
|
|
* @deprecated use egw(window).app_name()
|
2011-06-15 22:54:58 +02:00
|
|
|
*/
|
|
|
|
function egw_getAppName()
|
|
|
|
{
|
|
|
|
if (typeof egw_appName == 'undefined')
|
|
|
|
{
|
|
|
|
return 'egroupware';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return egw_appName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-28 04:02:49 +01:00
|
|
|
/**
|
2011-06-06 17:11:25 +02:00
|
|
|
* Refresh given application _targetapp display of entry _app _id, incl. outputting _msg
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2010-12-28 04:02:49 +01:00
|
|
|
* Default implementation here only reloads window with it's current url with an added msg=_msg attached
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2014-05-22 17:29:14 +02:00
|
|
|
* @param {string} _msg message (already translated) to show, eg. 'Entry deleted'
|
|
|
|
* @param {string} _app application name
|
|
|
|
* @param {(string|number)} _id id of entry to refresh or null
|
|
|
|
* @param {string} _type either 'update', 'edit', 'delete', 'add' or null
|
2014-01-13 10:40:23 +01:00
|
|
|
* - update: request just modified data from given rows. Sorting is not considered,
|
|
|
|
* so if the sort field is changed, the row will not be moved.
|
|
|
|
* - edit: rows changed, but sorting may be affected. Requires full reload.
|
|
|
|
* - delete: just delete the given rows clientside (no server interaction neccessary)
|
|
|
|
* - add: requires full reload for proper sorting
|
2014-05-22 17:29:14 +02:00
|
|
|
* @param {string} _targetapp which app's window should be refreshed, default current
|
|
|
|
* @param {(string|RegExp)} _replace regular expression to replace in url
|
|
|
|
* @param {string} _with
|
|
|
|
* @param {string} _msg_type 'error', 'warning' or 'success' (default)
|
|
|
|
* @deprecated use egw(window).refresh() instead
|
2010-12-28 04:02:49 +01:00
|
|
|
*/
|
2013-09-04 21:02:34 +02:00
|
|
|
function egw_refresh(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type)
|
2010-12-28 04:02:49 +01:00
|
|
|
{
|
2014-05-22 17:29:14 +02:00
|
|
|
egw(window).refresh(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type);
|
2010-12-28 04:02:49 +01:00
|
|
|
}
|
|
|
|
|
2013-09-04 21:02:34 +02:00
|
|
|
/**
|
|
|
|
* Display an error or regular message
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2014-02-06 16:42:33 +01:00
|
|
|
* @param {string} _msg message to show
|
|
|
|
* @param {string} _type 'error', 'warning' or 'success' (default)
|
|
|
|
* @deprecated use egw(window).message(_msg, _type)
|
2013-09-04 21:02:34 +02:00
|
|
|
*/
|
|
|
|
function egw_message(_msg, _type)
|
|
|
|
{
|
2014-02-06 16:42:33 +01:00
|
|
|
egw(window).message(_msg, _type);
|
2013-09-05 13:53:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update app-header and website-title
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2014-02-06 16:42:33 +01:00
|
|
|
* @param {string} _header
|
|
|
|
* @param {string} _app Application name, if not for the current app
|
|
|
|
@deprecated use egw(window).app_header(_header, _app)
|
|
|
|
*/
|
2013-12-23 17:13:40 +01:00
|
|
|
function egw_app_header(_header,_app)
|
2013-09-05 13:53:25 +02:00
|
|
|
{
|
2014-02-06 16:42:33 +01:00
|
|
|
egw(window).app_header(_header, _app);
|
2013-09-05 13:53:25 +02:00
|
|
|
}
|
2013-09-04 21:02:34 +02:00
|
|
|
|
2011-06-02 13:13:41 +02:00
|
|
|
/**
|
|
|
|
* View an EGroupware entry: opens a popup of correct size or redirects window.location to requested url
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
|
|
|
* Examples:
|
2011-06-02 13:13:41 +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'
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2011-06-02 13:13:41 +02:00
|
|
|
* @param string|int id either just the id or "app:id" if app==""
|
|
|
|
* @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
|
2011-08-23 16:29:56 +02:00
|
|
|
* @deprecated use egw.open()
|
2011-06-02 13:13:41 +02:00
|
|
|
*/
|
|
|
|
function egw_open(id, app, type, extra, target)
|
|
|
|
{
|
2011-08-26 09:31:18 +02:00
|
|
|
window.egw.open(id, app, type, extra, target);
|
2011-06-02 13:13:41 +02:00
|
|
|
}
|
|
|
|
|
2010-07-08 14:03:13 +02:00
|
|
|
window.egw_getFramework = function()
|
|
|
|
{
|
|
|
|
if (typeof window.framework != 'undefined')
|
|
|
|
{
|
|
|
|
return framework;
|
|
|
|
}
|
2013-01-18 00:29:14 +01:00
|
|
|
else if (typeof window.parent.egw_getFramework != "undefined" && window != window.parent)
|
2010-07-08 14:03:13 +02:00
|
|
|
{
|
|
|
|
return window.parent.egw_getFramework();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-12 16:46:14 +01:00
|
|
|
/**
|
|
|
|
* Register a custom method to refresh an application in an intelligent way
|
|
|
|
*
|
|
|
|
* This function will be called any time the application needs to be refreshed.
|
|
|
|
* The default is to just reload, but with more detailed knowledge of the application
|
|
|
|
* internals, it should be possible to only refresh what is needed.
|
|
|
|
*
|
|
|
|
* The refresh function signature is:
|
|
|
|
* function (_msg, _app, _id, _type);
|
|
|
|
* returns void
|
|
|
|
* @see egw_refresh()
|
|
|
|
*
|
|
|
|
* @param appname String Name of the application
|
|
|
|
* @param refresh_func function to call when refreshing
|
|
|
|
*/
|
|
|
|
window.register_app_refresh = function(appname, refresh_func)
|
|
|
|
{
|
|
|
|
var framework = window.egw_getFramework();
|
|
|
|
if(framework != null && typeof framework.register_app_refresh == "function")
|
|
|
|
{
|
|
|
|
framework.register_app_refresh(appname,refresh_func);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(typeof window.app_refresh != "function")
|
|
|
|
{
|
|
|
|
// Define the app_refresh stuff here
|
|
|
|
window.app_refresh = function(_msg, appname, _id, _type) {
|
|
|
|
if(window.app_refresh.registry[appname])
|
|
|
|
{
|
|
|
|
window.app_refresh.registry[appname].call(this,_msg,appname,_id,_type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.app_refresh.registry = {};
|
|
|
|
window.app_refresh.registered = function(appname) {
|
|
|
|
return (typeof window.app_refresh.registry[appname] == "function");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
window.app_refresh.registry[appname] = refresh_func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:03:13 +02:00
|
|
|
|
2010-04-16 15:24:58 +02:00
|
|
|
function egw_set_checkbox_multiselect_enabled(_id, _enabled)
|
|
|
|
{
|
|
|
|
//Retrieve the checkbox_multiselect base div
|
|
|
|
var ms = document.getElementById('exec['+_id+']');
|
|
|
|
if (ms !== null)
|
|
|
|
{
|
|
|
|
//Set the background color
|
|
|
|
var label_color = "";
|
|
|
|
if (_enabled)
|
|
|
|
{
|
|
|
|
ms.style.backgroundColor = "white";
|
|
|
|
label_color = "black";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ms.style.backgroundColor = "#EEEEEE";
|
|
|
|
label_color = "gray"
|
|
|
|
}
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2010-04-16 15:24:58 +02:00
|
|
|
//Enable/Disable all children input elements
|
|
|
|
for (var i = 0; i <ms.childNodes.length; i++)
|
|
|
|
{
|
|
|
|
if (ms.childNodes[i].nodeName == 'LABEL')
|
|
|
|
{
|
|
|
|
ms.childNodes[i].style.color = label_color;
|
|
|
|
if ((ms.childNodes[i].childNodes.length >= 1) &&
|
|
|
|
(ms.childNodes[i].childNodes[0].nodeName == 'INPUT'))
|
|
|
|
{
|
|
|
|
ms.childNodes[i].childNodes[0].disabled = !_enabled;
|
|
|
|
ms.childNodes[i].childNodes[0].checked &= _enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-19 00:09:31 +02:00
|
|
|
|
2014-12-01 11:44:51 +01:00
|
|
|
/**
|
|
|
|
* Open a (centered) popup window with given size and url
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
* @param {string} _windowName or "_blank"
|
|
|
|
* @param {number} _width
|
|
|
|
* @param {number} _height
|
|
|
|
* @param {type} _status "yes" or "no" to display status bar of popup
|
|
|
|
* @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
|
|
|
|
* @returns {DOMWindow|undefined}
|
|
|
|
* @deprecated use egw.openPopup(_url, _width, _height, _windowName, _app, _returnID, _status)
|
|
|
|
*/
|
2010-06-11 14:31:29 +02:00
|
|
|
function egw_openWindowCentered2(_url, _windowName, _width, _height, _status, _app, _returnID)
|
2005-08-28 22:32:15 +02:00
|
|
|
{
|
2014-12-01 11:44:51 +01:00
|
|
|
return egw(window).openPopup(_url, _width, _height, _windowName, _app, _returnID, _status);
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2009-07-07 11:58:20 +02:00
|
|
|
|
2014-12-01 11:44:51 +01:00
|
|
|
/**
|
|
|
|
* @deprecated use egw.openPopup(_url, _width, _height, _windowName, _app, _returnID, _status)
|
|
|
|
*/
|
2005-11-20 15:19:29 +01:00
|
|
|
function egw_openWindowCentered(_url, _windowName, _width, _height)
|
2005-10-24 09:29:12 +02:00
|
|
|
{
|
2010-06-11 14:31:29 +02:00
|
|
|
return egw_openWindowCentered2(_url, _windowName, _width, _height, 'no', false, true);
|
2005-10-24 09:29:12 +02:00
|
|
|
}
|
2005-08-28 22:32:15 +02:00
|
|
|
|
|
|
|
// return the left position of the window
|
|
|
|
function egw_getWindowLeft()
|
|
|
|
{
|
2011-06-03 12:14:12 +02:00
|
|
|
// workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception
|
|
|
|
try {
|
|
|
|
if(is_mozilla) return window.screenX;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2011-06-03 12:14:12 +02:00
|
|
|
catch (e) {}
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2011-06-03 12:14:12 +02:00
|
|
|
return window.screenLeft;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// return the left position of the window
|
|
|
|
function egw_getWindowTop()
|
|
|
|
{
|
2011-06-03 12:14:12 +02:00
|
|
|
// workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception
|
|
|
|
try {
|
|
|
|
if(is_mozilla) return window.screenY;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2011-06-03 12:14:12 +02:00
|
|
|
catch (e) {}
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2011-06-03 12:14:12 +02:00
|
|
|
return window.screenTop-90;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the outerWidth of the browser window. For IE we simply return the innerWidth
|
|
|
|
function egw_getWindowInnerWidth()
|
|
|
|
{
|
|
|
|
if (is_mozilla)
|
|
|
|
{
|
|
|
|
return window.innerWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// works only after the body has parsed
|
|
|
|
//return document.body.offsetWidth;
|
|
|
|
return document.body.clientWidth;
|
|
|
|
//return document.documentElement.clientWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the outerHeight of the browser window. For IE we simply return the innerHeight
|
|
|
|
function egw_getWindowInnerHeight()
|
|
|
|
{
|
|
|
|
if (is_mozilla)
|
|
|
|
{
|
|
|
|
return window.innerHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// works only after the body has parsed
|
|
|
|
//return document.body.offsetHeight;
|
|
|
|
//return document.body.clientHeight;
|
|
|
|
return document.documentElement.clientHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the outerWidth of the browser window. For IE we simply return the innerWidth
|
|
|
|
function egw_getWindowOuterWidth()
|
|
|
|
{
|
2011-06-03 12:14:12 +02:00
|
|
|
// workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception
|
|
|
|
try {
|
|
|
|
if (is_mozilla) return window.outerWidth;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2011-06-03 12:14:12 +02:00
|
|
|
catch (e) {}
|
|
|
|
|
|
|
|
return egw_getWindowInnerWidth();
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the outerHeight of the browser window. For IE we simply return the innerHeight
|
|
|
|
function egw_getWindowOuterHeight()
|
|
|
|
{
|
2011-06-03 12:14:12 +02:00
|
|
|
// workaround for Fennec bug https://bugzilla.mozilla.org/show_bug.cgi?format=multiple&id=648250 window.(outerHeight|outerWidth|screenX|screenY) throw exception
|
|
|
|
try {
|
|
|
|
if (is_mozilla) return window.outerHeight;
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2011-06-03 12:14:12 +02:00
|
|
|
catch (e) {}
|
2013-11-19 09:36:08 +01:00
|
|
|
|
2011-06-03 12:14:12 +02:00
|
|
|
return egw_getWindowInnerHeight();
|
2005-08-28 22:32:15 +02:00
|
|
|
}
|
2010-02-12 10:04:44 +01:00
|
|
|
|
|
|
|
// ie selectbox dropdown menu hack. as ie is not able to resize dropdown menus from selectboxes, we
|
2013-11-19 09:36:08 +01:00
|
|
|
// read the content of the dropdown menu and present it as popup resized for the user. if the user
|
2010-02-12 10:04:44 +01:00
|
|
|
// clicks/seleckts a value, the selection is posted back to the origial selectbox
|
|
|
|
function dropdown_menu_hack(el)
|
|
|
|
{
|
|
|
|
if(el.runtimeStyle)
|
|
|
|
{
|
2013-12-19 11:19:14 +01:00
|
|
|
if(typeof(enable_ie_dropdownmenuhack) !== 'undefined')
|
|
|
|
{
|
|
|
|
if (enable_ie_dropdownmenuhack==1){
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
2010-02-12 10:04:44 +01:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(el.runtimeStyle.behavior.toLowerCase()=="none"){return;}
|
|
|
|
el.runtimeStyle.behavior="none";
|
|
|
|
|
|
|
|
if (el.multiple ==1) {return;}
|
|
|
|
if (el.size > 1) {return;}
|
|
|
|
|
|
|
|
var ie5 = (document.namespaces==null);
|
|
|
|
el.ondblclick = function(e)
|
|
|
|
{
|
|
|
|
window.event.returnValue=false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(window.createPopup==null)
|
|
|
|
{
|
|
|
|
var fid = "dropdown_menu_hack_" + Date.parse(new Date());
|
|
|
|
|
|
|
|
window.createPopup = function()
|
|
|
|
{
|
|
|
|
if(window.createPopup.frameWindow==null)
|
|
|
|
{
|
|
|
|
el.insertAdjacentHTML("MyFrame","<iframe id='"+fid+"' name='"+fid+"' src='about:blank' frameborder='1' scrolling='no'></></iframe>");
|
|
|
|
var f = document.frames[fid];
|
|
|
|
f.document.open();
|
|
|
|
f.document.write("<html><body></body></html>");
|
|
|
|
f.document.close();
|
|
|
|
f.fid = fid;
|
|
|
|
|
|
|
|
|
|
|
|
var fwin = document.getElementById(fid);
|
|
|
|
fwin.style.cssText="position:absolute;top:0;left:0;display:none;z-index:99999;";
|
|
|
|
|
|
|
|
|
|
|
|
f.show = function(px,py,pw,ph,baseElement)
|
|
|
|
{
|
|
|
|
py = py + baseElement.getBoundingClientRect().top + Math.max( document.body.scrollTop, document.documentElement.scrollTop) ;
|
|
|
|
px = px + baseElement.getBoundingClientRect().left + Math.max( document.body.scrollLeft, document.documentElement.scrollLeft) ;
|
|
|
|
fwin.style.width = pw + "px";
|
|
|
|
fwin.style.height = ph + "px";
|
|
|
|
fwin.style.posLeft =px ;
|
|
|
|
fwin.style.posTop = py ;
|
|
|
|
fwin.style.display="block";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
f_hide = function(e)
|
|
|
|
{
|
|
|
|
if(window.event && window.event.srcElement && window.event.srcElement.tagName && window.event.srcElement.tagName.toLowerCase()=="select"){return true;}
|
|
|
|
fwin.style.display="none";
|
|
|
|
}
|
|
|
|
f.hide = f_hide;
|
|
|
|
document.attachEvent("onclick",f_hide);
|
|
|
|
document.attachEvent("onkeydown",f_hide);
|
|
|
|
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showMenu()
|
|
|
|
{
|
|
|
|
|
|
|
|
function selectMenu(obj)
|
|
|
|
{
|
|
|
|
var o = document.createElement("option");
|
|
|
|
o.value = obj.value;
|
|
|
|
//alert("val"+o.value+', text:'+obj.innerHTML+'selected:'+obj.selectedIndex);
|
|
|
|
o.text = obj.innerHTML;
|
|
|
|
o.text = o.text.replace('<NOBR>','');
|
|
|
|
o.text = o.text.replace('</NOBR>','');
|
|
|
|
//if there is no value, you should not try to set the innerHTML, as it screws up the empty selection ...
|
|
|
|
if (o.value != '') o.innerHTML = o.text;
|
|
|
|
while(el.options.length>0){el.options[0].removeNode(true);}
|
|
|
|
el.appendChild(o);
|
|
|
|
el.title = o.innerHTML;
|
|
|
|
el.contentIndex = obj.selectedIndex ;
|
|
|
|
el.menu.hide();
|
|
|
|
if(el.onchange)
|
|
|
|
{
|
|
|
|
el.onchange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
el.menu.show(0 , el.offsetHeight , 10, 10, el);
|
|
|
|
var mb = el.menu.document.body;
|
|
|
|
|
|
|
|
mb.style.cssText ="border:solid 1px black;margin:0;padding:0;overflow-y:auto;overflow-x:auto;background:white;font:12px Tahoma, sans-serif;";
|
|
|
|
var t = el.contentHTML;
|
|
|
|
//alert("1"+t);
|
|
|
|
t = t.replace(/<select/gi,'<div');
|
|
|
|
//alert("2"+t);
|
|
|
|
t = t.replace(/<option/gi,'<span');
|
|
|
|
//alert("3"+t);
|
|
|
|
t = t.replace(/<\/option/gi,'</span');
|
|
|
|
//alert("4"+t);
|
|
|
|
t = t.replace(/<\/select/gi,'</div');
|
|
|
|
t = t.replace(/<optgroup label=\"([\w\s\wäöüßÄÖÜ]*[^>])*">/gi,'<span value="i-opt-group-lable-i">$1</span>');
|
|
|
|
t = t.replace(/<\/optgroup>/gi,'<span value="">---</span>');
|
|
|
|
mb.innerHTML = t;
|
|
|
|
//mb.innerHTML = "<div><span value='dd:ff'>gfgfg</span></div>";
|
|
|
|
|
|
|
|
el.select = mb.all.tags("div")[0];
|
|
|
|
el.select.style.cssText="list-style:none;margin:0;padding:0;";
|
|
|
|
mb.options = el.select.getElementsByTagName("span");
|
|
|
|
|
|
|
|
for(var i=0;i<mb.options.length;i++)
|
|
|
|
{
|
|
|
|
//alert('Value:'+mb.options[i].value + ', Text:'+ mb.options[i].innerHTML);
|
|
|
|
mb.options[i].selectedIndex = i;
|
|
|
|
mb.options[i].style.cssText = "list-style:none;margin:0;padding:1px 2px;width/**/:100%;white-space:nowrap;"
|
|
|
|
if (mb.options[i].value != 'i-opt-group-lable-i') mb.options[i].style.cssText = mb.options[i].style.cssText + "cursor:hand;cursor:pointer;";
|
|
|
|
mb.options[i].title =mb.options[i].innerHTML;
|
|
|
|
mb.options[i].innerHTML ="<nobr>" + mb.options[i].innerHTML + "</nobr>";
|
|
|
|
if (mb.options[i].value == 'i-opt-group-lable-i') mb.options[i].innerHTML = "<b><i>"+mb.options[i].innerHTML+"</b></i>";
|
|
|
|
if (mb.options[i].value != 'i-opt-group-lable-i') mb.options[i].onmouseover = function()
|
|
|
|
{
|
|
|
|
if( mb.options.selected )
|
|
|
|
{mb.options.selected.style.background="white";mb.options.selected.style.color="black";}
|
|
|
|
mb.options.selected = this;
|
|
|
|
this.style.background="#333366";this.style.color="white";
|
|
|
|
}
|
|
|
|
mb.options[i].onmouseout = function(){this.style.background="white";this.style.color="black";}
|
2013-11-19 09:36:08 +01:00
|
|
|
if (mb.options[i].value != 'i-opt-group-lable-i')
|
2010-02-12 10:04:44 +01:00
|
|
|
{
|
|
|
|
mb.options[i].onmousedown = function(){selectMenu(this); }
|
|
|
|
mb.options[i].onkeydown = function(){selectMenu(this); }
|
|
|
|
}
|
|
|
|
if(i == el.contentIndex)
|
|
|
|
{
|
|
|
|
mb.options[i].style.background="#333366";
|
|
|
|
mb.options[i].style.color="white";
|
|
|
|
mb.options.selected = mb.options[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var mw = Math.max( ( el.select.offsetWidth + 22 ), el.offsetWidth + 22 );
|
|
|
|
mw = Math.max( mw, ( mb.scrollWidth+22) );
|
|
|
|
var mh = mb.options.length * 15 + 8 ;
|
|
|
|
var mx = (ie5)?-3:0;
|
|
|
|
var docW = document.documentElement.offsetWidth ;
|
|
|
|
var sideW = docW - el.getBoundingClientRect().left ;
|
|
|
|
if (sideW < mw)
|
|
|
|
{
|
|
|
|
//alert(el.getBoundingClientRect().left+' Avail: '+docW+' Mx:'+mx+' My:'+my);
|
|
|
|
// if it does not fit into the window on the right side, move it to the left
|
|
|
|
mx = mx -mw + sideW-5;
|
|
|
|
}
|
|
|
|
var my = el.offsetHeight -2;
|
|
|
|
my=my+5;
|
|
|
|
var docH = document.documentElement.offsetHeight ;
|
|
|
|
var bottomH = docH - el.getBoundingClientRect().bottom ;
|
|
|
|
mh = Math.min(mh, Math.max(( docH - el.getBoundingClientRect().top - 50),100) );
|
|
|
|
if(( bottomH < mh) )
|
|
|
|
{
|
|
|
|
mh = Math.max( (bottomH - 12),10);
|
|
|
|
if( mh <100 )
|
|
|
|
{
|
|
|
|
my = -100 ;
|
|
|
|
}
|
|
|
|
mh = Math.max(mh,100);
|
|
|
|
}
|
|
|
|
self.focus();
|
|
|
|
el.menu.show( mx , my , mw, mh , el);
|
|
|
|
sync=null;
|
|
|
|
if(mb.options.selected)
|
|
|
|
{
|
|
|
|
mb.scrollTop = mb.options.selected.offsetTop;
|
|
|
|
}
|
|
|
|
window.onresize = function(){el.menu.hide()};
|
|
|
|
}
|
|
|
|
|
|
|
|
function switchMenu()
|
|
|
|
{
|
|
|
|
if(event.keyCode)
|
|
|
|
{
|
|
|
|
if(event.keyCode==40){ el.contentIndex++ ;}
|
|
|
|
else if(event.keyCode==38){ el.contentIndex--; }
|
|
|
|
}
|
|
|
|
else if(event.wheelDelta )
|
|
|
|
{
|
|
|
|
if (event.wheelDelta >= 120)
|
|
|
|
el.contentIndex++ ;
|
|
|
|
else if (event.wheelDelta <= -120)
|
|
|
|
el.contentIndex-- ;
|
|
|
|
}
|
|
|
|
else{return true;}
|
|
|
|
if( el.contentIndex > (el.contentOptions.length-1) ){ el.contentIndex =0;}
|
|
|
|
else if (el.contentIndex<0){el.contentIndex = el.contentOptions.length-1 ;}
|
|
|
|
var o = document.createElement("option");
|
|
|
|
o.value = el.contentOptions[el.contentIndex].value;
|
|
|
|
o.innerHTML = el.contentOptions[el.contentIndex].text;
|
|
|
|
while(el.options.length>0){el.options[0].removeNode(true);}
|
|
|
|
el.appendChild(o);
|
|
|
|
el.title = o.innerHTML;
|
|
|
|
}
|
|
|
|
if(dropdown_menu_hack.menu ==null)
|
|
|
|
{
|
|
|
|
dropdown_menu_hack.menu = window.createPopup();
|
|
|
|
document.attachEvent("onkeydown",dropdown_menu_hack.menu.hide);
|
|
|
|
}
|
|
|
|
el.menu = dropdown_menu_hack.menu ;
|
|
|
|
el.contentOptions = new Array();
|
|
|
|
el.contentIndex = el.selectedIndex;
|
|
|
|
el.contentHTML = el.outerHTML;
|
|
|
|
|
|
|
|
for(var i=0;i<el.options.length;i++)
|
|
|
|
{
|
|
|
|
|
|
|
|
el.contentOptions [el.contentOptions.length] =
|
|
|
|
{
|
|
|
|
"value": el.options[i].value,"text": el.options[i].innerHTML
|
2013-10-02 18:29:08 +02:00
|
|
|
};
|
2010-02-12 10:04:44 +01:00
|
|
|
if(!el.options[i].selected){el.options[i].removeNode(true);i--;};
|
|
|
|
}
|
|
|
|
el.onkeydown = switchMenu;
|
|
|
|
el.onclick = showMenu;
|
|
|
|
el.onmousewheel= switchMenu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 18:29:08 +02:00
|
|
|
/**
|
2014-02-07 15:04:12 +01:00
|
|
|
* Use frameworks (framed template) link handler to open a url
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2013-10-02 18:29:08 +02:00
|
|
|
* @param _link
|
|
|
|
* @param _app
|
2014-02-07 15:04:12 +01:00
|
|
|
* @deprecated use egw(window).link_handler(_link, _app) instead
|
2013-10-02 18:29:08 +02:00
|
|
|
*/
|
|
|
|
function egw_link_handler(_link, _app)
|
|
|
|
{
|
2014-02-07 15:04:12 +01:00
|
|
|
egw(window).link_handler(_link, _app);
|
2013-10-02 18:29:08 +02:00
|
|
|
}
|
2013-10-05 15:33:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Support functions for uiaccountselection class
|
2013-11-19 09:36:08 +01:00
|
|
|
*
|
2013-10-05 15:33:28 +02:00
|
|
|
* @ToDo: should be removed if uiaccountsel class is no longer in use
|
|
|
|
*/
|
|
|
|
function addOption(id,label,value,do_onchange)
|
|
|
|
{
|
|
|
|
selectBox = document.getElementById(id);
|
|
|
|
for (var i=0; i < selectBox.length; i++) {
|
|
|
|
// check existing entries if they're already there and only select them in that case
|
|
|
|
if (selectBox.options[i].value == value) {
|
|
|
|
selectBox.options[i].selected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= selectBox.length) {
|
|
|
|
if (!do_onchange) {
|
|
|
|
if (selectBox.length && selectBox.options[0].value=='') selectBox.options[0] = null;
|
|
|
|
selectBox.multiple=true;
|
|
|
|
selectBox.size=4;
|
|
|
|
}
|
|
|
|
selectBox.options[selectBox.length] = new Option(label,value,false,true);
|
|
|
|
}
|
|
|
|
if (selectBox.onchange && do_onchange) selectBox.onchange();
|
|
|
|
}
|
2018-02-06 18:00:36 +01:00
|
|
|
|
|
|
|
function egw_get_file_editor_prefered_mimes(_data, _params)
|
|
|
|
{
|
2018-02-07 12:38:07 +01:00
|
|
|
var fe = jQuery.extend(true, {},egw.link_get_registry('filemanager-editor'));
|
2018-02-06 18:00:36 +01:00
|
|
|
var ex_mimes = egw.preference('collab_excluded_mimes', 'filemanager');
|
|
|
|
if (fe && fe.mime && ex_mimes)
|
|
|
|
{
|
|
|
|
ex_mimes = ex_mimes.split(',');
|
|
|
|
for (var mime in fe.mime)
|
|
|
|
{
|
|
|
|
for (var i in ex_mimes)
|
|
|
|
{
|
|
|
|
if (ex_mimes[i] == mime) delete(fe.mime[mime]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fe && fe.mime?fe:null;
|
|
|
|
}
|
2013-10-05 15:33:28 +02:00
|
|
|
/**
|
|
|
|
* Install click handlers for popup and multiple triggers of uiaccountselection
|
|
|
|
*/
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(function(){
|
|
|
|
jQuery(document).on('click', '.uiaccountselection_trigger',function(){
|
2013-10-05 15:33:28 +02:00
|
|
|
var selectBox = document.getElementById(this.id.replace(/(_multiple|_popup)$/, ''));
|
|
|
|
if (selectBox)
|
|
|
|
{
|
|
|
|
var link = selectBox.getAttribute('data-popup-link');
|
|
|
|
|
2013-11-19 09:36:08 +01:00
|
|
|
if (selectBox.multiple || this.id.match(/_popup$/))
|
2013-10-05 15:33:28 +02:00
|
|
|
{
|
|
|
|
window.open(link, 'uiaccountsel', 'width=600,height=420,toolbar=no,scrollbars=yes,resizable=yes');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-19 09:36:08 +01:00
|
|
|
selectBox.size = 4;
|
|
|
|
selectBox.multiple = true;
|
2013-10-05 15:33:28 +02:00
|
|
|
if (selectBox.options[0].value=='') selectBox.options[0] = null;
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
if (!jQuery(selectBox).hasClass('groupmembers') && !jQuery(selectBox).hasClass('selectbox')) // no popup!
|
2013-10-05 15:33:28 +02:00
|
|
|
{
|
|
|
|
this.src = egw.image('search');
|
|
|
|
this.title = egw.lang('Search accounts');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-19 09:36:08 +01:00
|
|
|
this.style.display = 'none';
|
2013-10-05 15:33:28 +02:00
|
|
|
selectBox.style.width = '100%';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(document).on('change', 'select.uiaccountselection',function(e){
|
2013-10-05 15:33:28 +02:00
|
|
|
if (this.value == 'popup')
|
|
|
|
{
|
|
|
|
var link = this.getAttribute('data-popup-link');
|
|
|
|
window.open(link, 'uiaccountsel', 'width=600,height=420,toolbar=no,scrollbars=yes,resizable=yes');
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|