move egw_(message|app_header) from jsapi.js to egw_message.js available as egw(window).message(_msg, _type) and make it usable in popups too

This commit is contained in:
Ralf Becker 2014-02-06 15:42:33 +00:00
parent e6f96648a3
commit 6a8802fc35
5 changed files with 135 additions and 54 deletions

View File

@ -33,7 +33,7 @@
egw_data;
egw_tail;
egw_inheritance;
// egw_jquery;
egw_message;
app_base;
*/
@ -135,11 +135,7 @@
// If there's a message & opener, set it
if(window.opener && egw_script.getAttribute('data-message'))
{
var data = {};
if ((data = egw_script.getAttribute('data-message')) && (data = JSON.parse(data)))
{
window.opener.egw_message.apply(window.opener, data);
}
egw(window.opener).message(JSON.parse(egw_script.getAttribute('data-message')));
}
window.close();
}
@ -235,14 +231,14 @@
}
$j(function() {
// set app-header
if (window.framework && (data = egw_script.getAttribute('data-app-header')))
if (window.framework && egw_script.getAttribute('data-app-header'))
{
window.egw_app_header(data);
egw(window).app_header(egw_script.getAttribute('data-app-header'));
}
// display a message
if ((data = egw_script.getAttribute('data-message')) && (data = JSON.parse(data)))
if (egw_script.getAttribute('data-message'))
{
window.egw_message.apply(window, data);
egw(window).message(JSON.parse(egw_script.getAttribute('data-message')));
}
});
});

View File

@ -237,7 +237,7 @@ egw.extend('debug', egw.MODULE_GLOBAL, function(_app, _wnd) {
log_on_client('error', [e.originalEvent.message]);
raise_error();
// rethrow error to let browser log and show it in usual way too
throw e;
throw e.originalEvent;
});
/**

View File

@ -0,0 +1,104 @@
/**
* EGroupware clientside API object
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker@outdoor-training.de>
* @version $Id$
*/
"use strict";
/*egw:uses
egw_core;
*/
/**
* Methods to display a success or error message and the app-header
*
* @augments Class
* @param {string} _app application name object is instanciated for
* @param {object} _wnd window object is instanciated for
*/
egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
{
_app; // not used, but required by function signature
var message_timer;
var jQuery = _wnd.jQuery;
var framework = _wnd.framework;
var is_popup = !framework || _wnd.opener;
return {
/**
* Display an error or regular message
*
* @param {string} _msg message to show
* @param {string} _type 'error', 'warning' or 'success' (default)
*/
message: function(_msg, _type)
{
if (typeof _type == 'undefined')
_type = _msg.match(/error/i) ? 'error' : 'success';
// if we are NOT in a popup and have a framwork --> let it deal with it
if (!is_popup && typeof framework.setMessage != 'undefined')
{
// currently not using framework, but top windows message
//framework.setMessage.call(framework, _msg, _type);
if (_wnd !== _wnd.top)
{
egw(_wnd.top).message(_msg, _type);
return;
}
}
// handle message display for non-framework templates, eg. idots or jerryr
if (message_timer)
{
_wnd.clearTimeout(message_timer);
message_timer = null;
}
var parent = jQuery('div#divAppboxHeader');
// popup has no app-header (idots) or it is hidden by onlyPrint class (jdots) --> use body
if (!parent.length || parent.hasClass('onlyPrint'))
{
parent = jQuery('body');
}
jQuery('div#egw_message').remove();
parent.prepend(jQuery(_wnd.document.createElement('div'))
.attr('id','egw_message')
.text(_msg)
.addClass(_type+'_message')
.css('position', 'absolute'));
if (_type != 'error') // clear message again after some time, if no error
{
message_timer = _wnd.setTimeout(function() {
jQuery('div#egw_message').remove();
}, 5000);
}
},
/**
* Update app-header and website-title
*
* @param {string} _header
* @param {string} _app Application name, if not for the current app
*/
app_header: function(_header,_app)
{
if (!is_popup) // not for popups
{
var app = _app || egw_getAppName();
var title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
framework.setWebsiteTitle.call(window.framework, app, title, _header);
return;
}
jQuery('div#divAppboxHeader').text(_header);
_wnd.document.title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
}
};
});

View File

@ -285,59 +285,25 @@ function egw_refresh(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_t
/**
* Display an error or regular message
*
* @param string _msg message to show
* @param string _type 'error', 'warning' or 'success' (default)
* @param {string} _msg message to show
* @param {string} _type 'error', 'warning' or 'success' (default)
* @deprecated use egw(window).message(_msg, _type)
*/
function egw_message(_msg, _type)
{
if (typeof _type == 'undefined')
_type = _msg.match(/error/i) ? 'error' : 'success';
var framework = egw_getFramework();
if (framework && (typeof framework.setMessage != 'undefined'))
{
framework.setMessage.call(window.framework, _msg, _type);
return;
}
// handle message display for non-framework templates, eg. idots or jerryr
if (window.egw_message_timer)
{
window.clearTimeout(window.egw_message_timer);
delete window.egw_message_timer;
}
$j('div#divAppboxHeader div').remove();
$j('div#divAppboxHeader').prepend($j(document.createElement('div')).text(_msg).addClass(_type+'_message').css('position', 'absolute'));
if (_type != 'error') // clear message again after some time, if no error
{
window.egw_message_timer = window.setTimeout(function() {
$j('div#divAppboxHeader').text(document.title.replace(/^.*\[(.*)\]$/, '$1'));
}, 5000);
}
egw(window).message(_msg, _type);
}
/**
* Update app-header and website-title
*
* @param _header
* @param {_app=null} Application name, if not for the current app
*/
* @param {string} _header
* @param {string} _app Application name, if not for the current app
@deprecated use egw(window).app_header(_header, _app)
*/
function egw_app_header(_header,_app)
{
var framework = egw_getFramework();
if (framework && !window.opener) // not for popups
{
var app = _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+']');
egw(window).app_header(_header, _app);
}
/**

View File

@ -910,6 +910,21 @@ td.lettersearch {
font-weight: bold;
background-image: url(../../default/images/dialog_error.png);
}
/**
* Message in popup
*/
body > div#egw_message {
background-color: lightyellow;
border-radius: 10px;
right: 5px;
top: 5px;
padding: 10px;
padding-left: 25px;
background-position-x: 5px;
border: 2px gray solid;
min-width: 100px;
z-index: 10;
}
/**
* Clientside Javascript error-log