[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-os / client / src / 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,$timeout) {
26             this.templateUrl = 'app/directives/right-menu/right-menu.tpl.html';
27             this.restrict = 'AE';
28             this.$rootScope = $rootScope;
29             this.$window = $window;
30             this.$timeout=$timeout;
31             this.link = this._link.bind(this);
32             this.scope = {              
33                 userList :'='
34             }
35         }
36
37         _link(scope) {
38             let init = () => {
39                 scope.isOpen = true;
40                 scope.rightSideToggleBtn = 'Collapse';
41                 
42                 scope.openInNewTab = (url) => {
43                         if(url == "self") {
44                                 alert("Cannot chat with self!");
45                         } else {
46                                 var win = window.open(url, '_blank');
47                                 setCookie(url.split("chat_id=")[1], 'source', 1);
48                                 //window.localStorage.setItem(url.split("chat_id=")[1],'source'); 
49                                 win.focus();
50                         }
51                 };
52                      
53             };
54
55             init();
56             
57            
58             scope.toggleSidebar = () => {
59                 scope.isOpen = !scope.isOpen;
60                 if(scope.isOpen){
61                         scope.rightSideToggleBtn = 'Collapse';
62                 }else{
63                         scope.rightSideToggleBtn = 'Expand';
64                 }
65             };
66
67                 scope.scrollbarWidth  =function(){
68                     var $outer = $('<div>').css({visibility: 'hidden', width: 100, overflow: 'scroll'}).appendTo('body'),
69                                                 widthWithScroll = $('<div>').css({width: '100%'}).appendTo($outer).outerWidth();
70                     $outer.remove();
71                     return 100 - widthWithScroll;
72                 };
73  
74             scope.calculateUserbarOffset = function(){                  
75                 var userbarWid = $("#online-userbar").width()==0?75:$("#online-userbar").width();
76                 var scrollbarWid = scope.scrollbarWidth();
77                         var userbarOffset = scrollbarWid+userbarWid-1;
78                         /*Setting the offset for userbar*/
79                         $("#online-userbar").css("left",-userbarOffset);        
80                         /*Setting the offset for user bar toggle button*/
81                         $(".ecomp-right-sidebar-toggle-btn").css("right",scrollbarWid);
82             }
83             this.$timeout(scope.calculateUserbarOffset, 0);
84             
85             scope.isBrowserInternetExplorer = false;
86             scope.browserName = bowser.name;
87
88             if (bowser.msie || bowser.msedge) {
89                 scope.isBrowserInternetExplorer = true;
90             } else {
91                 scope.isBrowserInternetExplorer = false;
92             }
93             
94             scope.calculateUserBarHeight = () => {
95                  var footerOff = $('#online-userbar').offset().top;
96                         var headOff = $('#footer').offset().top;
97                         var userbarHeight=  parseInt($(".online-user-container").css('height'),10);
98                         var defaultOffSet = 45;
99                         // console.log(headOff - footerOff-defaultOffSet);
100                         $(".online-user-container").css({
101                                 "height" : headOff - footerOff-defaultOffSet
102                         });
103             };       
104             angular.element(this.$window).bind('resize', function(){
105                  scope.calculateUserBarHeight();
106             });
107         }
108         
109     }
110     angular.module('ecompApp').directive('rightMenu', ($rootScope,$window,$timeout) => new RightMenu($rootScope,$window,$timeout));
111 })();