2014-02-06 16:42:33 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2014-02-06 18:24:40 +01:00
|
|
|
var error_reg_exp;
|
2014-02-10 17:10:01 +01:00
|
|
|
var on_click_remove_installed = false;
|
2014-02-06 16:42:33 +01:00
|
|
|
|
2014-02-13 19:47:19 +01:00
|
|
|
// Register an 'error' plugin, displaying using the message system
|
|
|
|
this.registerJSONPlugin(function(type, res, req) {
|
|
|
|
if (typeof res.data == 'string')
|
|
|
|
{
|
|
|
|
egw.message(res.data,'error');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw 'Invalid parameters';
|
|
|
|
}, null, 'error');
|
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Display an error or regular message
|
|
|
|
*
|
2014-02-06 18:24:40 +01:00
|
|
|
* @param {string} _msg message to show or empty to remove previous message
|
2014-02-06 16:42:33 +01:00
|
|
|
* @param {string} _type 'error', 'warning' or 'success' (default)
|
|
|
|
*/
|
|
|
|
message: function(_msg, _type)
|
|
|
|
{
|
2014-02-07 10:11:30 +01:00
|
|
|
var framework = _wnd.framework;
|
2014-02-10 17:10:01 +01:00
|
|
|
var jQuery = _wnd.jQuery;
|
2014-02-07 10:11:30 +01:00
|
|
|
|
2014-02-06 18:24:40 +01:00
|
|
|
if (_msg && typeof _type == 'undefined')
|
|
|
|
{
|
|
|
|
if (typeof error_reg_exp == 'undefined') error_reg_exp = new RegExp('(error|'+egw.lang('error')+')', 'i');
|
|
|
|
|
|
|
|
_type = _msg.match(error_reg_exp) ? 'error' : 'success';
|
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
|
|
|
|
// if we are NOT in a popup and have a framwork --> let it deal with it
|
2014-02-10 12:21:58 +01:00
|
|
|
if (!this.is_popup() && typeof framework != 'undefined')
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
|
|
|
// 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();
|
|
|
|
|
2014-02-06 18:24:40 +01:00
|
|
|
if (_msg) // empty _msg just removes pervious message
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
2014-02-10 17:10:01 +01:00
|
|
|
if (!on_click_remove_installed)
|
|
|
|
{
|
|
|
|
// install handler to remove message on click
|
|
|
|
jQuery('body').on('click', 'div#egw_message', function(e) {
|
|
|
|
jQuery('div#egw_message').remove();
|
|
|
|
});
|
|
|
|
on_click_remove_installed = true;
|
|
|
|
}
|
2014-02-06 18:24:40 +01:00
|
|
|
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);
|
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-02-10 12:21:58 +01:00
|
|
|
/**
|
|
|
|
* Are we running in a popup
|
|
|
|
*
|
|
|
|
* @returns {boolean} true: popup, false: main window
|
|
|
|
*/
|
|
|
|
is_popup: function ()
|
|
|
|
{
|
|
|
|
var popup = false;
|
|
|
|
try {
|
|
|
|
if (_wnd.opener && typeof _wnd.opener.top.egw == 'object')
|
|
|
|
{
|
|
|
|
popup = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
// ignore SecurityError exception if opener is different security context / cross-origin
|
|
|
|
}
|
|
|
|
return popup;
|
|
|
|
},
|
|
|
|
|
2014-02-07 10:11:30 +01:00
|
|
|
/**
|
|
|
|
* Active app independent if we are using a framed template-set or not
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
app_name: function()
|
|
|
|
{
|
2014-02-10 12:49:27 +01:00
|
|
|
return !this.is_popup() && _wnd.framework && _wnd.framework.activeApp ? _wnd.framework.activeApp.appName : _wnd.egw_appName;
|
2014-02-07 10:11:30 +01:00
|
|
|
},
|
|
|
|
|
2014-02-06 16:42:33 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2014-02-10 12:49:27 +01:00
|
|
|
// not for popups and only for framed templates
|
|
|
|
if (!this.is_popup() && _wnd.framework && _wnd.framework.setWebsiteTitle)
|
2014-02-06 16:42:33 +01:00
|
|
|
{
|
2014-02-07 10:11:30 +01:00
|
|
|
var app = _app || this.app_name();
|
2014-02-06 16:42:33 +01:00
|
|
|
var title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
|
|
|
|
|
2014-02-07 10:11:30 +01:00
|
|
|
_wnd.framework.setWebsiteTitle.call(_wnd.framework, app, title, _header);
|
2014-02-06 16:42:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 17:10:01 +01:00
|
|
|
_wnd.jQuery('div#divAppboxHeader').text(_header);
|
2014-02-06 16:42:33 +01:00
|
|
|
|
|
|
|
_wnd.document.title = _wnd.document.title.replace(/[.*]$/, '['+_header+']');
|
2014-02-25 10:46:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh given application _targetapp display of entry _app _id, incl. outputting _msg
|
|
|
|
*
|
|
|
|
* Default implementation here only reloads window with it's current url with an added msg=_msg attached
|
|
|
|
*
|
|
|
|
* @param {string} _msg message (already translated) to show, eg. 'Entry deleted'
|
|
|
|
* @param {string} _app application name
|
2014-02-25 17:03:12 +01:00
|
|
|
* @param {(string|number)} _id id of entry to refresh or null
|
|
|
|
* @param {string} _type either 'update', 'edit', 'delete', 'add' or null
|
2014-02-25 10:46:05 +01:00
|
|
|
* - update: request just modified data from given rows. Sorting is not considered,
|
|
|
|
* so if the sort field is changed, the row will not be moved.
|
|
|
|
* - edit: rows changed, but sorting may be affected. Requires full reload.
|
|
|
|
* - delete: just delete the given rows clientside (no server interaction neccessary)
|
|
|
|
* - add: requires full reload for proper sorting
|
|
|
|
* @param {string} _targetapp which app's window should be refreshed, default current
|
|
|
|
* @param {(string|RegExp)} _replace regular expression to replace in url
|
|
|
|
* @param {string} _with
|
|
|
|
* @param {string} _msg_type 'error', 'warning' or 'success' (default)
|
|
|
|
* @todo move code from jsapi to here to deprecate egw_refresh in favor of egw.refresh()
|
|
|
|
*/
|
|
|
|
refresh: function(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type)
|
|
|
|
{
|
|
|
|
_wnd.egw_refresh(_msg, _app, _id, _type, _targetapp, _replace, _with, _msg_type);
|
|
|
|
}
|
2014-02-06 16:42:33 +01:00
|
|
|
};
|
|
|
|
});
|