2015-09-11 09:37:16 +00:00
|
|
|
|
2022-06-06 16:19:43 +00:00
|
|
|
module.exports = new Class({
|
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
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,initialize(basePath, path) {
|
2015-11-17 10:34:33 +00:00
|
|
|
var absPath = basePath +'/'+ path;
|
|
|
|
|
2022-06-06 16:19:43 +00:00
|
|
|
var aux = path.split('/');
|
2015-11-17 10:34:33 +00:00
|
|
|
var moduleName = aux[aux.length - 1];
|
|
|
|
|
2022-06-06 16:19:43 +00:00
|
|
|
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));
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
this.basePath = basePath;
|
|
|
|
this.path = path;
|
|
|
|
this.moduleName = moduleName;
|
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,addCallback(callback) {
|
2015-11-17 10:34:33 +00:00
|
|
|
if (!this.ready)
|
2022-06-06 16:19:43 +00:00
|
|
|
this.callbacks.push(callback);
|
2015-11-17 10:34:33 +00:00
|
|
|
else
|
2022-06-06 16:19:43 +00:00
|
|
|
callback(this);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onLocaleReady() {
|
2015-11-17 10:34:33 +00:00
|
|
|
this.localeReady = true;
|
2022-06-06 16:19:43 +00:00
|
|
|
this.onReady();
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onJsReady(success) {
|
2015-11-17 10:34:33 +00:00
|
|
|
this.jsReady = true;
|
|
|
|
this.error = !success;
|
2022-06-06 16:19:43 +00:00
|
|
|
this.onReady();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onUiReady(success) {
|
2015-11-17 10:34:33 +00:00
|
|
|
this.uiReady = true;
|
|
|
|
this.error = !success;
|
2022-06-06 16:19:43 +00:00
|
|
|
this.onReady();
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,onReady() {
|
2015-11-17 10:34:33 +00:00
|
|
|
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
|
|
|
|
2022-06-06 16:19:43 +00:00
|
|
|
var klassName = this.toCamelCase(this.moduleName);
|
2015-11-17 10:34:33 +00:00
|
|
|
|
|
|
|
try {
|
2016-09-26 09:28:47 +00:00
|
|
|
this.klass = Hedera[klassName];
|
2022-06-06 16:19:43 +00:00
|
|
|
} catch (e) {
|
2015-11-17 10:34:33 +00:00
|
|
|
this.error = true;
|
2022-06-06 16:19:43 +00:00
|
|
|
console.error(e);
|
2015-11-17 10:34:33 +00:00
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
var callbacks = this.callbacks;
|
|
|
|
this.callbacks = null;
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-11-17 10:34:33 +00:00
|
|
|
for (var i = 0; i < callbacks.length; i++)
|
2022-06-06 16:19:43 +00:00
|
|
|
callbacks[i](this);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,toCamelCase(dashedName) {
|
2022-06-06 16:19:43 +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();
|
2015-11-17 10:34:33 +00:00
|
|
|
});
|
|
|
|
return camelCase;
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|