Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / directives / leftMenu.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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 app.directive('qMenu', function () {
22     return {
23         restrict: 'A', //This menas that it will be used as an attribute and NOT as an element. I don't like creating custom HTML elements
24         replace: false,
25         templateUrl: "app/fusion/scripts/view-models/left_menu.html",
26         controller: ['$scope', '$filter','$http','$timeout','$cookies','LeftMenuService', function ($scope, $filter, $http,$timeout,$cookies,LeftMenuService) {
27                 
28                 $scope.leftChildData=[];
29                 $scope.leftParentData=[];
30                 $scope.leftMenuItems = [];
31                 $scope.app_name = "";
32                 $scope.app_name_full;
33                 LeftMenuService.getLeftMenu().then(function(response){
34                         var j = response; 
35                         try{
36                                 if(j && j !== "null" && j!== "undefined"){
37                                         $scope.leftParentData = JSON.parse(j.data);
38                             $scope.leftChildData = JSON.parse(j.data2);
39                                 }else{
40                                         throw "Get Left Menu respsone is not an object/is empty"; 
41                                 }  
42                         try{
43                                         var leftChildItemList = $scope.leftChildData;
44                                 var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1];
45                                 var leftParentList =$scope.leftParentData;
46                                 for (var i = 0; i < leftParentList.length; i++) {
47                                         $scope.item = {
48                                                 parentLabel : leftParentList[i].label,
49                                                 parentAction : leftParentList[i].action,
50                                                 parentImageSrc : leftParentList[i].imageSrc,                                            
51                                                 open:pageUrl==leftParentList[i].action?true:false,
52                                                 childItemList : leftChildItemList[i]
53                                         }
54                                         $scope.leftMenuItems.push($scope.item);
55                                 };   
56                                 }catch(err){
57                                         console.log("error happened while trying to set left menu structure"+err);                                         
58                                 }
59                         }catch (e) {
60                                 console.log("error happened while trying to get left menu items"+e);
61                                 reloadPageOnce();
62                                 return;
63                 }              
64                 },function(error){
65                         console.log("error happened while calling getLeftMenu"+error);
66                 });
67                 
68                 LeftMenuService.getAppName().then(function(response){
69                         var j = response; 
70                         try{
71                                 if(j && j !== "null" && j!== "undefined"){
72                                         console.log("app name is " + $scope.app_name);
73                                         $scope.app_name_full = j.data;
74                                         var processed_app_name = j.data;
75                                         var n = processed_app_name.length;
76                                         if (n > 15) {
77                                                 n = 15;
78                                         }
79                                         $scope.app_name = processed_app_name.substr(0, n);
80                                 }else{
81                                         throw "Get app_name respsone is not an object/is empty"; 
82                                 }  
83                         }catch (e) {
84                                 console.log("error happened while trying to get app name "+e);
85                                 return;
86                 }              
87                 },function(error){
88                         console.log("error happened while calling getAppName "+error);
89                 });
90                 
91                 $scope.adjustHeader=function() {
92                         $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header);
93                         
94                         if($scope.showHeader == true) {
95                         $scope.drawer_margin_top = 50;
96                         $scope.drawer_custom_top = 20;
97                         $scope.toggle_drawer_top = 55;
98                         }
99                         else  {
100                                 
101                                 $scope.drawer_margin_top = 0;
102                         $scope.drawer_custom_top = 0;
103                         $scope.toggle_drawer_top = 0;
104                         }
105                         
106                         
107                 };
108
109                 $scope.adjustHLeftMenu = function (type){
110                         $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header);
111                         
112                         if($scope.showHeader == true) {
113                         $scope.drawer_margin_top = 60;
114                         $scope.drawer_custom_top = 54;
115                         $scope.toggle_drawer_top = 55;
116                         }
117                         else  {
118                                 
119                                 $scope.drawer_margin_top = 50;
120                         $scope.drawer_custom_top = 0;
121                         $scope.toggle_drawer_top = 10;
122                         }
123                         if(type=='burgerIcon'){
124                                 return { "top": $scope.toggle_drawer_top+"px"};
125                         }else if(type=='leftMenu'){
126                                 return { "margin-top": $scope.drawer_margin_top+"px"};
127                         }else
128                                 return;
129                 }
130                 $scope.adjustHeader();
131                 $scope.drawerOpen = true;
132
133                 $scope.toggleDrawer = function() {
134                         $scope.drawerOpen = !($scope.drawerOpen);
135                         if ($scope.drawerOpen) {
136                         // setCookie('drawerOpen','open',30);
137                         $scope.arrowShow = true;
138
139
140                         if (document.getElementById('fnMenueContent')!=null)
141                         document.getElementById('fnMenueContent').style.marginLeft = "0px";
142                         
143                         if (document.getElementById('rightContentAdmin')!=null)
144                                         document.getElementById('rightContentAdmin').style.marginLeft = "210px"; 
145                                         
146                                 else if (document.getElementById('rightContentProfile')!=null)
147                                         document.getElementById('rightContentProfile').style.marginLeft = "210px";
148
149
150
151                         } else {
152
153                         $scope.arrowShow = false;
154
155                         if (document.getElementById('fnMenueContent')!=null)
156                         document.getElementById('fnMenueContent').style.marginLeft = "-150px";
157                         
158                         if (document.getElementById('rightContentAdmin')!=null) {
159                                                 document.getElementById('rightContentAdmin').style.marginLeft = "50px";
160                                                 
161                                         }
162                                         
163                         else if (document.getElementById('rightContentProfile')!=null)
164                                 document.getElementById('rightContentProfile').style.marginLeft = "50px";
165                         
166                                 
167
168
169                         }
170                         };
171                         
172                 $timeout(function() {
173                         detectScrollEvent();
174                 }, 800);
175         }]
176     }
177     
178 });
179 $(window).scroll(function() {
180         if ($('.att-drawer').is(':visible')) {
181                 detectScrollEvent();
182         }
183
184 });
185
186 function detectScrollEvent() {
187         try{
188                 var footerOff = $('#footerContainer').offset().top;
189                 var headOff = $('#headerContainer').offset().top;
190                 var winHeight = $(window).height();
191                 if ((footerOff - headOff) <= winHeight) {
192                         $('.att-drawer').css({
193                                 "height" : footerOff - headOff - 55
194                         });
195                 } else {
196                         $('.att-drawer').css({
197                                 "height" : "94vh"
198                         });
199                 }
200         }catch(err){
201                 console.log(err)
202         }
203 }