112 lines
5.4 KiB
JavaScript
112 lines
5.4 KiB
JavaScript
/**
|
|
* Created by mkumar1 on 03-06-2019.
|
|
*/
|
|
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('calendarModule')
|
|
.controller('CalendarController', ['$scope', 'permissionModel', 'metadataModel', '$rootScope', 'AUTH_EVENTS', '$window', 'authModel',
|
|
function ($scope, permissionModel, metadataModel, $rootScope, AUTH_EVENTS, $window, authModel) {
|
|
var permissions = [];
|
|
['change', 'release'].forEach(function (ticketType) {
|
|
if (permissionModel.hasPermissionForCalendar(ticketType)) {
|
|
permissions.push(ticketType);
|
|
}
|
|
});
|
|
$scope.dataLoading = true;
|
|
$scope.ccsEnabledForCalendar = true;
|
|
metadataModel.getMetadataByType('global').then(function (metadata) {
|
|
$scope.ccsEnabledForCalendar = metadata && metadata.configurationParameters && metadata.configurationParameters.calendarFeatureEnabled === 'true';
|
|
}).catch(function (error) {
|
|
if (error) {
|
|
$scope.ccsEnabledForCalendar = false;
|
|
}
|
|
});
|
|
$scope.checkIfJson = function (str) {
|
|
if (str.length == 0) {
|
|
return false;
|
|
}
|
|
try {
|
|
JSON.parse(str);
|
|
if (!isNaN(str))
|
|
return false;
|
|
}
|
|
catch (e) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
$(document).on('focusout', function () {
|
|
setTimeout(function () {
|
|
// using the 'setTimout' to let the event pass the run loop
|
|
if (document.activeElement instanceof HTMLIFrameElement) {
|
|
var navElement = document.getElementsByClassName('open');
|
|
if (navElement.length) {
|
|
var dropdownElement = navElement[0].getElementsByClassName('dropdown-toggle');
|
|
if (dropdownElement.length) {
|
|
dropdownElement = dropdownElement[0];
|
|
dropdownElement.click();
|
|
}
|
|
}
|
|
else {
|
|
navElement = document.getElementsByClassName('search__close');
|
|
if (navElement.length) {
|
|
var closeButton = navElement[0];
|
|
closeButton.click();
|
|
}
|
|
}
|
|
}
|
|
}, 0);
|
|
});
|
|
window.onmessage = handleMessage;
|
|
function handleMessage(e) {
|
|
if (typeof e.data === 'string' && $scope.checkIfJson(e.data)) {
|
|
var dataObj = JSON.parse(e.data);
|
|
if (dataObj.hasOwnProperty('information')) {
|
|
var iFrameUrl = (dataObj.information === 'local') ? 'http://localhost:4200' : window.location.origin;
|
|
var iframeWindow = document.getElementsByClassName('app__calendar-iframe')[0].contentWindow;
|
|
var parcelObject = { permissions: permissions };
|
|
//check if filter state is present in the session storage.
|
|
var filterState = sessionStorage.getItem('calendarFilterState');
|
|
var defaultView = sessionStorage.getItem('calendarFilterView');
|
|
var calDate = sessionStorage.getItem('calendarFilterDate');
|
|
if (filterState) {
|
|
parcelObject.calendarFilterState = filterState;
|
|
}
|
|
if (defaultView) {
|
|
parcelObject.calendarFilterView = defaultView;
|
|
}
|
|
if (calDate) {
|
|
parcelObject.calendarFilterDate = calDate;
|
|
}
|
|
iframeWindow.postMessage(JSON.stringify(parcelObject), iFrameUrl); //NOSONAR
|
|
}
|
|
else if (dataObj.hasOwnProperty('filterState')) {
|
|
var calendarFilterState = dataObj.filterState;
|
|
sessionStorage.setItem('calendarFilterState', angular.toJson(calendarFilterState));
|
|
}
|
|
else if (dataObj.hasOwnProperty('filterView')) {
|
|
sessionStorage.setItem('calendarFilterView', dataObj.filterView);
|
|
}
|
|
else if (dataObj.hasOwnProperty('filterDate')) {
|
|
sessionStorage.setItem('calendarFilterDate', dataObj.filterDate);
|
|
}
|
|
else if (dataObj.hasOwnProperty('sessionExpired')) {
|
|
if (authModel.isSSOEnabled()) {
|
|
$rootScope.$broadcast(AUTH_EVENTS.SESSION_EXPIRED);
|
|
}
|
|
else {
|
|
window.location.reload();
|
|
}
|
|
}
|
|
else if (dataObj.hasOwnProperty('initialize-metadata-error')) {
|
|
$rootScope.$broadcast(AUTH_EVENTS.INITIALIZE_METADATA_ERROR, dataObj);
|
|
}
|
|
$scope.dataLoading = false;
|
|
$scope.$digest();
|
|
}
|
|
}
|
|
}
|
|
]);
|
|
})();
|