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
...@@ -40,70 +40,72 @@ ...@@ -40,70 +40,72 @@
} }
}, },
request: function(type, url, callback, data){ 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, statusEvent, data){
data = data || ''; data = data || '';
statusEvent = statusEvent || this.statusDefault;
return $.ajax({ return $.ajax({
url: this.store('host')+url, url: this.store('host')+url,
dataType: 'json', dataType: 'json',
data: data, data: data,
context: this.$elem, context: this.$elem,
type: type, type: type,
statusCode: { statusCode: statusEvent
0: function(){ console.log('status code 0') } }).done(callback);
}
}).done(callback).fail(this.failCallback);
},
failCallback: function(jqXHR, textStatus){
//console.log(jqXHR);
}, },
newInstance: function(data, callback){ newInstance: function(data, callback, statusEvent){
return this.request('POST', '/request', callback, data); return this.request('POST', '/request', callback, statusEvent, data);
}, },
deleteInstance: function(id, callback){ deleteInstance: function(id, callback, statusEvent){
this.request('DELETE', '/instance/'+id, callback); return this.request('DELETE', '/instance/'+id, callback, statusEvent);
}, },
getInstance: function(id, callback){ getInstance: function(id, callback, statusEvent){
this.request('GET', '/instance/'+id, callback); return this.request('GET', '/instance/'+id, callback, statusEvent);
}, },
getInstanceCert: function(id, callback){ getInstanceCert: function(id, callback, statusEvent){
this.request('GET', '/instance/'+id+'/certificate', callback); return this.request('GET', '/instance/'+id+'/certificate', callback, statusEvent);
}, },
bangInstance: function(id, log, callback){ bangInstance: function(id, log, callback, statusEvent){
this.request('POST', '/instance/'+id+'/bang', callback, log); return this.request('POST', '/instance/'+id+'/bang', callback, statusEvent, log);
}, },
editInstance: function(id, data, callback){ editInstance: function(id, data, callback, statusEvent){
this.request('PUT', '/instance/'+id, callback, data); return this.request('PUT', '/instance/'+id, callback, statusEvent, data);
}, },
newComputer: function(data, callback){ newComputer: function(data, callback, statusEvent){
this.request('POST', '/computer', callback, data); return this.request('POST', '/computer', callback, statusEvent, data);
}, },
getComputer: function(id, callback){ getComputer: function(id, callback, statusEvent){
this.request('GET', '/computer/'+id, callback, data); return this.request('GET', '/computer/'+id, callback, statusEvent);
}, },
editComputer: function(id, data, callback){ editComputer: function(id, data, callback, statusEvent){
this.request('PUT', '/computer/'+id, callback, data); return this.request('PUT', '/computer/'+id, callback, statusEvent, data);
}, },
newSoftware: function(computerId, data, callback){ newSoftware: function(computerId, data, callback, statusEvent){
this.request('POST', '/computer/'+computerId+'/supply', callback, data); return this.request('POST', '/computer/'+computerId+'/supply', callback, statusEvent, data);
}, },
bangComputer: function(id, log, callback){ bangComputer: function(id, log, callback, statusEvent){
this.request('POST', '/computer/'+id+'/bang', callback, log); return this.request('POST', '/computer/'+id+'/bang', callback, statusEvent, log);
}, },
computerReport: function(id, data, callback){ computerReport: function(id, data, callback, statusEvent){
this.request('POST', '/computer/'+id+'/report', callback, data); 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