nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / directives / left-menu / left-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 (function () {
22     class LeftMenu {
23         constructor($rootScope, $log, userbarUpdateService) {
24             this.templateUrl = 'app/directives/left-menu/left-menu.tpl.html';
25             this.restrict = 'AE';
26             this.$rootScope = $rootScope;
27             this.$log = $log;
28             this.userbarUpdateService = userbarUpdateService;
29             this.link = this._link.bind(this);
30             this.scope = {
31                 sidebarModel: '='
32             }
33         }
34
35         _link(scope) {
36             let init = () => {
37                 scope.isOpen = true;
38             };
39
40             init();
41             
42             scope.refreshOnlineUsers = () => {
43                 this.userbarUpdateService.setRefreshCount(this.userbarUpdateService.maxCount);
44             };
45
46             scope.toggleSidebar = () => {
47                 scope.isOpen = !scope.isOpen;
48                 if(scope.isOpen)
49                         setContentPos(1);
50                 else
51                         setContentPos(0);
52                 
53             };
54
55             scope.isBrowserInternetExplorer = false;
56             scope.browserName = bowser.name;
57
58             if (bowser.msie || bowser.msedge) {
59                 scope.isBrowserInternetExplorer = true;
60             } else {
61                 scope.isBrowserInternetExplorer = false;
62             }
63
64             let log = this.$log;
65
66             this.userbarUpdateService.getWidthThresholdLeftMenu().then(function (res) {
67             if (res == null || res.response == null) {
68                 log.error('userbarUpdateService: failed to get window width threshold for collapsing left menu; please make sure "window_width_threshold_left_menu" is specified in system.properties file.');
69             } else { 
70                 var leftMenuCollapseWidthThreshold = parseInt(res.response.windowWidth);
71                 if ($(window).width()<leftMenuCollapseWidthThreshold) {
72                     scope.toggleSidebar();
73                 }
74             }
75             })['catch'](function (err) {
76             log.error('LeftMenu Controller:: getWidthThresholdLeftMenu() failed: ' + err);
77             });
78
79
80
81             this.$rootScope.$on('$stateChangeStart', () => {
82                 scope.isOpen = true;
83             });
84         }
85     }
86     angular.module('ecompApp').directive('leftMenu', ($rootScope,$log,userbarUpdateService) => new LeftMenu($rootScope,$log,userbarUpdateService));
87 })();
88
89 function setContentPos(open) {
90         if(open==1){
91                 $("#contentId" ).css( "padding-left", "210px" );
92         }else{
93                 $("#contentId" ).css( "padding-left", "50px" );
94         }
95
96 }