hedera-web/js/hedera/module.js

97 lines
1.7 KiB
JavaScript
Raw Normal View History

Vn.Module = new Class
({
basePath: null
,path: null
,moduleName: null
,callbacks: []
,localeReady: false
,jsReady: false
,uiReady: false
,error: false
,ready: false
,initialize: function (basePath, path)
{
var absPath = basePath +'/'+ path;
var aux = path.split ('/');
var moduleName = aux[aux.length - 1];
Vn.Locale.load (absPath,
this.onLocaleReady.bind (this));
Vn.includeJs (absPath +'/'+ moduleName +'.js',
this.onJsReady.bind (this));
Vn.loadXml (absPath +'/ui.xml',
this.onUiReady.bind (this));
this.basePath = basePath;
this.path = path;
this.moduleName = moduleName;
}
,addCallback: function (callback)
{
if (!this.ready)
this.callbacks.push (callback);
else
callback (this);
}
,onLocaleReady: function (success)
{
this.localeReady = true;
this.onReady ();
}
,onJsReady: function (success)
{
this.jsReady = true;
this.error = !success;
this.onReady ();
}
,onUiReady: function (success)
{
this.uiReady = true;
this.error = !success;
this.onReady ();
}
,onReady: function ()
{
if (!(this.localeReady && this.jsReady && this.uiReady))
return;
2015-11-09 08:14:33 +00:00
this.ready = true;
var klassName = this.toCamelCase (this.moduleName);
try {
2016-08-22 10:41:05 +00:00
this.klass = Vn[klassName];
}
catch (e)
{
this.error = true;
console.error (e);
}
var callbacks = this.callbacks;
this.callbacks = null;
for (var i = 0; i < callbacks.length; i++)
callbacks[i] (this);
}
,toCamelCase: function (dashedName)
{
2016-08-22 10:41:05 +00:00
var camelCase = dashedName.charAt (0).toUpperCase ();
camelCase += dashedName.substr (1).replace (/\w\-\w/g, function (token)
{
return token.charAt (0) + token.charAt (2).toUpperCase ();
});
return camelCase;
}
});