2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
22 const HTTP_PROTOCOL_RGX = /https?:\/\//;
24 constructor(applicationsService, $log, $window, conf, userProfileService, $scope,$cookies,$rootScope,confirmBoxService) {
29 var cookieDomain = this.conf.cookieDomain;
31 $scope.notificationShow=true;
32 $rootScope.showFooter = "";
33 console.log("****************** get cookie domain from config json file " + this.conf.cookieDomain);
34 $cookies.putObject('show_app_header', false,{domain: cookieDomain, path : '/'});
37 let noRefresh = function () {
38 window.onbeforeunload = function(e) {
40 var isQtoHref = false;
42 isQtoHref = e.srcElement.activeElement.href.includes("mailto");
47 if ($scope.tabs.length > 1 && isQtoHref == false) {
48 return "Changes you made may not be saved. Are you sure you want to refresh?";
54 var addTab = function (title, content) {
55 if($scope.tabs.length==tabLimit){
56 confirmBoxService.showInformation('You have reached your maximum limit of tabs allowed.').then(isConfirmed => {});
58 if(title!=='Home' && content.indexOf('https') == -1){
59 console.log('App URL: '+content+'. The application URL you are trying to open is not HTTPS. We recommend to use secured HTTPS URL while on-boarding the application.');
62 $scope.tabs.push({ title: title, content: content });
64 $scope.selectedIndex = $scope.tabs.length - 1;
65 if ($scope.tabs.length > 1) {
68 $cookies.putObject('cookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
69 $cookies.putObject('visInVisCookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
73 var adjustTitle = function (title) {
75 var nonEmptyCharPattern = /(\s|\w)/;
76 var adjustedTitle = title.substring(0,index);
77 var ext = title.charAt(index).replace(nonEmptyCharPattern,'...');
78 return adjustedTitle.concat(ext);
83 var removeTab = function (event, index) {
84 event.preventDefault();
85 event.stopPropagation();
86 $scope.tabs.splice(index, 1);
87 $cookies.putObject('cookieTabs', $scope.tabs,{domain: cookieDomain, path : '/'});
90 var selectTab = function (title) {
92 $rootScope.ContentModel.IsVisible=true;
93 $rootScope.showFooter = true;
94 $rootScope.tabBottom = 75;
97 $rootScope.ContentModel.IsVisible=false;
98 $rootScope.showFooter = false;
99 $rootScope.tabBottom = 0;
103 $scope.addTab = addTab;
104 $scope.removeTab = removeTab;
105 $scope.selectTab = selectTab;
106 $scope.adjustTitle = adjustTitle;
109 $rootScope.ContentModel = {
115 var sessionActive = applicationsService.ping()
116 .then(sessionActive => {
117 $log.debug('TabsCtrl::addTab: applicationsService.ping() = ' + JSON.stringify(sessionActive));
119 var cookieTabs = $cookies.getObject('cookieTabs');
120 if(cookieTabs!=null){
121 for(var t in cookieTabs){
122 console.log('TabsCtrl::addTab: cookieTabs title: '+cookieTabs[t].title);
123 if(cookieTabs[t].title!=null && cookieTabs[t].title==='Home'){
124 cookieTabs[t].content = "";
125 $rootScope.ContentModel.IsVisible=true;
128 addTab( cookieTabs[t].title, cookieTabs[t].content) ;
131 for (var i = 0; i < 1; i++) {
136 $rootScope.ContentModel.IsVisible=true;
138 addTab(title, content);
142 $scope.selectedIndex = 0;
145 $scope.$watchCollection(function() { return $cookies.getObject('addTab'); }, function(newValue) {
146 var tabContent = $cookies.getObject('addTab');
147 if(tabContent!=null && tabContent.url!=null){
148 var tabExists = false;
149 for(var x in $scope.tabs){
150 console.log($scope.tabs[x].content);
151 if($scope.tabs[x].title==tabContent.title){
153 $scope.selectedIndex = x;
157 addTab( tabContent.title, tabContent.url) ;
159 $cookies.remove('addTab');
169 TabsCtrl.$inject = ['applicationsService', '$log', '$window', 'conf','userProfileService', '$scope','$cookies','$rootScope','confirmBoxService'];
170 angular.module('ecompApp').controller('TabsCtrl', TabsCtrl);
172 angular.module('ecompApp').directive('mainArea', function() {
175 templateUrl: 'app/views/tabs/tabframe.html',
176 link: function(scope, element) {
184 angular.module('ecompApp').directive('tabHighlight', [function () {
187 link: function (scope, element) {
188 var x, y, initial_background = '#c3d5e6';
192 .mousemove(function (e) {
193 if(!element.hasClass('md-active'))
195 x = e.pageX - this.offsetLeft;
196 y = e.pageY - this.offsetTop;
199 .css({ background: '-moz-radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background })
200 .css({ background: '-webkit-radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background })
201 .css({ background: 'radial-gradient(circle at ' + x + 'px ' + y + 'px, rgba(255,255,255,0.4) 0px, rgba(255,255,255,0.0) 45px), ' + initial_background });
204 .mouseout(function () {
205 element.removeAttr('style');
215 function getParameterByName(name, url) {
216 if (!url) url = window.location.href;
217 name = name.replace(/[\[\]]/g, "\\$&");
218 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
219 results = regex.exec(url);
220 if (!results) return '';
221 if (!results[2]) return '';
222 return (results[2].replace(/\+/g, " "));
225 function isCascadeFrame(ref) {
227 var e = document.body;
228 e.parentNode.removeChild(e);
229 window.location = "unKnownError";