Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

define(['angular', 'app'], function (angular, app) {
"use strict";

app.service("connectionErrorService", function ($modal, $http, $q) {
var service = {},
modalInfo = {value: null, dismissed: true, resendHash: []},
modalInstance,
uniqueId = 0;

var openModal = function (template, controller, modalInfo) {

modalInstance = $modal.open({
windowTemplateUrl: 'modules/ui-components/modals/helper/modal-window_template.html',
templateUrl: template,
controller: controller,
backdrop: 'static',
keyboard: false,
resolve: {
modalInfo: function () {
return modalInfo;
}
}
});
};

var dismissModal = function () {
if (angular.isDefined(modalInstance) && !modalInfo.dismissed) {
modalInfo.dismissed = true;
modalInstance.dismiss();
}
};

service.run = function () {
window.addEventListener("offline", function () {
service.showConnectionErrorMsg();
});
window.addEventListener("online", function () {
dismissModal();
});
};

service.showConnectionErrorMsg = function () {
dismissModal();
openModal('modules/core/connection/connection_error_template.html', ModalInstanceCtrl, modalInfo);
};


service.showAuthorizationErrorMsg = function () {
dismissModal();
openModal('modules/core/connection/authorization_error_template.html', ModalInstanceCtrl, modalInfo);
};


service.showServerErrorMsg = function (rejection) {
var deferred = $q.defer();

modalInfo.resendHash.push({rejection: rejection, deferred: deferred});

if (modalInfo.dismissed) {
openModal('modules/core/connection/server_error_template.html', ModalInstanceCtrl, modalInfo);
}

return deferred.promise;
};


var ModalInstanceCtrl = function ($scope, $modalInstance, modalInfo, focusService) {
modalInfo.dismissed = false;

focusService.focusTopModal();

$scope.ok = function () {
$modalInstance.close();
modalInfo.dismissed = true;
};

$scope.dismiss = function () {
$modalInstance.dismiss();
modalInfo.dismissed = true;

var resendHash = modalInfo.resendHash;
var resendHashLength = resendHash.length;
for(var i = resendHashLength - 1; i >= 0; i--) {
var resend = resendHash[i];
resend.deferred.reject(resend.rejection);
resendHash.splice(i, 1);
}
modalInstance.result.finally(function(){
if (angular.element('.primary-header h2').length) {
focusService.focusElement('.primary-header h2');
} else {
focusService.focusMain();
}
});
};

$scope.retry = function () {
$modalInstance.close();
modalInfo.dismissed = true;

var resendHash = modalInfo.resendHash;
var resendHashLength = resendHash.length;
for(var i = resendHashLength - 1; i >= 0; i--) {
var resend = resendHash[i];
$http(resend.rejection.config).success(function (data, status, headers, config) {
resend.deferred.resolve({data: data, status: status, headers: headers, config: config});
}).error(function (data, status, headers, config) {
resend.deferred.reject({data: data, status: status, headers: headers, config: config});
});
resendHash.splice(i, 1);
}
};

if (modalInfo.resendHash.length > 0) {
var rejection = modalInfo.resendHash[modalInfo.resendHash.length - 1].rejection;
if (rejection.status === 422) {
$scope.message = "The system encountered a validation error. Please check the entered data and try again.";
}
}
};

return service;
});
});