mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-08 09:26:57 +01:00
6 lines
2.1 KiB
JavaScript
6 lines
2.1 KiB
JavaScript
sysPass.Requests=function(c){var d=c.log,b=[],g={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,useFullLoading:!1};Object.seal(g);var h={get:function(){return b},add:function(a){var e=""===a.hash?SparkMD5.hash(JSON.stringify(a),!1):a.hash;if(0<b.length&&b[b.length-1].hash===e)return b;d.info("history:add");a.hash=e;b.push(a);15<=b.length&&b.splice(0,10);
|
|
return b},del:function(){d.info("history:del");if("undefined"!==typeof b.pop())return b[b.length-1]},reset:function(){d.info("history:reset");b=[]},length:function(){return b.length}},k=function(a){return-1===a.indexOf("http")&&-1===a.indexOf("https")?c.config().APP_ROOT+a:a};return{getRequestOpts:function(){return Object.create(g)},getActionCall:function(a,b,l){d.info("getActionCall");return $.ajax({dataType:a.type,url:k(a.url),method:a.method,async:a.async,data:a.data,cache:a.cache,processData:a.processData,
|
|
contentType:a.contentType,timeout:a.timeout,beforeSend:function(){!0===a.useLoading&&c.appTheme().loading.show(a.useFullLoading)},success:function(n){if("function"!==typeof b)return!0;!0===a.addHistory&&(a.callback=b,h.add(a));b(n)},error:function(b,e,m){"function"!==typeof l?(b=c.config().LANG[1]+"<p>"+m+e+"</p>",d.error(b),"html"===a.type&&$("#content").html(c.msg.html.error(m)),c.msg.error(b)):l()},complete:function(b){!0===a.useLoading&&c.appTheme().loading.hide();"json"===a.type&&void 0!==b.responseJSON.csrf&&
|
|
""!==b.responseJSON.csrf&&c.sk.set(b.responseJSON.csrf);c.appTheme().ajax.complete()}})},getActionEvent:function(a,b,c){var e=k(a.url),e=e+("?"+$.param(a.data)),f=new EventSource(e);f.addEventListener("message",function(a){a=JSON.parse(a.data);d.debug(a);1===a.end?(d.info("getActionEvent:Ending"),f.close(),"function"===typeof c&&c(a)):"function"===typeof b&&b(a)});f.addEventListener("error",function(a){d.error("getActionEvent:Error occured");f.close()});return f},getRouteForQuery:function(a,b){return"object"===
|
|
typeof b?{r:a+"/"+b.join("/")}:{r:a+"/"+b}},history:h}};
|