new egw_framework::message($msg, $msg_type="success") method and fixing nextmatch filter-change to return app-header

This commit is contained in:
Ralf Becker 2013-09-05 11:53:25 +00:00
parent b1aca92a9e
commit 1590d02816
6 changed files with 81 additions and 25 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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() {

View File

@ -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 ='<meta name="robots" content="none" />';
$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 ='<meta name="robots" content="none" />';
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,

View File

@ -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);
}
});
/**

View File

@ -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