MDL-54551 core: touch-up after review
[moodle.git] / lib / amd / build / ajax.min.js
CommitLineData
feb6a520 1define(["jquery","core/config","core/log","core/url"],function(a,b,c,d){var e=!1,f=function(a){var b,c,e=this,f=null,g=0;if(a.error)for(;g<e.length;g++)b=e[g],b.deferred.reject(a);else{for(g=0;g<e.length;g++){if(b=e[g],c=a[g],"undefined"==typeof c){f=new Error("missing response");break}if(c.error!==!1){f=c.exception;break}b.deferred.resolve(c.data)}if(null!==f)if("servicerequireslogin"===f.errorcode)window.location=d.relativeUrl("/login/index.php");else for(;g<e.length;g++)b=e[g],b.deferred.reject(f)}},g=function(a,b,d){var f=this,g=0;for(g=0;g<f.length;g++){var h=f[g];e?(c.error("Page unloaded."),c.error(d)):h.deferred.reject(d)}};return{call:function(c,d,h){a(window).bind("beforeunload",function(){e=!0});var i,j=[],k=[],l=[],m="";for("undefined"==typeof h&&(h=!0),"undefined"==typeof d&&(d=!0),i=0;i<c.length;i++){var n=c[i];j.push({index:i,methodname:n.methodname,args:n.args}),n.deferred=a.Deferred(),k.push(n.deferred.promise()),"undefined"!=typeof n.done&&n.deferred.done(n.done),"undefined"!=typeof n.fail&&n.deferred.fail(n.fail),n.index=i,l.push(n.methodname)}m=l.length<=5?l.sort().join():l.length+"-method-calls",j=JSON.stringify(j);var o={type:"POST",data:j,context:c,dataType:"json",processData:!1,async:d,contentType:"application/json"},p="service.php";h||(p="service-nologin.php");var q=b.wwwroot+"/lib/ajax/"+p+"?sesskey="+b.sesskey+"&info="+m;return d?a.ajax(q,o).done(f).fail(g):(o.success=f,o.error=g,a.ajax(q,o)),k}}});