new javascript method egw_open() to open egw_entries using there registered url and popup sizes from the link registry

This commit is contained in:
Ralf Becker
2011-06-02 11:13:41 +00:00
parent 30bef48900
commit 47e2764da0
4 changed files with 143 additions and 5 deletions

View File

@ -209,6 +209,96 @@ function egw_refresh(_msg, _app, _id, _type)
win.location.href = href;
}
/**
* View an EGroupware entry: opens a popup of correct size or redirects window.location to requested url
*
* Examples:
* - 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'
*
* @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
*/
function egw_open(id, app, type, extra, target)
{
var registry = egw_topWindow().egw_link_registry;
if (typeof registry != 'object')
{
alert('egw_open() link registry is NOT defined!');
return;
}
if (!app)
{
var app_id = id.split(':',2);
app = app_id[0];
id = app_id[1];
}
if (!app || typeof registry[app] != 'object')
{
alert('egw_open() app "'+app+'" NOT defined in link registry!');
return;
}
var app_registry = registry[app];
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+'"!');
return;
}
var url = egw_webserverUrl+'/index.php';
var delimiter = '?';
var params = app_registry[type];
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];
}
for(var attr in params)
{
url += delimiter+attr+'='+encodeURIComponent(params[attr]);
delimiter = '&';
}
if (typeof extra == 'object')
{
for(var attr in extra)
{
url += delimiter+attr+'='+encodeURIComponent(extra[attr]);
}
}
else if (typeof extra == 'string')
{
url += delimiter + extra;
}
if (typeof app_registry[type+'_popup'] == 'undefined')
{
if (target)
{
window.open(url, target);
}
else
{
egw_appWindow(app).location = url;
}
}
else
{
var w_h = app_registry[type+'_popup'].split('x');
if (w_h[1] == 'egw_getWindowOuterHeight()') w_h[1] = egw_getWindowOuterHeight();
egw_openWindowCentered2(url, target, w_h[0], w_h[1], 'yes', app, false);
}
}
window.egw_getFramework = function()
{
if (typeof window.framework != 'undefined')