Your IP : 3.135.220.255


Current Path : /home/bitrix/initial_sites/coffe.land_1/bitrix/js/rest/client/
Upload File :
Current File : /home/bitrix/initial_sites/coffe.land_1/bitrix/js/rest/client/rest.client.min.js

"use strict";(function(){if(!window.BX){window.BX={}}else if(window.BX.RestClient){return}var e=window.BX;e.RestClient=function(e){e=e||{};this.endpoint=e.endpoint||"/rest";this.queryParams=e.queryParams||"";this.cors=e.cors===true};e.RestClient.prototype.callMethod=function(e,t,r,i,s){return n({method:e,data:t,callback:r,sendCallback:i,logTag:s,endpoint:this.endpoint,queryParams:this.queryParams,cors:this.cors})};e.RestClient.prototype.callBatch=function(e,t,i,s,o){var a=r.isArray(e)?[]:{};var u=0;var f=function(e){n.batch(e,t,i,s,this.endpoint,this.queryParams,this.cors,o)}.bind(this);for(var l in e){var c=null,p=null;if(!!e[l]&&e.hasOwnProperty(l)){if(r.isArray(e[l])){c=e[l][0];p=e[l][1]}else if(!!e[l].method){c=e[l].method;p=e[l].params}if(!!c){u++;a[l]=[c,p]}}}if(u>0){var d=function(e){return function(t){a[e]=a[e][0]+"?"+t;if(--u<=0)f(a)}};for(var h in a){if(a.hasOwnProperty(h)){n.prepareData(a[h][1],"",d(h))}}}};e.RestClient.prototype.setEndpoint=function(e){this.endpoint=e};e.RestClient.prototype.enableCorsRequest=function(e){this.cors=e===true};e.RestClient.prototype.setQueryParams=function(e){this.queryParams=e};if(typeof e.namespace!=="undefined"){var t=new e.RestClient;if(typeof e.rest=="undefined"){e.rest={}}e.rest.callMethod=function(e,r,n,i,s){return t.callMethod(e,r,n,i,s)};e.rest.callBatch=function(e,r,n,i,s){return t.callBatch(e,r,n,i,s)}}var r={isArray:function(e){return e&&Object.prototype.toString.call(e)=="[object Array]"},isFunction:function(e){return e===null?false:typeof e=="function"||e instanceof Function},isString:function(e){return e===""?true:e?typeof e=="string"||e instanceof String:false},isDomNode:function(e){return e&&typeof e=="object"&&"nodeType"in e},isDate:function(e){return e&&Object.prototype.toString.call(e)=="[object Date]"},buildQueryString:function(e){var t="";for(var r in e){if(!e.hasOwnProperty(r)){continue}var n=e[r];if(this.isArray(n)){n.forEach(function(e,n){t+=encodeURIComponent(r+"["+n+"]")+"="+encodeURIComponent(e)+"&"})}else{t+=encodeURIComponent(r)+"="+encodeURIComponent(n)+"&"}}if(t.length>0){t=t.substr(0,t.length-1)}return t},clone:function(e,t){var r,n,i;if(t!==false)t=true;if(e===null)return null;if(this.isDomNode(e)){r=e.cloneNode(t)}else if(typeof e=="object"){if(this.isArray(e)){r=[];for(n=0,i=e.length;n<i;n++){if(typeof e[n]=="object"&&t)r[n]=this.clone(e[n],t);else r[n]=e[n]}}else{r={};if(e.constructor){if(this.isDate(e))r=new Date(e);else r=new e.constructor}for(n in e){if(typeof e[n]=="object"&&t)r[n]=this.clone(e[n],t);else r[n]=e[n]}}}else{r=e}return r}};var n=function(t){var s=!!t.callback&&r.isFunction(t.callback);var o=typeof e.Promise==="undefined"||s?null:new e.Promise;var a=t.sendCallback||function(){};var u=t.withoutRestoringCsrf||false;var f=n.xhr();var l=t.endpoint+"/"+n.escape(t.method)+".json"+(t.logTag?"?logTag="+t.logTag:"");f.open("POST",l);f.setRequestHeader("Content-Type","application/x-www-form-urlencoded");if(t.cors){f.withCredentials=true}var c=false;f.onprogress=function(){};f.ontimeout=function(){};f.timeout=0;f.onload=function(){if(c)return;f.onload=function(){};var r=n.isSuccess(f);var a=f.status;if(r){var l=f.responseText;if(l.length>0){try{l=JSON.parse(l)}catch(e){r=false}}if(a==401){if(l.sessid&&!u){e.message({bitrix_sessid:l.sessid});console.warn("BX.rest: your csrf-token has expired, send query with a new token");t.withoutRestoringCsrf=true;if(!s){t.callback=function(e){if(e.error()){o.reject(e)}else{o.fulfill(e)}}}n(t);return true}}else if(a==0){l={result:{},error:"ERROR_NETWORK",error_description:"A network error occurred while the request was being executed."}}else{if(a==200){if(l.length<=0){l={result:{}}}}else if(l.length<=0){l={result:{},error:"BLANK_ANSWER_WITH_ERROR_CODE",error_description:"Blank answer with error http code: "+a}}}}f=null;if(r){var p=new i(l,t,a);if(s){t.callback.apply(window,[p])}else{if(p.error()){o.reject(p)}else{o.fulfill(p)}}}else{var p=new i({error:"ERROR_UNEXPECTED_ANSWER",error_description:"Server returned an unexpected response.",ex:{}},t,0);if(s){t.callback.apply(window,[p])}else{o.reject(p)}}};f.onerror=function(e){var r=new i({error:"ERROR_NETWORK",error_description:"A network error occurred while the request was being executed.",ex:e},t,0);if(s){t.callback.apply(window,[r])}else{o.reject(r)}};var p="";if(t.queryParams){p=r.buildQueryString(t.queryParams)}else if(typeof e.bitrix_sessid!=="undefined"){p="sessid="+e.bitrix_sessid()}if(typeof t.start!=="undefined"){p+="&start="+parseInt(t.start)}if(!!t.data){n.prepareData(t.data,"",function(e){p+="&"+e;f.send(p);a(f)})}else{f.send(p);a(f)}return s||!o?f:o};n.batch=function(e,t,s,o,a,u,f,l){return n({method:"batch",data:{halt:!!s?1:0,cmd:e},callback:function(n,s,o){if(!!t){var l=n.error();var c=n.data();var p=r.isArray(e)?[]:{};for(var d in e){if(!!e[d]&&e.hasOwnProperty(d)){if(r.isString(e[d])){var h=e[d].split("?")}else{h=[r.isArray(e[d])?e[d][0]:e[d].method,r.isArray(e[d])?e[d][1]:e[d].data]}if(c&&(typeof c.result[d]!=="undefined"||typeof c.result_error[d]!=="undefined")){p[d]=new i({result:typeof c.result[d]!=="undefined"?c.result[d]:{},error:c.result_error[d]||undefined,total:c.result_total[d],time:c.result_time[d],next:c.result_next[d]},{method:h[0],data:h[1],callback:t,endpoint:a,queryParams:u,cors:f},n.status)}else if(l){p[d]=new i({result:{},error:l.ex,total:0},{method:h[0],data:h[1],callback:t,endpoint:a,queryParams:u,cors:f},n.status)}}}t.apply(window,[p])}},sendCallback:o,endpoint:a,queryParams:u,cors:f,logTag:l})};n.xhr=function(){return new XMLHttpRequest};n.escape=function(e){return encodeURIComponent(e)};n.prepareData=function(e,t,i){var s="",o=[];if(r.isString(e)||e===null){i.call(document,e||"")}else{for(var u in e){if(!e.hasOwnProperty(u)){continue}var f=n.escape(u);if(t)f=t+"["+f+"]";if(typeof e[u]==="object"){o.push([f,e[u]])}else{if(s.length>0){s+="&"}if(typeof e[u]==="boolean"){s+=f+"="+(e[u]?1:0)}else{s+=f+"="+n.escape(e[u])}}}var l=o.length;if(l>0){var c=function(e){s+=(!!e?"&":"")+e;if(--l<=0){i.call(document,s)}};var p=l;for(var u=0;u<p;u++){if(r.isDomNode(o[u][1])){if(o[u][1].tagName.toUpperCase()==="INPUT"&&o[u][1].type==="file"){if(a.canUse()){a(o[u][1],function(e){return function(t){if(r.isArray(t)&&t.length>0){c(e+"[0]="+n.escape(t[0])+"&"+e+"[1]="+n.escape(t[1]))}else{c(e+"=")}}}(o[u][0]))}}else if(typeof o[u][1].value!=="undefined"){c(o[u][0]+"="+n.escape(o[u][1].value))}else{c("")}}else if(r.isDate(o[u][1])){c(o[u][0]+"="+n.escape(o[u][1].toJSON()))}else if(r.isArray(o[u][1])&&o[u][1].length<=0){c(o[u][0]+"=")}else{n.prepareData(o[u][1],o[u][0],c)}}}else{i.call(document,s)}}};n.isSuccess=function(e){return typeof e.status==="undefined"||e.status>=200&&e.status<300||e.status===304||e.status>=400&&e.status<500||e.status===1223||e.status===0};var i=function(e,t,n){this.answer=e;this.query=r.clone(t);this.status=n;if(typeof this.answer.next!=="undefined"){this.answer.next=parseInt(this.answer.next)}if(typeof this.answer.error!=="undefined"){this.answer.ex=new s(this.status,typeof this.answer.error==="string"?this.answer:this.answer.error)}};i.prototype.data=function(){return this.answer.result};i.prototype.time=function(){return this.answer.time};i.prototype.error=function(){return this.answer.ex};i.prototype.error_description=function(){return this.answer.error_description};i.prototype.more=function(){return!isNaN(this.answer.next)};i.prototype.total=function(){return parseInt(this.answer.total)};i.prototype.next=function(e){if(this.more()){this.query.start=this.answer.next;if(!!e&&r.isFunction(e)){this.query.callback=e}return n(this.query)}return false};var s=function(e,t){this.status=e;this.ex=t};s.prototype.getError=function(){return this.ex};s.prototype.getStatus=function(){return this.status};s.prototype.toString=function(){return this.ex.error+(!!this.ex.error_description?": "+this.ex.error_description:"")+" ("+this.status+")"};var o=function(e){var t=new Uint8Array(e);var r="";if(typeof t.forEach==="function"){t.forEach(function(e){r+=String.fromCharCode(e)})}else{var n=t.length;for(var i=0;i<n;i+=1){r+=String.fromCharCode(t[i])}}return btoa(r)};var a=function(e,t){if(a.canUse()){var r=e.files,n=0,i=e.multiple?[]:null;for(var s=0,u;u=r[s];s++){var f=new window.FileReader;f.BXFILENAME=r[s].name;f.onload=function(e){e=e||window.event;var r=[this.BXFILENAME,o(e.target.result)];if(i===null)i=r;else i.push(r);if(--n<=0){t(i)}};f.readAsArrayBuffer(u)}n=s;if(n<=0){t(i)}}};a.canUse=function(){return!!window.FileReader}})();
//# sourceMappingURL=rest.client.map.js