@corpecca/qp-web-resources
Version:
Qp web resources
1 lines • 2.93 kB
JavaScript
(function(n,t){if(t){n.ng=n.ng||{};n.ng.http={defaultError:{message:"An error has occurred!",details:"Error detail not sent by server."},defaultError401:{message:"You are not authenticated!",details:"You should be authenticated (sign in) in order to perform this operation."},defaultError403:{message:"You are not authorized!",details:"You are not allowed to perform this operation."},defaultError404:{message:"Resource not found!",details:"The resource requested could not be found on the server."},logError:function(t){n.log.error(t)},showError:function(t){return t.details?n.message.error(t.details,t.message||n.ng.http.defaultError.message):n.message.error(t.message||n.ng.http.defaultError.message)},handleTargetUrl:function(t){location.href=t?t:n.appPath},handleNonQpErrorResponse:function(t,i){if(t.config.qpHandleError!==!1)switch(t.status){case 401:n.ng.http.handleUnAuthorizedRequest(n.ng.http.showError(n.ng.http.defaultError401),n.appPath);break;case 403:n.ng.http.showError(n.ajax.defaultError403);break;case 404:n.ng.http.showError(n.ajax.defaultError404);break;default:n.ng.http.showError(n.ng.http.defaultError)}i.reject(t)},handleUnAuthorizedRequest:function(t,i){t?t.done(function(){n.ng.http.handleTargetUrl(i||n.appPath)}):n.ng.http.handleTargetUrl(i||n.appPath)},handleResponse:function(t,i){var r=t.data,u;r.success===!0?(t.data=r.result,i.resolve(t),r.targetUrl&&n.ng.http.handleTargetUrl(r.targetUrl)):r.success===!1?(u=null,r.error?t.config.qpHandleError!==!1&&(u=n.ng.http.showError(r.error)):r.error=defaultError,n.ng.http.logError(r.error),t.data=r.error,i.reject(t),t.status==401&&t.config.qpHandleError!==!1&&n.ng.http.handleUnAuthorizedRequest(u,r.targetUrl)):i.resolve(t)}};var i=t.module("qp",[]);i.config(["$httpProvider",function(t){t.interceptors.push(["$q",function(t){return{request:function(t){return t.url.indexOf(".cshtml")!==-1&&(t.url=n.appPath+"QpAppView/Load?viewUrl="+t.url+"&_t="+n.pageLoadTime.getTime()),t},response:function(i){if(!i.data||!i.data.__qp)return i;var r=t.defer();return n.ng.http.handleResponse(i,r),r.promise},responseError:function(i){var r=t.defer();return i.data&&i.data.__qp?n.ng.http.handleResponse(i,r):n.ng.http.handleNonQpErrorResponse(i,r),r.promise}}}])}]);n.event.on("qp.dynamicScriptsInitialized",function(){n.ng.http.defaultError.message=n.localization.qpWeb("DefaultError");n.ng.http.defaultError.details=n.localization.qpWeb("DefaultErrorDetail");n.ng.http.defaultError401.message=n.localization.qpWeb("DefaultError401");n.ng.http.defaultError401.details=n.localization.qpWeb("DefaultErrorDetail401");n.ng.http.defaultError403.message=n.localization.qpWeb("DefaultError403");n.ng.http.defaultError403.details=n.localization.qpWeb("DefaultErrorDetail403");n.ng.http.defaultError404.message=n.localization.qpWeb("DefaultError404");n.ng.http.defaultError404.details=n.localization.qpWeb("DefaultErrorDetail404")})}})(qp||(qp={}),angular||undefined);