fix redirects in a popup and new egw_exception_redirect to be used in hooks/callbacks like for addressbook.edit to redirect to a different location

r49022: resize import popup to regular compose size
This commit is contained in:
Ralf Becker 2014-10-17 12:51:02 +00:00
parent b1f48200e6
commit 585e313851
6 changed files with 67 additions and 8 deletions

View File

@ -1786,6 +1786,10 @@ window.egw_LAB.wait(function() {
$content['msg'] .= ', '.$success_msg;
}
}
catch(egw_exception_redirect $r)
{
// catch it to continue execution and rethrow it later
}
catch (Exception $ex) {
$content['msg'] .= ', '.$ex->getMessage();
$button = 'apply'; // do not close dialog
@ -1832,6 +1836,12 @@ window.egw_LAB.wait(function() {
}
egw_framework::refresh_opener($content['msg'], 'addressbook', $content['id'], $content['id'] ? 'update' : 'add',
null, null, null, $this->error ? 'error' : 'success');
// re-throw redirect exception, if there's no error
if (!$this->error && isset($r))
{
throw $r;
}
if ($button == 'save')
{
egw_framework::window_close();

View File

@ -35,6 +35,11 @@ function login_redirect(&$anon_account)
*/
function ajax_exception_handler(Exception $e)
{
// handle redirects without logging
if (is_a($e, 'egw_exception_redirect'))
{
egw::redirect($e->url, $e->app);
}
// logging all exceptions to the error_log
$message = null;
if (function_exists('_egw_log_exception'))

View File

@ -3112,8 +3112,10 @@ class mail_ui
}
if (!$importFailed)
{
list($width, $height) = explode('x', egw_link::get_registry('mail', 'add_popup'));
if ($width > 0 && $height > 0) egw_json_response::get()->call('resizeTo', $width, $height);
ExecMethod2('mail.mail_ui.displayMessage',$linkData);
exit;
return;
}
}
if (!is_array($content)) $content = array();

View File

@ -27,6 +27,10 @@
class egw_exception extends Exception
{
// nothing fancy yet
function __construct($msg=null,$code=100,Exception $previous=null)
{
return parent::__construct($msg, $code, $previous);
}
}
/**
@ -38,8 +42,8 @@ class egw_exception_no_permission extends egw_exception
/**
* Constructor
*
* @param string $msg=null message, default "Permission denied!"
* @param int $code=100 numerical code, default 100
* @param string $msg =null message, default "Permission denied!"
* @param int $code =100 numerical code, default 100
*/
function __construct($msg=null,$code=100)
{
@ -106,8 +110,8 @@ class egw_exception_not_found extends egw_exception
/**
* Constructor
*
* @param string $msg=null message, default "Entry not found!"
* @param int $code=99 numerical code, default 2
* @param string $msg =null message, default "Entry not found!"
* @param int $code =99 numerical code, default 2
*/
function __construct($msg=null,$code=2)
{
@ -145,8 +149,8 @@ class egw_exception_db extends egw_exception
/**
* Constructor
*
* @param string $msg=null message, default "Database error!"
* @param int $code=100
* @param string $msg =null message, default "Database error!"
* @param int $code =100
*/
function __construct($msg=null,$code=100)
{
@ -179,4 +183,31 @@ class egw_exception_db_invalid_sql extends egw_exception_db { }
/**
* EGroupware not (fully) installed, visit setup
*/
class egw_exception_db_setup extends egw_exception_db { }
class egw_exception_db_setup extends egw_exception_db { }
/**
* Allow callbacks to request a redirect
*
* Can be caught be applications and is otherwise handled by global exception handler.
*/
class egw_exception_redirect extends egw_exception
{
public $url;
public $app;
/**
* Constructor
*
* @param string $url
* @param string $app
* @param string $msg
* @param int $code
*/
function __construct($url,$app=null,$msg=null,$code=301)
{
$this->url = $url;
$this->app = $app;
parent::__construct($msg, $code);
}
}

View File

@ -1709,6 +1709,11 @@ function _egw_log_exception(Exception $e,&$headline=null)
*/
function egw_exception_handler(Exception $e)
{
// handle redirects without logging
if (is_a($e, 'egw_exception_redirect'))
{
egw::redirect($e->url, $e->app);
}
// logging all exceptions to the error_log (if not cli) and get headline
$headline = null;
_egw_log_exception($e,$headline);

View File

@ -406,6 +406,12 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
{
egw_topWindow().location.href = res.data.url;
}
// json request was originating from a different window --> redirect that one
else if(this.DOMContainer && this.DOMContainer.ownerDocument.defaultView != window)
{
this.DOMContainer.ownerDocument.location.href = res.data.url;
}
// main window, open url in respective tab
else
{
egw_appWindowOpen(res.data.app, res.data.url);