2015-09-11 09:37:16 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-09-11 09:37:16 +00:00
|
|
|
({
|
2015-11-17 10:34:33 +00:00
|
|
|
basePath: null
|
|
|
|
,path: null
|
|
|
|
,moduleName: null
|
|
|
|
,callbacks: []
|
|
|
|
,localeReady: false
|
|
|
|
,jsReady: false
|
|
|
|
,uiReady: false
|
|
|
|
,error: false
|
|
|
|
,ready: false
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,initialize: function (basePath, path)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2015-11-17 10:34:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-03-23 16:20:51 +00:00
|
|
|
|
|
|
|
,getCssPath: function ()
|
|
|
|
{
|
|
|
|
return this.basePath +'/'+ this.path +'/style.css';
|
|
|
|
}
|
|
|
|
|
|
|
|
,includeCss: function ()
|
|
|
|
{
|
|
|
|
Vn.includeCss (this.getCssPath ());
|
|
|
|
}
|
|
|
|
|
|
|
|
,unload: function ()
|
|
|
|
{
|
|
|
|
Vn.excludeCss (this.getCssPath ());
|
|
|
|
}
|
2015-11-17 10:34:33 +00:00
|
|
|
|
2017-03-23 16:20:51 +00:00
|
|
|
,load: function (callback)
|
2015-11-17 10:34:33 +00:00
|
|
|
{
|
2017-03-23 16:20:51 +00:00
|
|
|
if (this.ready)
|
|
|
|
{
|
|
|
|
this.includeCss ();
|
2015-11-17 10:34:33 +00:00
|
|
|
callback (this);
|
2017-03-23 16:20:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
this.callbacks.push (callback);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,onLocaleReady: function (success)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2015-11-17 10:34:33 +00:00
|
|
|
this.localeReady = true;
|
|
|
|
this.onReady ();
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,onJsReady: function (success)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2015-11-17 10:34:33 +00:00
|
|
|
this.jsReady = true;
|
|
|
|
this.error = !success;
|
|
|
|
this.onReady ();
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,onUiReady: function (success)
|
|
|
|
{
|
|
|
|
this.uiReady = true;
|
|
|
|
this.error = !success;
|
|
|
|
this.onReady ();
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,onReady: function ()
|
|
|
|
{
|
|
|
|
if (!(this.localeReady && this.jsReady && this.uiReady))
|
|
|
|
return;
|
2015-11-09 08:14:33 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
this.ready = true;
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
var klassName = this.toCamelCase (this.moduleName);
|
|
|
|
|
|
|
|
try {
|
2016-09-26 09:28:47 +00:00
|
|
|
this.klass = Hedera[klassName];
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
this.error = true;
|
|
|
|
console.error (e);
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
var callbacks = this.callbacks;
|
|
|
|
this.callbacks = null;
|
2017-03-23 16:20:51 +00:00
|
|
|
this.includeCss ();
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
for (var i = 0; i < callbacks.length; i++)
|
|
|
|
callbacks[i] (this);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
,toCamelCase: function (dashedName)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2016-08-22 10:41:05 +00:00
|
|
|
var camelCase = dashedName.charAt (0).toUpperCase ();
|
2015-11-17 10:34:33 +00:00
|
|
|
camelCase += dashedName.substr (1).replace (/\w\-\w/g, function (token)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2015-11-17 10:34:33 +00:00
|
|
|
return token.charAt (0) + token.charAt (2).toUpperCase ();
|
|
|
|
});
|
|
|
|
return camelCase;
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|