log system in js
This commit is contained in:
parent
058d4d3b90
commit
2d0dd2ea8c
@ -3,6 +3,11 @@ var system = null;
|
|||||||
//mother object
|
//mother object
|
||||||
function SYSTEM(endpoint, group,start_state){
|
function SYSTEM(endpoint, group,start_state){
|
||||||
system = this;
|
system = this;
|
||||||
|
|
||||||
|
this.LOG_START = 0;
|
||||||
|
this.LOG_INFO = 1;
|
||||||
|
this.LOG_ERROR = 2;
|
||||||
|
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.pages = null;
|
this.pages = null;
|
||||||
@ -13,10 +18,10 @@ function SYSTEM(endpoint, group,start_state){
|
|||||||
SYSTEM.prototype.handle_call_pages = function (data) {
|
SYSTEM.prototype.handle_call_pages = function (data) {
|
||||||
if(data['status']){
|
if(data['status']){
|
||||||
newps = data['result'];
|
newps = data['result'];
|
||||||
console.log('SYSTEM: load pages: '+system.endpoint+':'+system.group+' - success');
|
system.log(system.LOG_INFO,'load pages: '+system.endpoint+':'+system.group+' - success');
|
||||||
result = true;
|
result = true;
|
||||||
} else {
|
} else {
|
||||||
console.log('SYSTEM-ERROR: Problem with your Pages: '+data['result']['message']);
|
system.log(system.LOG_INFO,'Problem with your Pages: '+data['result']['message']);
|
||||||
result = false;}
|
result = false;}
|
||||||
};
|
};
|
||||||
//send a call to the endpoint
|
//send a call to the endpoint
|
||||||
@ -27,9 +32,24 @@ SYSTEM.prototype.call = function(call,success,data,data_type,async){
|
|||||||
dataType: data_type,
|
dataType: data_type,
|
||||||
url: this.endpoint+'?'+call,
|
url: this.endpoint+'?'+call,
|
||||||
success: success,
|
success: success,
|
||||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(call);}
|
error: function(XMLHttpRequest, textStatus, errorThrown){system.log(system.LOG_ERROR,call);}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
SYSTEM.prototype.log = function(type,msg){
|
||||||
|
var res = '';
|
||||||
|
switch(type){
|
||||||
|
case system.LOG_START:
|
||||||
|
res = '#SYSTEM: ';
|
||||||
|
break;
|
||||||
|
case system.LOG_INFO:
|
||||||
|
res = '-SYSTEM: ';
|
||||||
|
break;
|
||||||
|
case system.LOG_ERROR:
|
||||||
|
res = '!SYSTEM-ERROR: ';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(res+msg);
|
||||||
|
};
|
||||||
//get the pages and save em
|
//get the pages and save em
|
||||||
SYSTEM.prototype.load_page = function(){
|
SYSTEM.prototype.load_page = function(){
|
||||||
result = false;
|
result = false;
|
||||||
@ -42,8 +62,9 @@ SYSTEM.prototype.load_page = function(){
|
|||||||
};
|
};
|
||||||
//load a pagestatewith given id
|
//load a pagestatewith given id
|
||||||
SYSTEM.prototype.load = function(id){
|
SYSTEM.prototype.load = function(id){
|
||||||
|
system.log(system.LOG_START,'load page '+id);
|
||||||
if(!system.load_page()){
|
if(!system.load_page()){
|
||||||
console.log('SYSTEM-ERROR: Problem with your Pages');
|
system.log(system.LOG_ERROR,'Problem with your Pages');
|
||||||
return false;}
|
return false;}
|
||||||
var push = true;
|
var push = true;
|
||||||
var found = false;
|
var found = false;
|
||||||
@ -62,21 +83,23 @@ SYSTEM.prototype.load = function(id){
|
|||||||
url: entry['url'],
|
url: entry['url'],
|
||||||
success: function(data){
|
success: function(data){
|
||||||
$(entry['div']).html(data);
|
$(entry['div']).html(data);
|
||||||
console.log('SYSTEM: load page: '+id+entry['div']+' - success');},
|
system.log(system.LOG_INFO,'load page: '+id+entry['div']+' - success');},
|
||||||
error: function(XMLHttpRequest, textStatus, errorThrown){console.log(errorThrown);}
|
error: function(XMLHttpRequest, textStatus, errorThrown){system.log(system.LOG_ERROR,errorThrown);}
|
||||||
});
|
});
|
||||||
//load css
|
//load css
|
||||||
for(var i=0; i < entry['css'].length; i++){
|
for(var i=0; i < entry['css'].length; i++){
|
||||||
system.load_css(entry['css'][i]);}
|
system.load_css(entry['css'][i]);}
|
||||||
//load js
|
//load js
|
||||||
|
var call_func = true;
|
||||||
for(var i=0; i < entry['js'].length; i++){
|
for(var i=0; i < entry['js'].length; i++){
|
||||||
console.log('SYSTEM: load js: '+entry['js'][i]);
|
system.log(system.LOG_INFO,'load js: '+entry['js'][i]);
|
||||||
$.getScript(entry['js'][i]).done(function(response, status) {
|
$.getScript(entry['js'][i]).done(function(response, status) {
|
||||||
console.log('SYSTEM: load js: '+status);
|
system.log(system.LOG_INFO,'load js: '+status);
|
||||||
var fn = window[entry['func']];
|
var fn = window[entry['func']];
|
||||||
if(typeof fn === 'function'){
|
if(call_func && typeof fn === 'function'){
|
||||||
|
call_func = false;
|
||||||
fn();
|
fn();
|
||||||
console.log('SYSTEM: call func: '+entry['func']);}});
|
system.log(system.LOG_INFO,'call func: '+entry['func']);}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -92,7 +115,7 @@ SYSTEM.prototype.load_css = function loadCSS(csssrc) {
|
|||||||
snode.setAttribute('rel', 'stylesheet');
|
snode.setAttribute('rel', 'stylesheet');
|
||||||
snode.setAttribute('href',csssrc);
|
snode.setAttribute('href',csssrc);
|
||||||
document.getElementsByTagName('head')[0].appendChild(snode);
|
document.getElementsByTagName('head')[0].appendChild(snode);
|
||||||
console.log('SYSTEM: load css '+csssrc);
|
system.log(system.LOG_INFO,'load css '+csssrc);
|
||||||
};
|
};
|
||||||
|
|
||||||
//what?
|
//what?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user