Replace ecomp references
[portal.git] / ecomp-portal-FE-os / client / src / directives / right-menu / right-menu.directive.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 (function () {
39     class RightMenu {
40         constructor($rootScope,$window,$timeout) {
41             this.templateUrl = 'app/directives/right-menu/right-menu.tpl.html';
42             this.restrict = 'AE';
43             this.$rootScope = $rootScope;
44             this.$window = $window;
45             this.$timeout=$timeout;
46             this.link = this._link.bind(this);
47             this.scope = {              
48                 userList :'='
49             }
50         }
51
52         _link(scope) {
53             let init = () => {
54                 scope.isOpen = true;
55                 scope.rightSideToggleBtn = 'Collapse';
56                 
57                 scope.openInNewTab = (url) => {
58                         if(url == "self") {
59                                 alert("Cannot chat with self!");
60                         } else {
61                                 var win = window.open(url, '_blank');
62                                 setCookie(url.split("chat_id=")[1], 'source', 1);
63                                 //window.localStorage.setItem(url.split("chat_id=")[1],'source'); 
64                                 win.focus();
65                         }
66                 };
67                      
68             };
69
70             init();
71             
72            
73             scope.toggleSidebar = () => {
74                 scope.isOpen = !scope.isOpen;
75                 if(scope.isOpen){
76                         scope.rightSideToggleBtn = 'Collapse';
77                 }else{
78                         scope.rightSideToggleBtn = 'Expand';
79                 }
80             };
81
82                 scope.scrollbarWidth  =function(){
83                     var $outer = $('<div>').css({visibility: 'hidden', width: 100, overflow: 'scroll'}).appendTo('body'),
84                                                 widthWithScroll = $('<div>').css({width: '100%'}).appendTo($outer).outerWidth();
85                     $outer.remove();
86                     return 100 - widthWithScroll;
87                 };
88  
89             scope.calculateUserbarOffset = function(){                  
90                 var userbarWid = $("#online-userbar").width()==0?75:$("#online-userbar").width();
91                 var scrollbarWid = scope.scrollbarWidth();
92                         var userbarOffset = scrollbarWid+userbarWid-1;
93                         /*Setting the offset for userbar*/
94                         $("#online-userbar").css("left",-userbarOffset);        
95                         /*Setting the offset for user bar toggle button*/
96                         $(".ecomp-right-sidebar-toggle-btn").css("right",scrollbarWid);
97             }
98             this.$timeout(scope.calculateUserbarOffset, 0);
99             
100             scope.isBrowserInternetExplorer = false;
101             scope.browserName = bowser.name;
102
103             if (bowser.msie || bowser.msedge) {
104                 scope.isBrowserInternetExplorer = true;
105             } else {
106                 scope.isBrowserInternetExplorer = false;
107             }
108             
109             scope.calculateUserBarHeight = () => {
110                  var footerOff = $('#online-userbar').offset().top;
111                         var headOff = $('#footer').offset().top;
112                         var userbarHeight=  parseInt($(".online-user-container").css('height'),10);
113                         var defaultOffSet = 45;
114                         // console.log(headOff - footerOff-defaultOffSet);
115                         $(".online-user-container").css({
116                                 "height" : headOff - footerOff-defaultOffSet
117                         });
118             };       
119             angular.element(this.$window).bind('resize', function(){
120                  scope.calculateUserBarHeight();
121             });
122         }
123         
124     }
125     angular.module('ecompApp').directive('rightMenu', ($rootScope,$window,$timeout) => new RightMenu($rootScope,$window,$timeout));
126 })();