SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/innovation-studio/studio-controller.js

127 lines
6.9 KiB
JavaScript

'use strict';
(function () {
'use strict';
angular.module('innovationStudio')
.controller('StudioController', ['$scope', '$state', '$sce', '$rootScope', '$timeout', 'studioModel',
function ($scope, $state, $sce, $rootScope, $timeout, studioModel) {
var extendedUrl = '/helix/index.html#';
var studioBaseUrl = '';
var calendarStaticUrl = '/com.bmc.dsm.itsm-applications/iview/com.bmc.dsm.itsm-applications:Calendar';
var sharedConsoleStaticUrl = '/com.bmc.dsm.itsm-applications/iview/com.bmc.dsm.itsm-applications:IT%20Ticket%20Console%20SM';
var assetConsoleStaticUrl = '/com.bmc.dsm.itsm-applications/iview/com.bmc.dsm.itsm-applications:Asset%20Console%20SM';
if ($state.current.name === 'calendarStudio') {
if (studioModel.ccsFetched) {
if (studioModel.enableISCalendar && studioModel.baseUrlForIS) {
studioBaseUrl = studioModel.baseUrlForIS;
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + calendarStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('calendar');
}
}
else {
studioModel.calendarEnabledPromise().then(function (enableISCalendar) {
//Sample baseUrl format: http://<sub-domain>.<domain>.com:8008
studioBaseUrl = studioModel.baseUrlForIS;
if (enableISCalendar && studioBaseUrl) {
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + calendarStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('calendar');
}
});
}
}
else if ($state.current.name === 'ticketConsoleStudio') {
if (studioModel.ccsFetched) {
if (studioModel.enableSharedConsole && studioModel.baseUrlForIS) {
studioBaseUrl = studioModel.baseUrlForIS;
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + sharedConsoleStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('ticketConsole');
}
}
else {
studioModel.sharedConsoleEnabledPromise().then(function (enableSharedConsole) {
//Sample baseUrl format: http://<sub-domain>.<domain>.com:8008
studioBaseUrl = studioModel.baseUrlForIS;
if (enableSharedConsole && studioBaseUrl) {
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + sharedConsoleStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('ticketConsole');
}
});
}
}
else if ($state.current.name === 'assetConsoleStudio') {
if (studioModel.ccsFetched) {
if (studioModel.enableISAssetConsole && studioModel.baseUrlForIS) {
studioBaseUrl = studioModel.baseUrlForIS;
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + assetConsoleStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('assetConsole');
}
}
else {
studioModel.assetConsoleEnabledPromise().then(function (enableISAssetConsole) {
//Sample baseUrl format: http://<sub-domain>.<domain>.com:8008
studioBaseUrl = studioModel.baseUrlForIS;
if (enableISAssetConsole && studioBaseUrl) {
$rootScope.studioFrameUrl = $sce.trustAsResourceUrl(studioBaseUrl + extendedUrl + assetConsoleStaticUrl + "?SmartIT_URL=" + studioModel.smartITUrl);
setStudioFrameUrl($rootScope.studioFrameUrl);
}
else {
$state.go('assetConsole');
}
});
}
}
function setStudioFrameUrl(studioFrameUrl) {
var studioFrame = document.getElementsByClassName('app__studio-iframe');
console.info('Inside setStudioFrameUrl method - url : ' + studioFrameUrl);
if (studioFrame && studioFrame.length !== 0) {
if (studioFrameUrl) {
setTimeout(function () {
studioFrame[0].contentWindow.location.replace(studioFrameUrl);
});
console.info('Inside setStudioFrameUrl method - location url changed');
}
}
else {
console.error('Inside setStudioFrameUrl method : studio iframe not loaded');
}
}
$(document).on('focusout', function () {
$timeout(function () {
var navElement;
// using the $timeout to let the event pass the run loop
if (document.activeElement instanceof HTMLIFrameElement) {
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);
});
}]);
})();