nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / directives / right-menu / right-menu.directive.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 /**
21  * Created by nnaffar on 1/28/16.
22  */
23 (function () {
24     class RightMenu {
25         constructor($rootScope,$window,$log,userbarUpdateService) {
26             this.templateUrl = 'app/directives/right-menu/right-menu.tpl.html';
27             this.restrict = 'AE';
28             this.$rootScope = $rootScope;
29             this.userbarUpdateService = userbarUpdateService;
30             this.$window = $window;
31             this.$log = $log;
32             this.link = this._link.bind(this);
33             this.scope = {              
34                 userList :'='
35             }
36         }
37         
38         
39
40         _link(scope) {
41             let init = () => {
42                 scope.isOpen = true;
43                 scope.rightSideToggleBtn = 'Collapse';  
44                 
45                 scope.openInNewTab = (url) => {
46                         if(url == "self") {
47                                 alert("Cannot chat with self!");
48                         } else {
49                                 var win = window.open(url, '_blank');
50                                 setCookie(url.split("chat_id=")[1], 'source', 1);
51                                 //window.localStorage.setItem(url.split("chat_id=")[1],'source'); 
52                                 win.focus();
53                         }
54                 };
55                 
56             };
57             
58             function setCookie(cname,cvalue,exdays) {
59                     var d = new Date();
60                     d.setTime(d.getTime() + (exdays*24*60*60*1000));
61                     var expires = "expires=" + d.toGMTString();
62                     document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
63                 }
64
65                 function getCookie(cname) {
66                     var name = cname + "=";
67                     var decodedCookie = decodeURIComponent(document.cookie);
68                     var ca = decodedCookie.split(';');
69                     for(var i = 0; i < ca.length; i++) {
70                         var c = ca[i];
71                         while (c.charAt(0) == ' ') {
72                             c = c.substring(1);
73                         }
74                         if (c.indexOf(name) == 0) {
75                             return c.substring(name.length, c.length);
76                         }
77                     }
78                     return "";
79                 }
80             
81            
82
83             init();
84             
85             /***Getting the list of the users***/
86             scope.toggleSidebar = () => {
87                 scope.isOpen = !scope.isOpen;
88                 if(scope.isOpen){
89                         scope.rightSideToggleBtn = 'Collapse';
90                 }else{
91                         scope.rightSideToggleBtn = 'Expand';
92                 }
93             };
94
95             scope.isBrowserInternetExplorer = false;
96             scope.browserName = bowser.name;
97
98             if (bowser.msie || bowser.msedge) {
99                 scope.isBrowserInternetExplorer = true;
100             } else {
101                 scope.isBrowserInternetExplorer = false;
102             }
103             
104            
105
106             
107             scope.calculateUserBarHeight = () => {
108                  var footerOff = $('#online-userbar').offset().top;
109                         var headOff = $('#footer').offset().top;
110                         var userbarHeight=  parseInt($(".online-user-container").css('height'),10);
111                         var defaultOffSet = 45;
112                         // console.log(headOff - footerOff-defaultOffSet);
113                         $(".online-user-container").css({
114                                 "height" : headOff - footerOff-defaultOffSet
115                         });
116             };       
117
118             let log = this.$log;
119
120             this.userbarUpdateService.getWidthThresholdRightMenu().then(function (res) {
121             if (res.status=="ERROR") {
122                 log.error('userbarUpdateService: failed to get window width threshold for collapsing right menu; please make sure "window_width_threshold_right_menu" is specified in system.properties file.');
123             } else { 
124                 var rightMenuCollapseWidthThreshold = parseInt(res.response.windowWidth);
125                 if ($(window).width()<rightMenuCollapseWidthThreshold) {
126                     scope.toggleSidebar();
127                 }
128             }
129             })['catch'](function (err) {
130             log.error('LeftMenu Controller:: getWidthThresholdLeftMenu() failed: ' + err);
131             });
132
133             angular.element(this.$window).bind('resize', function(){
134                  scope.calculateUserBarHeight();
135             });
136         }
137         
138     }
139     angular.module('ecompApp').directive('rightMenu', ($rootScope,$window,$log,userbarUpdateService) => new RightMenu($rootScope,$window,$log,userbarUpdateService));
140 })();