Files
sysPass/js/app-requests.min.js

9 lines
3.0 KiB
JavaScript

var $jscomp={scope:{},checkStringArgs:function(a,d,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(d instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""}};
$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(a,d,c){if(c.get||c.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[d]=c.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,d,c,e){if(d){c=$jscomp.global;a=a.split(".");for(e=0;e<a.length-1;e++){var b=a[e];b in c||(c[b]={});c=c[b]}a=a[a.length-1];e=c[a];d=d(e);d!=e&&null!=d&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:d})}};
$jscomp.polyfill("String.prototype.startsWith",function(a){return a?a:function(a,c){var d=$jscomp.checkStringArgs(this,a,"startsWith");a+="";for(var b=d.length,h=a.length,g=Math.max(0,Math.min(c|0,d.length)),f=0;f<h&&g<b;)if(d[g++]!=a[f++])return!1;return f>=h}},"es6-impl","es3");
sysPass.Requests=function(a){var d=a.log,c=[],e={get:function(){return c},add:function(b){var a=""===b.hash?SparkMD5.hash(JSON.stringify(b),!1):b.hash;if(0<c.length&&c[c.length-1].hash===a)return c;d.info("history:add");b.hash=a;c.push(b);15<=c.length&&c.splice(0,10);return c},del:function(){d.info("history:del");if("undefined"!==typeof c.pop())return c[c.length-1]},reset:function(){d.info("history:reset");c=[]},length:function(){return c.length}};return{getRequestOpts:function(){return Object.create({type:"json",
url:"",method:"post",callback:"",async:!0,data:"",cache:!1,processData:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",timeout:0,addHistory:!1,hash:"",useLoading:!0})},getActionCall:function(b,c,g){d.info("getActionCall");var f=b.url.startsWith("http",0)||b.url.startsWith("https",0)?b.url:a.config().APP_ROOT+b.url;return $.ajax({dataType:b.type,url:f,method:b.method,async:b.async,data:b.data,cache:b.cache,processData:b.processData,contentType:b.contentType,timeout:b.timeout,beforeSend:function(){!0===
b.useLoading&&a.appTheme().loading.show()},success:function(a){if("function"!==typeof c)return!0;!0===b.addHistory&&(b.callback=c,e.add(b));c(a)},error:function(c,e,f){"function"!==typeof g?(c=a.config().LANG[1]+"<p>"+f+e+"</p>",d.error(c),"html"===b.type&&$("#content").html(a.msg.html.error(f)),a.msg.error(c)):g()},complete:function(){!0===b.useLoading&&a.appTheme().loading.hide();a.appTheme().ajax.complete()}})},getActionPromise:function(b,c){d.info("getActionPromise");var e=b.url.startsWith("http",
0)||b.url.startsWith("https",0)?b.url:a.config().APP_ROOT+b.url;$.when($.ajax({dataType:b.type,url:e,method:b.method,async:b.async,data:b.data,cache:b.cache,processData:b.processData,contentType:b.contentType,timeout:b.timeout})).done(c)},history:e}};