1 line
1.7 KiB
JavaScript
Executable File
1 line
1.7 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={error:-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("error")&&0!=t.error&&console.error("ModuleError::"+t.error),t.hasOwnProperty("error")&&0==t.error&&(clearTimeout(SESSION_TIMEOUT),SESSION_TIMEOUT=setTimeout(SESSION_TIMEOUT_FUNC,SERVER.session.timeout)),r(t,n.optionalParams[s])}else r({error:-2,ErrorDescription:"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)}}; |