From 1590d02816504e5a46dc2dea65b67d8c3574608c Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 5 Sep 2013 11:53:25 +0000 Subject: [PATCH] new egw_framework::message($msg, $msg_type="success") method and fixing nextmatch filter-change to return app-header --- etemplate/inc/class.etemplate.inc.php | 5 ++- .../class.etemplate_widget_nextmatch.inc.php | 15 +++++++ etemplate/js/etemplate2.js | 9 +---- phpgwapi/inc/class.egw_framework.inc.php | 40 ++++++++++++------- phpgwapi/js/jsapi/egw.js | 10 +++++ phpgwapi/js/jsapi/jsapi.js | 27 +++++++++++-- 6 files changed, 81 insertions(+), 25 deletions(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 89af3d9d69..ad7537c486 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -115,7 +115,6 @@ class etemplate_new extends etemplate_widget_template self::$request->preserv = $preserv ? $preserv : array(); self::$request->method = $method; self::$request->ignore_validation = $ignore_validation; - self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header']; if (self::$request->output_mode == -1) self::$request->output_mode = 0; self::$request->template = $this->as_array(); @@ -125,6 +124,9 @@ class etemplate_new extends etemplate_widget_template $template = etemplate_widget_template::instance($this->name, $this->template_set, $this->version, $this->laod_via); $template->run('beforeSendToClient', array('', array('cont'=>$content))); + // some apps (eg. InfoLog) set app_header only in get_rows depending on filter settings + self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header']; + $data = array( 'etemplate_exec_id' => self::$request->id(), 'app_header' => self::$request->app_header, @@ -249,6 +251,7 @@ class etemplate_new extends etemplate_widget_template //error_log(__METHOD__."(,".array2string($content).')'); //error_log(' validated='.array2string($validated)); $content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); + if (isset($GLOBALS['egw_info']['flags']['java_script'])) { // Strip out any script tags diff --git a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php index 89c3ace874..89c1f97b6d 100644 --- a/etemplate/inc/class.etemplate_widget_nextmatch.inc.php +++ b/etemplate/inc/class.etemplate_widget_nextmatch.inc.php @@ -299,6 +299,14 @@ class etemplate_widget_nextmatch extends etemplate_widget $value['col_filter']['parent_id'] = $queriedRange['parent_id']; } + // Set current app for get_rows + list($app) = explode('.',self::$request->method); + if(!$app) list($app) = explode('::',self::$request->method); + if($app) + { + $GLOBALS['egw_info']['flags']['currentapp'] = $app; + translation::add_app($app); + } // If specific data requested, just do that if (($row_id = $value['row_id']) && $queriedRange['refresh']) { @@ -309,6 +317,12 @@ class etemplate_widget_nextmatch extends etemplate_widget $result['total'] = self::call_get_rows($value, $rows, $result['readonlys']); $result['lastModification'] = egw_time::to('now', 'ts')-1; + if (isset($GLOBALS['egw_info']['flags']['app_header']) && self::$request->app_header != $GLOBALS['egw_info']['flags']['app_header']) + { + self::$request->app_header = $GLOBALS['egw_info']['flags']['app_header']; + egw_json_response::get()->apply('egw_app_header', array($GLOBALS['egw_info']['flags']['app_header'])); + } + $row_id = isset($value['row_id']) ? $value['row_id'] : 'id'; $row_modified = $value['row_modified']; $is_parent = $value['is_parent']; @@ -389,6 +403,7 @@ class etemplate_widget_nextmatch extends etemplate_widget } }*/ } + //foreach($result as $name => $value) if ($name != 'readonlys') error_log(__METHOD__."() result['$name']=".array2string($name == 'data' ? array_keys($value) : $value)); egw_json_response::get()->data($result); } diff --git a/etemplate/js/etemplate2.js b/etemplate/js/etemplate2.js index e245f84cef..a9903254d7 100644 --- a/etemplate/js/etemplate2.js +++ b/etemplate/js/etemplate2.js @@ -226,13 +226,8 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback) // store the id to submit it back to server if(_data) { this.etemplate_exec_id = _data.etemplate_exec_id; - } - - // set app_header - if (window.opener && _data) { // popup - document.title = _data.app_header; - } else { - // todo for idots or jdots framework + // set app_header + window.egw_app_header(_data.app_header); } var _load = function() { diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index b8e248d7da..8b35baa1c0 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -173,7 +173,7 @@ abstract class egw_framework /** * Refresh given application $targetapp display of entry $app $id, incl. outputting $msg * - * Calling egw_refresh on opener in a content security save way + * Calling egw_refresh and egw_message on opener in a content security save way * * @param string $msg message (already translated) to show, eg. 'Entry deleted' * @param string $app application name @@ -182,13 +182,27 @@ abstract class egw_framework * @param string $targetapp=null which app's window should be refreshed, default current * @param string|RegExp $replace=null regular expression to replace in url * @param string $with=null + * @param string $msg_type=null 'error', 'warning' or 'success' (default) */ - public static function refresh_opener($msg, $app, $id=null, $type=null, $targetapp=null, $replace=null, $with=null) + public static function refresh_opener($msg, $app, $id=null, $type=null, $targetapp=null, $replace=null, $with=null, $msg_type=null) { //error_log(__METHOD__.'('.array2string(func_get_args()).')'); self::$extra['refresh-opener'] = func_get_args(); } + /** + * Display an error or regular message + * + * Calls egw_message on client-side in a content security save way + * + * @param string $msg message to show + * @param string $type='success' 'error', 'warning' or 'success' (default) + */ + function message($msg, $type='success') + { + self::$extra['message'] = func_get_args(); + } + /** * Close (popup) window, use to replace egw_framework::onload('window.close()') in a content security save way * @@ -385,17 +399,15 @@ abstract class egw_framework } } - if ($GLOBALS['egw_info']['flags']['app_header']) - { - $app = $GLOBALS['egw_info']['flags']['app_header']; - } - else - { - $app = $GLOBALS['egw_info']['flags']['currentapp']; - $app = isset($GLOBALS['egw_info']['apps'][$app]) ? $GLOBALS['egw_info']['apps'][$app]['title'] : lang($app); - } - $var = array(); - if($app!='wiki') $robots =''; + $app = $GLOBALS['egw_info']['flags']['currentapp']; + $app_title = isset($GLOBALS['egw_info']['apps'][$app]) ? $GLOBALS['egw_info']['apps'][$app]['title'] : lang($app); + $app_header = $GLOBALS['egw_info']['flags']['app_header'] ? $GLOBALS['egw_info']['flags']['app_header'] : $app_title; + $site_title = strip_tags($GLOBALS['egw_info']['server']['site_title'].' ['.($app_header ? $app_header : $app_title).']'); + + // send appheader to clientside + $extra['app-header'] = $app_header; + + if($GLOBALS['egw_info']['flags']['currentapp'] != 'wiki') $robots =''; if (substr($GLOBALS['egw_info']['server']['favicon_file'],0,4) == 'http') { $var['favicon_file'] = $GLOBALS['egw_info']['server']['favicon_file']; @@ -417,7 +429,7 @@ abstract class egw_framework 'pngfix' => $pngfix, 'lang_code' => $lang_code, 'charset' => translation::charset(), - 'website_title' => strip_tags($GLOBALS['egw_info']['server']['site_title']. ($app ? " [$app]" : '')), + 'website_title' => $site_title, 'body_tags' => self::_get_body_attribs(), 'java_script' => self::_get_js($extra), 'meta_robots' => $robots, diff --git a/phpgwapi/js/jsapi/egw.js b/phpgwapi/js/jsapi/egw.js index b7b845d560..48a017720b 100644 --- a/phpgwapi/js/jsapi/egw.js +++ b/phpgwapi/js/jsapi/egw.js @@ -158,6 +158,16 @@ et2.load(data.name,data.url,data.data,callback); } } + // set app-header + if (window.framework && (data = egw_script.getAttribute('data-app-header'))) + { + window.egw_app_header(data); + } + // display a message + if ((data = egw_script.getAttribute('data-message')) && (data = JSON.parse(data))) + { + window.egw_message.apply(window, data); + } }); /** diff --git a/phpgwapi/js/jsapi/jsapi.js b/phpgwapi/js/jsapi/jsapi.js index 8cd8234a5c..dc6ea593e7 100644 --- a/phpgwapi/js/jsapi/jsapi.js +++ b/phpgwapi/js/jsapi/jsapi.js @@ -281,8 +281,7 @@ function egw_message(_msg, _type) { framework.setMessage.call(window.framework, _msg, _type); return; - } - + } // handle message display for non-framework templates, eg. idots or jerryr if (window.egw_message_timer) { @@ -299,7 +298,29 @@ function egw_message(_msg, _type) $j('div#divAppboxHeader').text(document.title.replace(/^.*\[(.*)\]$/, '$1')); }, 5000); } -}; +} + +/** + * Update app-header and website-title + * + * @param _header + */ +function egw_app_header(_header) +{ + var framework = egw_getFramework(); + if (framework && !window.opener) // not for popups + { + var app = egw_getAppName(); + var title = document.title.replace(/[.*]$/, '['+_header+']'); + + framework.setWebsiteTitle.call(window.framework, app, title, _header); + return; + } + + $j('div#divAppboxHeader').text(_header); + + document.title = document.title.replace(/[.*]$/, '['+_header+']'); +} /** * View an EGroupware entry: opens a popup of correct size or redirects window.location to requested url