SMMP/public_html/js/lib/min/api.js

5 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2016-07-02 15:10:41 +00:00
function APIClass(c){this.target=c}
APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(c,f,g){c.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;this.xhr[a].onreadystatechange=
function(){if(4==e.xhr[a].readyState)if(e.buffer=e.xhr[a].responseText,console.log("api request",c),-1<[0,200,417].indexOf(e.xhr[a].status)){var b={ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"};try{b=JSON.parse(e.xhr[a].responseText)}catch(d){}console.log("api response",b);b.hasOwnProperty("ModuleError")&&0!=b.ModuleError&&console.error("ModuleError::"+b.ModuleError);f(b,e.optionalParams[a])}else f({ModuleError:-2,ModuleDescription:"Erreur au niveau d'AJAX."})};var d=new FormData,
b;for(b in c)"path"==b?d.append(b,c[b]):c[b]instanceof File?d.append(b,c[b]):d.append(b,JSON.stringify(c[b]));this.xhr[a].open("POST",this.target,!0);null!=g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].setRequestHeader("X-Requested-With","XMLHttpRequest");this.xhr[a].send(d)}};