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,114 +193,111 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
var currentapp = _data.currentapp || window.egw_appName;
// 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
var split = _name.split('.');
var appname = split[0];
// Initialize application js
var app_callback = null;
// Only initialize once
if(typeof app[appname] == "function")
{
(function() { new app[appname]();}).call();
}
else if (typeof app[appname] !== "object")
{
egw.debug("warn", "Did not load '%s' JS object",appname);
}
if(typeof app[appname] == "object")
{
app_callback = function(et2) {app[appname].et2_ready(et2);};
}
// Appname should be first part of the template name
var split = _name.split('.');
var appname = split[0];
// Create the document fragment into which the HTML will be injected
var frag = document.createDocumentFragment();
// Clear any existing instance
this.clear();
// Create the basic widget container and attach it to the DOM
this.widgetContainer = new et2_container(null);
this.widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this.DOMContainer)));
this.widgetContainer.setInstanceManager(this);
this.widgetContainer.setParentDOMNode(this.DOMContainer);
// store the id to submit it back to server
if(_data) {
this.etemplate_exec_id = _data.etemplate_exec_id;
// set app_header
window.egw_app_header(_data.app_header);
}
var _load = function() {
// Read the XML structure of the requested template
this.widgetContainer.loadFromXML(this.templates[_name || missing_name]);
// Inform the widget tree that it has been successfully loaded.
this.widgetContainer.loadingFinished();
// Insert the document fragment to the DOM Container
this.DOMContainer.appendChild(frag);
// Add into indexed list
if(typeof etemplate2._byTemplate[_name] == "undefined")
// Initialize application js
var app_callback = null;
// Only initialize once
if(typeof app[appname] == "function")
{
etemplate2._byTemplate[_name] = [];
(function() { new app[appname]();}).call();
}
etemplate2._byTemplate[_name].push(this);
// Trigger the "resize" event
this.resize();
if(typeof _callback == "function")
else if (typeof app[appname] !== "object")
{
_callback.call(window,this);
egw.debug("warn", "Did not load '%s' JS object",appname);
}
if(_callback != app_callback)
if(typeof app[appname] == "object")
{
app_callback.call(window,this);
app_callback = function(et2) {app[appname].et2_ready(et2);};
}
$j(this.DOMContainer).trigger('load', this);
};
// Create the document fragment into which the HTML will be injected
var frag = document.createDocumentFragment();
// Load & process
if(!this.templates[_name])
{
// Asynchronously load the XET file
et2_loadXMLFromURL(_url, function(_xmldoc) {
// Scan for templates and store them
for(var i = 0; i < _xmldoc.childNodes.length; i++) {
var template = _xmldoc.childNodes[i];
if(template.nodeName.toLowerCase() != "template") continue;
this.templates[template.getAttribute("id")] = template;
if(!_name) missing_name = template.getAttribute("id");
// Clear any existing instance
this.clear();
// Create the basic widget container and attach it to the DOM
this.widgetContainer = new et2_container(null);
this.widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this.DOMContainer)));
this.widgetContainer.setInstanceManager(this);
this.widgetContainer.setParentDOMNode(this.DOMContainer);
// store the id to submit it back to server
if(_data) {
this.etemplate_exec_id = _data.etemplate_exec_id;
// set app_header
window.egw_app_header(_data.app_header);
}
var _load = function() {
// Read the XML structure of the requested template
this.widgetContainer.loadFromXML(this.templates[_name || missing_name]);
// Inform the widget tree that it has been successfully loaded.
this.widgetContainer.loadingFinished();
// Insert the document fragment to the DOM Container
this.DOMContainer.appendChild(frag);
// Add into indexed list
if(typeof etemplate2._byTemplate[_name] == "undefined")
{
etemplate2._byTemplate[_name] = [];
}
_load.apply(this,[]);
}, this);
// Split the given data into array manager objects and pass those to the
// widget container - do this here because file is loaded async
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
}
else
{
// Set array managers first, or errors will happen
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
// Already have it
_load.apply(this,[]);
}
etemplate2._byTemplate[_name].push(this);
// Trigger the "resize" event
this.resize();
if(typeof _callback == "function")
{
_callback.call(window,this);
}
if(_callback != app_callback)
{
app_callback.call(window,this);
}
$j(this.DOMContainer).trigger('load', this);
};
// Load & process
if(!this.templates[_name])
{
// Asynchronously load the XET file
et2_loadXMLFromURL(_url, function(_xmldoc) {
// Scan for templates and store them
for(var i = 0; i < _xmldoc.childNodes.length; i++) {
var template = _xmldoc.childNodes[i];
if(template.nodeName.toLowerCase() != "template") continue;
this.templates[template.getAttribute("id")] = template;
if(!_name) missing_name = template.getAttribute("id");
}
_load.apply(this,[]);
}, this);
// Split the given data into array manager objects and pass those to the
// widget container - do this here because file is loaded async
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
}
else
{
// Set array managers first, or errors will happen
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
// Already have it
_load.apply(this,[]);
}
}, this);
};
/**

View File

@ -18,8 +18,11 @@
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;
/**
@ -44,6 +47,15 @@ egw.extend('files', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
}
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) {
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) {
//Check whether the requested file has already been included
var file = removeTS(_cssFile);

View File

@ -101,8 +101,10 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
* app: <APPLICATION NAME>,
* 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
var ready = this.module("ready", _window);
var files = this.module("files", this.window);
@ -128,13 +130,24 @@ egw.extend('lang', egw.MODULE_GLOBAL, function() {
// Only continue if we need to include a language
if (jss.length > 0)
{
// Require a "ready postpone token"
var token = ready.readyWaitFor();
// Call "readyDone" once all js files have been included.
files.includeJS(jss, function () {
ready.readyDone(token);
}, this);
if (typeof _callback == 'function')
{
files.includeJS(jss, _callback, _context || null);
}
else
{
// Require a "ready postpone token"
var token = ready.readyWaitFor();
// Call "readyDone" once all js files have been included.
files.includeJS(jss, function () {
ready.readyDone(token);
}, this);
}
}
else if (typeof _callback == 'function')
{
_callback.call(_context || null);
}
}
};

View File

@ -17,6 +17,9 @@
egw_debug;
*/
/**
* @augments Class
*/
egw.extend('ready', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
var egw = this;
@ -135,7 +138,9 @@ egw.extend('ready', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
* The readyWaitFor function can be used to register an event, that has
* to be marked as "done" before the ready function will call its
* 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() {
return doReadyWaitFor();