mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
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:
parent
30bef48900
commit
47e2764da0
@ -745,7 +745,15 @@ abstract class egw_framework
|
||||
|
||||
// set webserver_url for json
|
||||
$java_script .= "<script type=\"text/javascript\">\nwindow.egw_webserverUrl = '".
|
||||
$GLOBALS['egw_info']['server']['webserver_url']."';\n</script>\n";
|
||||
($GLOBALS['egw_info']['server']['enforce_ssl'] && substr($GLOBALS['egw_info']['server']['webserver_url'],0,8) != 'https://' ? 'https://'.$_SERVER['HTTP_HOST'] : '').
|
||||
$GLOBALS['egw_info']['server']['webserver_url']."';\n";
|
||||
|
||||
// add link registry to non-popup windows, if explicit requested (idots_framework::navbar() loads it, if not explicit specified!)
|
||||
if ($GLOBALS['egw_info']['flags']['js_link_registry'])
|
||||
{
|
||||
$java_script .= 'window.egw_link_registry='.egw_link::json_registry().';';
|
||||
}
|
||||
$java_script .= "</script>\n";
|
||||
|
||||
/* this flag is for all javascript code that has to be put before other jscode.
|
||||
Think of conf vars etc... (pim@lingewoud.nl) */
|
||||
|
@ -45,7 +45,11 @@
|
||||
* ),
|
||||
* 'view_id' => 'app_id', // name of get parameter of the id
|
||||
* 'view_popup' => '400x300', // size of popup (XxY), if view is in popup
|
||||
* 'view_list' => 'app.class.method' // Method to be called to display a list of links, method should check $_GET['search'] to filter
|
||||
* 'view_list' => 'app.class.method' // deprecated use 'list' instead
|
||||
* 'list' => array( // Method to be called to display a list of links, method should check $_GET['search'] to filter
|
||||
* 'menuaction' => 'app.class.method',
|
||||
* ),
|
||||
* 'list_popup' => '400x300'
|
||||
* 'add' => array( // get parameter to add an empty entry to app
|
||||
* 'menuaction' => 'app.class.method',
|
||||
* ),
|
||||
@ -156,6 +160,15 @@ class egw_link extends solink
|
||||
}
|
||||
unset($data['additional']);
|
||||
}
|
||||
// support deprecated view_list attribute instead of new index attribute
|
||||
if (isset($data['view_list']) && !isset($data['list']))
|
||||
{
|
||||
$data['list'] = array('menuaction' => $data['view_list']);
|
||||
}
|
||||
elseif(isset($data['list']) && !isset($data['view_list']))
|
||||
{
|
||||
$data['view_list'] = $data['list']['menuaction'];
|
||||
}
|
||||
if (is_array($data))
|
||||
{
|
||||
self::$app_register[$app] = $data;
|
||||
@ -173,6 +186,28 @@ class egw_link extends solink
|
||||
//error_log(__METHOD__.'() items in title-cache: '.count(self::$title_cache).' file-access-cache: '.count(self::$file_access_cache));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get clientside relevant attributes from app registry in json format
|
||||
*
|
||||
* Only transfering relevant information cuts approx. half of the size.
|
||||
*
|
||||
* @return string json encoded object with app: object pairs with attributes "(view|add|edit)(|_id|_popup)"
|
||||
*/
|
||||
public static function json_registry()
|
||||
{
|
||||
$to_json = array();
|
||||
foreach(self::$app_register as $app => $data)
|
||||
{
|
||||
$to_json[$app] = array_intersect_key($data, array_flip(array(
|
||||
'view','view_id','view_popup',
|
||||
'add','add_app','add_id','add_popup',
|
||||
'edit','edit_id','edit_popup',
|
||||
'list','list_popup',
|
||||
)));
|
||||
}
|
||||
return json_encode($to_json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by egw::egw_final to store the title-cache in the session
|
||||
*
|
||||
|
@ -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')
|
||||
|
@ -89,7 +89,7 @@ class idots_framework extends egw_framework
|
||||
self::$header_done = true;
|
||||
|
||||
// add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv)
|
||||
header('Content-type: text/html; charset='.$GLOBALS['egw']->translation->charset());
|
||||
header('Content-type: text/html; charset='.translation::charset());
|
||||
|
||||
// catch error echo'ed before the header, ob_start'ed in the header.inc.php
|
||||
$content = ob_get_contents();
|
||||
@ -147,9 +147,14 @@ class idots_framework extends egw_framework
|
||||
$apps = $this->_get_navbar_apps();
|
||||
$vars = $this->_get_navbar($apps);
|
||||
|
||||
// add link registry to non-popup windows
|
||||
if (!isset($GLOBALS['egw_info']['flags']['js_link_registry']))
|
||||
{
|
||||
$content .= '<script type="text/javascript">'."\nwindow.egw_link_registry=".egw_link::json_registry().";\n</script>\n";
|
||||
}
|
||||
if($GLOBALS['egw_info']['user']['preferences']['common']['show_general_menu'] != 'sidebox')
|
||||
{
|
||||
$content = $this->topmenu($vars,$apps);
|
||||
$content .= $this->topmenu($vars,$apps);
|
||||
$vars['current_users'] = $vars['quick_add'] = $vars['user_info']='';
|
||||
}
|
||||
|
||||
@ -189,7 +194,7 @@ class idots_framework extends egw_framework
|
||||
$GLOBALS['egw']->hooks->single('sidebox_menu',$GLOBALS['egw_info']['flags']['currentapp']);
|
||||
|
||||
// allow other apps to hook into sidebox menu of every app: sidebox_all
|
||||
$GLOBALS['egw']->hooks->process('sidebox_all',array($GLOBALS['egw_info']['flags']['currentapp']),true);
|
||||
$GLOBALS['egw']->hooks->process('sidebox_all',array($GLOBALS['egw_info']['flags']['currentapp']),true);
|
||||
|
||||
if($this->sidebox_content)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user