%PDF- %PDF-
Direktori : /proc/985914/root/data/old/home/stash/stash/atlassian-stash/static/stash/api/util/ |
Current File : //proc/985914/root/data/old/home/stash/stash/atlassian-stash/static/stash/api/util/server-min.js |
define("stash/api/util/server",["aui","jquery","underscore","stash/api/util/navbuilder","util/error","util/function","model/page-state","widget/error-dialog","exports"],function(L,E,M,F,A,I,K,O,D){E.ajaxSetup({timeout:60000});var G=false;function C(W,X,V,U){var R=new Date();if(R<V){var T=function(){var Y=Math.ceil((+V-+new Date())/X);if(Y<=0){clearInterval(S);U()}else{W.text(Y)}},S=setInterval(T,X);T()}else{U()}}function Q(T,S,V,W,U){var R=new Date();if(R<U){T.addClass("hidden");T.before(S);C(V,W,U,function(){S.remove();T.removeClass("hidden")})}}function N(V,W,Z,a){var U,R,e;function b(f){R=f;e=R.abort;R.abort=Y}function Y(){e.apply(R,arguments)}function T(o,w,i,t,u,v,l){if(o.shouldLogin){window.onbeforeunload=null;window.location.href=F.login().next(window.location.href).build();return E.Deferred()}if(w){delete w.errors}var p;if(!G){p=new O()}var s=o.shouldRetry&&!G?E.Deferred():E.Deferred().rejectWith(this,[t,i,u,w,p]);if(!G){var m="",j=false;var q=stash.widget.errorContent(o);p.addHideListener(function(){G=false});var r={id:"ajax-error",titleText:o.title,titleClass:o.titleClass||"error-header",showCloseButton:M.isUndefined(o.canClose)?true:o.canClose,closeOnOutsideClick:false};if(o.fallbackUrl){r.okButtonText=L.escapeHtml(o.fallbackTitle);p.addOkListener(function(x){window.location.href=o.fallbackUrl;x.preventDefault()})}else{if(o.shouldReload){r.okButtonText=L.escapeHtml(L.I18n.getText("stash.web.ajax.reload"));p.addOkListener(function(x){window.location.reload();x.preventDefault()})}else{if(o.shouldRetry){s.notify("stalled");if(o.retryAfterDate){if(+o.retryAfterDate-+new Date()>60*60*1000){m=L.I18n.getText("stash.web.retry.later")}else{j=true}}r.okButtonText=L.escapeHtml(L.I18n.getText("stash.web.ajax.try.again"));var n;p.addOkListener(function(x){s.notify("unstalled");p.remove();n=J(v,l);b(n);n.done(function(){return s.resolveWith(this,arguments)});n.fail(function(){return s.rejectWith(this,arguments)});x.preventDefault()});p.addHideListener(function(){if(s.state()==="pending"&&!n){s.rejectWith(this,[t,i,u,w])}})}else{r.showCloseButton=false}}}r.panelContent="<p>"+q+m+"</p>";p.reinit(r).show();G=true;if(j){var f,k;if(+o.retryAfterDate-+new Date()>60*1000){k=L.I18n.getText("stash.web.retry.in.x.minutes","<time><span></span>","</time>");f=60*1000}else{k=L.I18n.getText("stash.web.retry.in.x.seconds","<time><span></span>","</time>");f=1000}var h=E("<span>"+k+"</span>"),g=h.children("time").children();Q(p.getOkButton(),h,g,f,o.retryAfterDate)}}return s}function c(h,f,g,i,n,m){var l=a?A.getDominantRESTError(h,g):A.getDominantAJAXError(g),j=true;if(n){var k=n(l);if(k&&typeof k.promise==="function"){return k.promise(g)}if(k&&M.isObject(k)){l=k}j=k!==false}if(j&&l){return T(l,h,f,g,i,W,a)}else{return m()}}function d(f){var g=Z[f];if(g===undefined||g===null){g=Z["*"]}if(typeof g==="function"){return g}else{return I.constant(g)}}function X(j,k,i){var g=this;var h=d(i.status),f=h?M.bind(h,g,j,k,i):null;return c(j,k,i,null,f,function(){return E.Deferred().resolveWith(g,[j,k,i])})}function S(i,m,l){var g=this;var j=i.responseText;try{j=JSON.parse(j)}catch(k){}var h=d(i.status),f=h?M.bind(h,g,i,m,l,j):null;return c(j,m,i,l,f,function(){return E.Deferred().rejectWith(g,[i,m,l,j])})}b(V);U=V.then(X,S);return U.promise(V)}function P(T,S){var R;if(T.statusCode){R=T.statusCode;delete T.statusCode}R=R||{};var U=N(E.ajax(T),T,R,S);U.statusCode=function(W){if(W){if(U.state()==="pending"){E.extend(R,W)}else{for(var X in W){if(W.hasOwnProperty(X)){L.log("xhr.statusCode() should not be called after the request has completed. Your handler will have no affect on the resolution of the request.");break}}var V=W[U.status];U.then(V,V)}}};return U}function J(R){return P(R)}function B(R){var S={};if(K.getCurrentUser()){S["X-AUSERNAME"]=K.getCurrentUser().getName();S["X-AUSERID"]=K.getCurrentUser().getId()}R=E.extend(true,{dataType:"json",contentType:"application/json",headers:S,jsonp:false,type:"GET"},R);if(R.type.toUpperCase()!=="GET"&&(E.isPlainObject(R.data)||E.isArray(R.data))){R.data=JSON.stringify(R.data)}return P(R,true)}function H(S){S=E.extend({pollTimeout:60000,interval:500,delay:0,tick:E.noop},S);var T=false;var V=false;var X=E.Deferred(),U=new Date().getTime(),R=function(){if(T||V){return }V=true;B(S).done(function(Z,b,a){var Y=S.tick(Z,b,a);if(Y){X.resolveWith(this,[Z,b,a])}else{if((new Date().getTime()-U)>S.pollTimeout||typeof Y!=="undefined"){X.rejectWith(this,[a,b,null,Z])}else{setTimeout(R,S.interval)}}}).fail(function(a,b,Z,Y){X.rejectWith(this,[a,b,Z,Y])}).always(function(){V=false})};setTimeout(R,S.delay);var W=X.promise();W.resume=function(){if(T){T=false;R()}};W.pause=function(){T=true};return W}D.ajax=J;D.rest=B;D.poll=H});