NxTIC/public_html/js/lib/min/api.js

5 lines
1.2 KiB
JavaScript
Executable File

function APIClass(b){this.target=b}
APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(b,f,g){b.hasOwnProperty("path")||f({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&this.xhr.splice(a,1);this.xhr.push(null);a=this.xhr.length-1;this.optionalParams[a]=[];if(3<arguments.length)for(var d=3;d<arguments.length;d++)this.optionalParams[a].push(arguments[d]);this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");var e=this;console.log("api request",
b);this.xhr[a].onreadystatechange=function(){if(4==e.xhr[a].readyState)if(e.buffer=e.xhr[a].responseText,console.log("api response",JSON.parse(e.xhr[a].responseText)),-1<[0,200].indexOf(e.xhr[a].status))try{f(JSON.parse(e.xhr[a].responseText),e.optionalParams[a])}catch(b){f({ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"},e.optionalParams[a]),console.warn(b)}else f({ModuleError:3})};var d=new FormData,c;for(c in b)"path"==c?d.append(c,b[c]):b[c]instanceof File?d.append(c,b[c]):d.append(c,
JSON.stringify(b[c]));this.xhr[a].open("POST",this.target,!0);g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].setRequestHeader("X-Requested-With","XMLHttpRequest");this.xhr[a].send(d)}};