1 line
1.6 KiB
JavaScript
Executable File
1 line
1.6 KiB
JavaScript
Executable File
function APIClass(e){this.target=e}APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(e,r,t){e.hasOwnProperty("path")||r({ModuleError:4});for(var s=0;s<this.xhr.length;s++)4==this.xhr[s].readyState&&this.xhr.splice(s,1);if(this.xhr.push(null),s=this.xhr.length-1,this.optionalParams[s]=[],arguments.length>3)for(var o=3;o<arguments.length;o++)this.optionalParams[s].push(arguments[o]);window.XMLHttpRequest?this.xhr[s]=new XMLHttpRequest:this.xhr[s]=new ActiveXObject("Microsoft.XMLHttpRequest");var n=this;this.xhr[s].onreadystatechange=function(){if(4==n.xhr[s].readyState)if(n.buffer=n.xhr[s].responseText,console.log("api request",e),[0,200,417].indexOf(n.xhr[s].status)>-1){window._tree_token_=n.xhr[s].getResponseHeader("X-Tree-Token");var t={ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"};try{t=JSON.parse(n.xhr[s].responseText)}catch(e){}console.log("api response",t),t.hasOwnProperty("ModuleError")&&0!=t.ModuleError&&console.error("ModuleError::"+t.ModuleError),r(t,n.optionalParams[s])}else r({ModuleError:-2,ModuleDescription:"Erreur au niveau d'AJAX."})};var a=new FormData;for(var i in e)"path"==i?a.append(i,e[i]):e[i]instanceof File?a.append(i,e[i]):a.append(i,JSON.stringify(e[i]));this.xhr[s].open("POST",this.target,!0),null!=t&&this.xhr[s].setRequestHeader("Authorization","Digest "+t),null==window._tree_token_?this.xhr[s].setRequestHeader("X-Tree-Token",JSON.parse('{"'+document.cookie.replace(/=/g,'":"').replace(/; /g,'","')+'"}')._PUBLIC_):this.xhr[s].setRequestHeader("X-Tree-Token",window._tree_token_),this.xhr[s].setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr[s].send(a)}}; |