From 585e3138514b05d3b981dd66e7a69086cd28f093 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 17 Oct 2014 12:51:02 +0000 Subject: [PATCH] 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 --- addressbook/inc/class.addressbook_ui.inc.php | 10 +++++ json.php | 5 +++ mail/inc/class.mail_ui.inc.php | 4 +- phpgwapi/inc/class.egw_exception.inc.php | 45 +++++++++++++++++--- phpgwapi/inc/common_functions.inc.php | 5 +++ phpgwapi/js/jsapi/egw_json.js | 6 +++ 6 files changed, 67 insertions(+), 8 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 9aecc49323..e46a06e9d2 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -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(); diff --git a/json.php b/json.php index 2e04f3f730..28736362dd 100644 --- a/json.php +++ b/json.php @@ -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')) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index c6de002500..60826bb4a6 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -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(); diff --git a/phpgwapi/inc/class.egw_exception.inc.php b/phpgwapi/inc/class.egw_exception.inc.php index 8f156b9add..fb446466d0 100644 --- a/phpgwapi/inc/class.egw_exception.inc.php +++ b/phpgwapi/inc/class.egw_exception.inc.php @@ -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 { } \ No newline at end of file +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); + } +} diff --git a/phpgwapi/inc/common_functions.inc.php b/phpgwapi/inc/common_functions.inc.php index d129f793a9..0867fefa32 100755 --- a/phpgwapi/inc/common_functions.inc.php +++ b/phpgwapi/inc/common_functions.inc.php @@ -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); diff --git a/phpgwapi/js/jsapi/egw_json.js b/phpgwapi/js/jsapi/egw_json.js index bde4b1ae55..aceae865fc 100644 --- a/phpgwapi/js/jsapi/egw_json.js +++ b/phpgwapi/js/jsapi/egw_json.js @@ -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);