Commit 540e5b0b authored by Thomas Lechauve's avatar Thomas Lechauve

Ajax request error handler added to plugin

statusEvent parameter added to request method. It define what's happen
when a non expected response occured from ajax request. Each API methods
can define it's own statusEvent but by default if no statusEvent is
provided then statusDefault is called. statusDefault can be overwritted
in the user interface application.
parent d97cbe76
......@@ -39,71 +39,73 @@
}
}
},
statusDefault: function(){
return {
0: function(){ console.error("status error code: 0"); },
404: function(){ console.error("status error code: Not Found !"); }
}
},
request: function(type, url, callback, data){
request: function(type, url, callback, statusEvent, data){
data = data || '';
statusEvent = statusEvent || this.statusDefault;
return $.ajax({
url: this.store('host')+url,
dataType: 'json',
data: data,
context: this.$elem,
type: type,
statusCode: {
0: function(){ console.log('status code 0') }
}
}).done(callback).fail(this.failCallback);
},
failCallback: function(jqXHR, textStatus){
//console.log(jqXHR);
statusCode: statusEvent
}).done(callback);
},
newInstance: function(data, callback){
return this.request('POST', '/request', callback, data);
newInstance: function(data, callback, statusEvent){
return this.request('POST', '/request', callback, statusEvent, data);
},
deleteInstance: function(id, callback){
this.request('DELETE', '/instance/'+id, callback);
deleteInstance: function(id, callback, statusEvent){
return this.request('DELETE', '/instance/'+id, callback, statusEvent);
},
getInstance: function(id, callback){
this.request('GET', '/instance/'+id, callback);
getInstance: function(id, callback, statusEvent){
return this.request('GET', '/instance/'+id, callback, statusEvent);
},
getInstanceCert: function(id, callback){
this.request('GET', '/instance/'+id+'/certificate', callback);
getInstanceCert: function(id, callback, statusEvent){
return this.request('GET', '/instance/'+id+'/certificate', callback, statusEvent);
},
bangInstance: function(id, log, callback){
this.request('POST', '/instance/'+id+'/bang', callback, log);
bangInstance: function(id, log, callback, statusEvent){
return this.request('POST', '/instance/'+id+'/bang', callback, statusEvent, log);
},
editInstance: function(id, data, callback){
this.request('PUT', '/instance/'+id, callback, data);
editInstance: function(id, data, callback, statusEvent){
return this.request('PUT', '/instance/'+id, callback, statusEvent, data);
},
newComputer: function(data, callback){
this.request('POST', '/computer', callback, data);
newComputer: function(data, callback, statusEvent){
return this.request('POST', '/computer', callback, statusEvent, data);
},
getComputer: function(id, callback){
this.request('GET', '/computer/'+id, callback, data);
getComputer: function(id, callback, statusEvent){
return this.request('GET', '/computer/'+id, callback, statusEvent);
},
editComputer: function(id, data, callback){
this.request('PUT', '/computer/'+id, callback, data);
editComputer: function(id, data, callback, statusEvent){
return this.request('PUT', '/computer/'+id, callback, statusEvent, data);
},
newSoftware: function(computerId, data, callback){
this.request('POST', '/computer/'+computerId+'/supply', callback, data);
newSoftware: function(computerId, data, callback, statusEvent){
return this.request('POST', '/computer/'+computerId+'/supply', callback, statusEvent, data);
},
bangComputer: function(id, log, callback){
this.request('POST', '/computer/'+id+'/bang', callback, log);
bangComputer: function(id, log, callback, statusEvent){
return this.request('POST', '/computer/'+id+'/bang', callback, statusEvent, log);
},
computerReport: function(id, data, callback){
this.request('POST', '/computer/'+id+'/report', callback, data);
computerReport: function(id, data, callback, statusEvent){
return this.request('POST', '/computer/'+id+'/report', callback, statusEvent, data);
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment