fixed translations not loaded on very first request, as postponing ready for waiting on translations did not work, now using a direct callback instead

This commit is contained in:
Ralf Becker 2013-10-08 08:55:15 +00:00
parent 1a4a4fdded
commit bafcc80e35
4 changed files with 139 additions and 107 deletions

View File

@ -193,11 +193,9 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
var currentapp = _data.currentapp || window.egw_appName; var currentapp = _data.currentapp || window.egw_appName;
// require necessary translations from server, if not already loaded // require necessary translations from server, if not already loaded
if ($j.isArray(_data.langRequire)) if (!$j.isArray(_data.langRequire)) _data.langRequire = [];
egw(currentapp, window).langRequire(window, _data.langRequire, function()
{ {
egw(currentapp, window).langRequire(window, _data.langRequire);
}
// Appname should be first part of the template name // Appname should be first part of the template name
var split = _name.split('.'); var split = _name.split('.');
var appname = split[0]; var appname = split[0];
@ -299,8 +297,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Already have it // Already have it
_load.apply(this,[]); _load.apply(this,[]);
} }
}, this);
}; };
/** /**

View File

@ -18,8 +18,11 @@
egw_debug; egw_debug;
*/ */
egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd) { /**
* @augments Class
*/
egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd)
{
var egw = this; var egw = this;
/** /**
@ -44,6 +47,15 @@ egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
} }
return { return {
/**
* Load and execute javascript file(s) in order
*
* @memberOf egw
* @param string|array _jsFiles (array of) urls to include
* @param function _callback called after JS files are loaded and executed
* @param object _context
* @param string _prefix prefix for _jsFiles
*/
includeJS: function(_jsFiles, _callback, _context, _prefix) { includeJS: function(_jsFiles, _callback, _context, _prefix) {
if (typeof _prefix === 'undefined') if (typeof _prefix === 'undefined')
{ {
@ -72,6 +84,11 @@ egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
}); });
}, },
/**
* Include a CSS file
*
* @param _cssFile full url of file to include
*/
includeCSS: function(_cssFile) { includeCSS: function(_cssFile) {
//Check whether the requested file has already been included //Check whether the requested file has already been included
var file = removeTS(_cssFile); var file = removeTS(_cssFile);

View File

@ -101,8 +101,10 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
* app: <APPLICATION NAME>, * app: <APPLICATION NAME>,
* lang: <LANGUAGE CODE> * lang: <LANGUAGE CODE>
* } * }
* @param function _callback called after loading, if not given ready event will be postponed instead
* @param object _context for callback
*/ */
langRequire: function(_window, _apps) { langRequire: function(_window, _apps, _callback, _context) {
// Get the ready and the files module for the given window // Get the ready and the files module for the given window
var ready = this.module("ready", _window); var ready = this.module("ready", _window);
var files = this.module("files", this.window); var files = this.module("files", this.window);
@ -127,6 +129,12 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
// Only continue if we need to include a language // Only continue if we need to include a language
if (jss.length > 0) if (jss.length > 0)
{
if (typeof _callback == 'function')
{
files.includeJS(jss, _callback, _context || null);
}
else
{ {
// Require a "ready postpone token" // Require a "ready postpone token"
var token = ready.readyWaitFor(); var token = ready.readyWaitFor();
@ -137,6 +145,11 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
}, this); }, this);
} }
} }
else if (typeof _callback == 'function')
{
_callback.call(_context || null);
}
}
}; };
}); });

View File

@ -17,6 +17,9 @@
egw_debug; egw_debug;
*/ */
/**
* @augments Class
*/
egw.extend('ready', egw.MODULE_WND_LOCAL, function(_app, _wnd) { egw.extend('ready', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
var egw = this; var egw = this;
@ -136,6 +139,8 @@ egw.extend('ready', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
* to be marked as "done" before the ready function will call its * to be marked as "done" before the ready function will call its
* registered callbacks. The function returns an id that has to be * registered callbacks. The function returns an id that has to be
* passed to the "readDone" function once * passed to the "readDone" function once
*
* @memberOf egw
*/ */
readyWaitFor: function() { readyWaitFor: function() {
return doReadyWaitFor(); return doReadyWaitFor();