Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / jsp / ebz / ebz_header.jsp
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 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
21 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
22 <%@ page isELIgnored="false"%>
23 <%@ page import="org.openecomp.portalsdk.core.util.SystemProperties"%>
24 <%@ page import="org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiProperties"%>
25 <%@ page import="org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiConstants"%>
26 <%@ page import="org.openecomp.portalsdk.core.domain.MenuData"%>
27 <link rel="stylesheet" type="text/css" href="app/fusion/external/ebz/ebz_header/header.css">
28 <link rel="stylesheet" type="text/css" href="app/fusion/external/ebz/ebz_header/portal_ebz_header.css">
29 <link rel="stylesheet" type="text/css" href="app/fusion/external/ebz/sandbox/styles/style.css" >
30
31 <!-- Icons -->
32 <link rel="stylesheet" type="text/css" href="app/fusion/external/ionicons-2.0.1/css/ionicons.css" />
33 <script src= "app/fusion/external/ebz/angular_js/angular.js"></script> 
34 <script src= "app/fusion/external/ebz/angular_js/angular-route.min.js"></script>
35 <script src= "app/fusion/external/ebz/angular_js/angular-sanitize.js"></script>
36 <script src= "app/fusion/external/ebz/angular_js/angular-cookies.js"></script>
37 <script src= "app/fusion/external/ebz/angular_js/app.js"></script>
38 <script src= "app/fusion/external/ebz/angular_js/gestures.js"></script>
39 <script src="static/js/jquery-1.10.2.js"></script>
40 <script src="app/fusion/scripts/modalService.js"></script>
41 <script src="static/js/jquery.mask.min.js" type="text/javascript"></script>
42 <script src="static/js/jquery-ui.js" type="text/javascript"></script>
43 <script src="app/fusion/external/ebz/sandbox/att-abs-tpls.js" type="text/javascript"></script>
44 <script src="static/fusion/js/att_angular_gridster/ui-gridster-tpls.js"></script>
45 <script src="static/fusion/js/att_angular_gridster/angular-gridster.js"></script>
46 <script src= "app/fusion/external/ebz/angular_js/checklist-model.js"></script>
47 <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>
48 <script src="app/fusion/external/angular-ui/ui-bootstrap-tpls-1.1.2.min.js"></script>
49 <script src="app/fusion/scripts/services/userInfoService.js"></script>
50 <script src="app/fusion/scripts/services/leftMenuService.js"></script>
51
52
53 <jsp:include page="/WEB-INF/fusion/jsp/ebz/loginSnippet.html" ></jsp:include> 
54
55 <c:set var="UserName"   value="<%= session.getAttribute(\"fullName\")%>" />
56 <c:set var="UserFirstName"      value="<%= session.getAttribute(\"first_name\")%>" />
57
58 <% 
59         String contactUsLink = SystemProperties.getProperty(SystemProperties.CONTACT_US_LINK);
60         String redirectUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);
61         String portalUrl = redirectUrl.substring(0, redirectUrl.lastIndexOf('/')) + "/processSingleSignOn";
62         String getAccessLink = redirectUrl.substring(0, redirectUrl.lastIndexOf('/')) + "/get_access";  
63 %>
64 <c:set var="returnPortalUrl" value="<%=portalUrl%>" />
65 <c:set var="contactUsLink" value="<%=contactUsLink%>" />
66 <c:set var="getAccessLink" value="<%=getAccessLink%>" />
67 <style>
68 .att-drawer{
69         z-index:997 !important;
70 }
71
72 .secondaryMenuContainer{
73         z-index:1000;
74 }
75 .megamenu-tabs .megamenu__item {
76         padding: 0 0;
77 }
78 .megamenu-tabs .megamenu__item span {
79     font-size: 18px;
80 }
81
82 .submenu-tabs {
83    line-height:50px;
84 }
85 .submenu-tabs .sub__menu{
86         top:54px;
87 }
88
89 .top-megamenu .megamenu-tabs ul{
90         width:98%;
91         list-style: none;
92 }
93
94 </style>
95 <%@include  file="/WEB-INF/fusion/jsp/ebz/loginSnippet.html" %>
96
97 <div style="position: relative; z-index: 999;">
98         <div ng-controller="headerController">
99         
100                  <div class="headerContainer" id="headerContainer" ng-cloak  ng-show="{{showHeader}}">
101                         <div id="megaMenuContainer" class="megaMenuContainer" style="margin-top: 0; overflow: visible;">
102                                 <div>
103                                         <!--for mega Menu-->
104                                         <!-- Mega Menu parent-tab directive with three models menu-items, active-sub-menu, active-menu -->
105                                         <div id="topMenu" class="top-megamenu" ng-mouseleave="activeClickSubMenu.x.active=false; activeClickMenu.x.active=false">
106                                                 <div style="float:left;width:100%;"parent-tab menu-items="megaMenuDataObject" active-sub-menu='activeClickSubMenu.x' active-menu='activeClickMenu.x'>
107                                         <div parentmenu-tabs mega-menu="true" menu-items="megaMenuDataObject" style="height:55px;">
108                                                                 <div style="float:left">
109                                                                         <li class="megamenu__item" style="line-height:55px;" onclick="returnToPortal()">
110                                                                                 
111 <!--                                                                                    <a id='returnPortal' class="primaryMenuOptionLink" style="font-weight: 400 !important; font-family: Arial !important; font-size: 18px;">ECOMP</a>
112  -->                                                                            <strong style="font-weight: 400 !important; font-family: Arial !important; font-size: 18px;" id='returnPortal' >ECOMP Portal</strong>
113                                                                         </li>                                                                           
114                                                                         <div menu-tabs mega-menu="true" tab-name="item.text" menu-item="item" active-menu="activeClickMenu.x" 
115                                                                         ng-repeat="item in megaMenuDataObject" style="font-size: 18px;" ng-mousedown="loadFavorites()" >
116                                                         <div parentmenu-tabs sub-menu="true" ng-show="activeClickMenu.x.active && item.active" menu-items="activeClickMenu.x.children">
117                                                         <!-- Second level menu -->
118                                                                         <div>
119                                                                                 <div menu-tabs sub-menu="true" tab-name="subItem.text" 
120                                                                                         tab-url="subItem.url"  menu-item="subItem" 
121                                                                                         ng-repeat="subItem in activeClickMenu.x.children | orderBy : 'column'" active-menu="activeClickSubMenu.x" 
122                                                                                         sub-item-active="{{subItem.active}}" style="float:left;" aria-label="{{subItem.text}}"
123                                                  ng-mouseenter="submenuLevelAction(subItem.text,subItem.column)"
124                                                  ng-mouseleave="submenuLevelAction(subItem.text,subItem.column)"
125                                                 ng-click="submenuLevelAction(subItem.text,subItem.column)"  >
126                                                 <i ng-if="subItem.text=='Favorites'" id="favorite-star"
127                                                    class="icon-star favorites-icon-active">
128                                                 </i>
129                                                                                 </div>
130                                                                                                 
131                                                         <div class="sub__menu" ng-mouseleave="activeClickSubMenu.x.active=false" >
132                                                                 <ul ng-show="activeClickSubMenu.x.active"  role="menubar" class="columns">
133                                        <!-- Third level menu -->                                                                                
134                                                                     <div menu-tabs menu-item="subItem" 
135                                                                     class="columns-div"
136                                                                     ng-repeat="subItem in activeClickSubMenu.x.children | orderBy : 'column'" 
137                                                                     ng-show="activeClickSubMenu.x.active">
138
139                                                             <i id="favorite-selector-third-level"
140                                                                ng-show="isUrlFavorite(subItem.menuId)==false"
141                                                                class="icon-star favorites-icon-inactive"
142                                                                ng-if="subItem.url.length > 1">
143                                                             </i>                                                                            
144                                                             <i id="favorite-selector-third-level"
145                                                                ng-show="isUrlFavorite(subItem.menuId)"
146                                                                class="icon-star favorites-icon-active"
147                                                                ng-if="subItem.url.length > 1">
148                                                             </i>                                                                            
149                                                                                                                 <span class="title" aria-label="{{subItem.text}}" 
150                                                                                                                 ng-click="goToUrl(subItem)">{{subItem.text}}</span>
151                                                         <!-- Fourth level menus -->     
152                                                                         <div att-links-list="">
153                                                             <i id="favorite-selector-fourth-level"
154                                                                class="icon-star favorites-icon-inactive"
155                                                                ng-show="isUrlFavorite(tabValue.menuId)==false"
156                                                                ng-if="tabValue.url.length > 1">
157
158                                                             </i>
159                                                             <i id="favorite-selector-fourth-level"
160                                                                class="icon-star favorites-icon-active"
161                                                                ng-show="isUrlFavorite(tabValue.menuId)"
162                                                                ng-if="tabValue.url.length > 1">
163
164                                                             </i>
165                                                                             <span role="menuitem" att-links-list-item="" 
166                                                                             ng-repeat="tabValue in subItem.children" 
167                                                                             ng-click="goToUrl(tabValue)" 
168                                                                             att-accessibility-click="13,32" 
169                                                                             ng-class="{'disabled': tabValue.disabled}">{{tabValue.text}}</span>
170                                                                         </div>
171                                                                         <hr ng-show="!$last"/>
172                                                                         
173                                                                     </div>
174                                                                  </ul>
175                                    <!-- Favorites level menu -->
176                                                                                                 <div class="favorites-window" ng-show='favoritesWindow' ng-mouseleave="hideFavoritesWindow()">
177                                                                                                         <div id="favorites-menu-items" ng-show="showFavorites">
178                                                                                                                 <div ng-repeat="subItem in favoritesMenuItems" att-links-list="" style='display: inline'>
179                                                                                                                                 <i id="favorite-selector-favorites-list" class="icon-star favorites-icon-active">
180                                                                                                                                 </i>
181                                                                                                                                 <a id="favorites-list" aria-label="{{subItem.text}}"
182                                                                                                                                    ng-click="goToUrl(subItem)" 
183                                                                                                                                    style="margin-left: 3px; margin-right: 20px; text-decoration: none;  color: #666666;">
184                                                                                                                                    {{subItem.text}}
185                                                                                                                                 </a>
186                                                                                                                 </div>
187                                                                                                                 <div>
188                                                                                                                         <br>
189                                                                                                                         <p style='font-weight: 400; font-family: Arial !important;
190                                                                                                                         font-size: 18px; text-align: center; background-color: lightgray;
191                                                                                                                         width: 400px; margin-left: 25%; margin-right: 25%;'>
192                                                                                                                                 Manage favorites on ECOMP Portal.
193                                                                                                                         </p>
194                                                                                                                 </div>
195                                                                                                         </div>
196                                                                   <!-- Favorites when empty -->
197                                                                                                                 <div id="favorites-empty" ng-show='favoritesWindow' ng-show="emptyFavorites">
198                                                                         <div id="favorites-empty" ng-show="emptyFavorites" class="favorites-window-empty">
199                                                                             <div>
200                                                                                 <img src="app/fusion/external/ebz/images/no_favorites_star.png">
201                                                                                 <p class='favoritesLargeText'>No Favorites</p>
202                                                                                                                                         <p class='favoritesNormalText'>Manage favorites on ECOMP Portal.</p>
203                                                                             </div>
204                                                                         </div>
205                                                                                                                 </div>
206                                                                                                         </div>
207                                                                         
208                                                                 </div>
209                                                             </div>
210                                                         </div> 
211                                                     </div >
212                                                     <li class="megamenu__item" style="line-height:55px;" ng-if="loadMenufail">
213                                                                                 <strong style="font-weight: 400 !important; font-family: Arial !important; font-size: 18px;" >Unable to load menus</strong>
214                                                                         </li>
215 <!--                                                                            <li class="megamenu__item" style="width: 20%;">&nbsp;</li>
216  -->                                                                    </div>
217                                                                 <!--  Login Snippet-->
218                                                                 <div  style="float:right">
219                                                                         <li id="bcLoginSnippet" class="megamenu__item" style="width: 140px;" >
220                                                                                 <div popover="loginSnippet.html"  aria-label="Login Snippet"    referby="loginSnippet" att-accessibility-click="13,32" popover-style="\" popover-placement="below" style="width: 200px;">
221                                                                                         <div class="ion-android-person login-snippet-icon" style="display:inline-block"></div>
222                                                                                         <div class="login-snippet-text" style="display: inline-block; font-size:12px; margin-left:5px;overflow: hidden; max-height: 31px;   max-width:120px; padding-top: 0px; margin-top: 0px; white-space: nowrap;" ng-bind="userProfile.firstName"></div>
223                                                                                 </div>
224                                                                         </li>
225                                                                         <li class="megamenu__item" style="width:120px;">&nbsp;</li>
226                                                                 </div>
227                                                                 
228                                                         </div>          
229                                                 </div>
230                                                 <div style="clear: both"></div>
231                                         </div>
232                                         </div>
233                                 </div>
234                         </div>
235
236                 <div style="position: relative; color: black; top: 70px;">
237                         <div ng-cloak>          
238                                 <span ng-style="adjustHLeftMenu('burgerIcon')" style="z-index:998; position:fixed; left:0%; font-size:35px; margin-left:10px;text-decoration:none;">
239                                         <a ng-click="toggleDrawer();isOpen = !isOpen" href="javascript:void(0);" class="arrow-icon-left" >
240                                         <span class="ion-navicon-round"></span></a>     
241                                         <span ng-init="isOpen = true" ng-show="isOpen" style="font-size:16px; position:relative; top:-8px; left:-15px;">&nbsp&nbsp&nbsp {{app_name}}</span>
242                                 </span>
243                                 <div att-drawer drawer-slide="left" drawer-custom-top="{{drawer_custom_top}}px" drawer-size="200px" drawer-open="drawerOpen" drawer-custom-height="100%" >
244                                     <div ng-style="adjustHLeftMenu('leftMenu')">
245                                             <div class="attDrawer" style="margin-top:{{drawer_margin_top}}px;">   
246                                                 <div style="margin-left:10px; margin-right:10px;">
247                                                         <accordion close-others="true" css="att-accordion--no-box">
248                                                     <accordion-group ng-repeat="parent in menuItems" heading="{{parent.parentLabel}}" child="{{parent.parentAction}}" parent-link="{{parent.parentAction}}" image-source="{{parent.parentImageSrc}}" child-length="{{parent.childItemList.length}}" is-open="parent.open">
249                                                         <div ng-repeat="subMenu in parent.childItemList" style="font-size:12px; margin-left:10px;">
250                                                                 <a href="{{subMenu.action}}" style="font-size:12px; color:#666666;" >{{subMenu.label}}</a>
251                                                         </div>
252                                                     </accordion-group>
253                                                 </accordion>
254                                                         </div>                                          
255                                             </div>
256                                     </div>
257                                 </div>
258                         </div>          
259                 </div>
260         </div>
261 </div>
262 <script>    
263         function returnToPortal(){
264                 window.location.href = "<c:out value='${returnPortalUrl}'/>";
265         }
266         detectScrollEvent = function() {
267                 var footerOff = $('#footerContainer').offset().top;
268                 var headOff = $('#headerContainer').offset().top;
269                 var winHeight = $(window).height();
270                 if ((footerOff - headOff) <= winHeight) {
271                         $('.att-drawer').css({
272                                 "height" : footerOff - headOff - 55
273                         });
274                 } else {
275                         $('.att-drawer').css({
276                                 "height" : "94vh"
277                         });
278                 }
279         }
280         $(window).scroll(function() {
281                 if ($('.att-drawer').is(':visible')) {
282                         detectScrollEvent();
283                 }
284         });
285         app.controller("headerController", function($scope, $timeout, $log, $http, UserInfoService, $window, $cookies,LeftMenuService) {
286                 $log.debug('HeaderController started');
287                 $scope.jsonMenuData = [];
288                 $scope.loadMenufail=false;
289                 $scope.app_name = "";
290                 $scope.app_name_full = "";
291                 $scope.megaMenuDataObject =[];
292                 $scope.activeClickSubMenu = {
293                         x: ''
294         };
295         $scope.activeClickMenu = {
296                         x: ''
297         };
298                 $scope.favoritesMenuItems = [];
299         $scope.favoriteItemsCount = 0;
300         $scope.showFavorites = false;
301         $scope.emptyFavorites = false;
302         $scope.favoritesWindow = false;
303         $scope.userProfile={
304                         firstName:'',
305                         lastName:'',
306                         fullName:'',
307                         email:''
308         }
309         /*Put user info into fields*/
310         $scope.inputUserInfo = function(userInfo){
311                 if (typeof(userInfo) != "undefined" && userInfo!=null && userInfo!=''){
312                         if (typeof(userInfo.USER_FIRST_NAME) != "undefined" && userInfo.USER_FIRST_NAME!=null && userInfo.USER_FIRST_NAME!='')
313                                 $scope.userProfile.firstName = userInfo.USER_FIRST_NAME;
314                         if (typeof(userInfo.USER_LAST_NAME) != "undefined" && userInfo.USER_LAST_NAME!=null && userInfo.USER_LAST_NAME!='')
315                                 $scope.userProfile.lastName = userInfo.USER_LAST_NAME;
316                         if (typeof(userInfo.USER_EMAIL) != "undefined" && userInfo.USER_EMAIL!=null && userInfo.USER_EMAIL!='')                         
317                                 $scope.userProfile.email = userInfo.USER_EMAIL;
318                 }               
319         }
320          /*getting user info from session*/
321         $scope.getUserNameFromSession = function(){
322                 UserInfoService.getFunctionalMenuStaticDetailSession()
323                 .then(function (res) {
324                                 $scope.userProfile.firstName = res.firstName;
325                                 $scope.redirectUrl = res.portalUrl;
326                 });
327         }
328         $scope.getTopMenuStaticInfo=function() {
329                 var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext();
330                 promise.then(
331                                 function(res) {                                         
332                                         if(res==null || res==''){
333                                                 $log.info('failed getting static User information');    
334                                                 $scope.getUserNameFromSession();
335                                         }else{
336                                                 $log.info('Received static User information');
337                                                 var resData = res;                                              
338                                                 $scope.inputUserInfo(resData);                                  
339                                                 $scope.userProfile.fullName = $scope.userProfile.firstName+ ' '+ $scope.userProfile.lastName;                                   
340                                         }
341                                 },
342                                 function(err) {
343                                         $log.info('failed getting static User information');                                    
344                                 }
345                 );
346                 }
347                         
348                 var unflatten = function( array, parent, tree ){
349                         tree = typeof tree !== 'undefined' ? tree : [];
350                         parent = typeof parent !== 'undefined' ? parent : { menuId: null };
351                         var children = _.filter( array, function(child){ return child.parentMenuId == parent.menuId; });
352                 
353                         if( !_.isEmpty( children )  ){
354                                 if( parent.menuId === null ){
355                                                 tree = children;
356                                 }else{
357                                         parent['children'] = children
358                                 }
359                                 _.each( children, function( child ){ unflatten( array, child ) } );
360                         }
361
362                         return tree;
363                 }
364                 
365                 var menuStructureConvert = function(menuItems) {
366                         var megaMenuDataObjectTemp = [
367                                          {
368                                                  text: "ECOMP",
369                                                  children:menuItems
370                                          },
371                                          {
372                                                  text: "Help",
373                                                  children: [{
374                                                          text:"Contact Us",
375                                                          url:"<c:out value='${contactUsLink}'/>"
376                                                  },
377                                                  {
378                                                          text:"Get Access",
379                                                          url:"<c:out value='${getAccessLink}'/>"
380                                                  }]
381                                          }
382                                          ];
383                         return megaMenuDataObjectTemp;
384                 }; 
385                 
386                 
387                 /*Left Menu*/
388                 LeftMenuService.getAppName().then(function(response){
389                         var j = response; 
390                         try{
391                                 if(j && j !== "null" && j!== "undefined"){
392                                         console.log("app name is " + $scope.app_name);
393                                         $scope.app_name_full = j.data;
394                                         var processed_app_name = j.data;
395                                         var n = processed_app_name.length;
396                                         if (n > 15) {
397                                                 n = 15;
398                                         }
399                                         $scope.app_name = processed_app_name.substr(0, n);
400                                 }else{
401                                         throw "Get app_name respsone is not an object/is empty"; 
402                                 }  
403                         }catch (e) {
404                                 console.log("error happened while trying to get app name "+e);
405                                 return;
406                 }              
407                 },function(error){
408                         console.log("error happened while calling getAppName "+error);
409                 });
410                 
411             $scope.getTopMenuStaticInfo();      
412         $scope.getMenu=function() {
413                 
414                  $http({
415                         method: "GET",
416                         url: 'get_functional_menu',
417 // TIMEOUT USED FOR LOCAL TESTING ONLY                          
418 //                      timeout: 100
419                  }).success(function (response) {
420                         if(response == '101: Timeout') {
421                                 $log.error('Timeout attempting to get_functional_menu');
422                         // TIMEOUT USED FOR LOCAL TESTING ONLY                          
423 //                              $scope.createErrorMenu();
424                                 $scope.megaMenuDataObject = menuStructureConvert('');
425                         }else {
426                                 $log.debug('get_functional_menu success: ' + response);                                                         
427                                 if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){
428 // createErrorMenu() USED FOR LOCAL TESTING ONLY
429 //                                      $scope.createErrorMenu();
430                                         $scope.megaMenuDataObject = menuStructureConvert('');
431                                 //      $scope.loadMenufail=true;
432                                 }else{
433                                         $scope.jsonMenuData = unflatten( response );
434                                         $scope.megaMenuDataObject = menuStructureConvert($scope.jsonMenuData);
435                                 }
436                         }
437                 }).error(function (response){
438 // createErrorMenu() USED FOR LOCAL TESTING ONLY                                
439 //                              $scope.createErrorMenu();
440
441                                 //$scope.loadMenufail=true;
442                                 $scope.megaMenuDataObject = menuStructureConvert('');
443                         $log.debug('REST API failed get_functional_menu...'+ response);
444                   });
445                 }
446         $scope.adjustHLeftMenu = function (type){
447                 $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header);
448                 
449                 if($scope.showHeader == true) {
450                         $scope.drawer_margin_top = 60;
451                         $scope.drawer_custom_top = 54;
452                         $scope.toggle_drawer_top = 55;
453                 }
454                 else  {
455                         
456                         $scope.drawer_margin_top = 50;
457                         $scope.drawer_custom_top = 0;
458                         $scope.toggle_drawer_top = 10;
459                 }
460                 if(type=='burgerIcon'){
461                         return { "top": $scope.toggle_drawer_top+"px"};
462                 }else if(type=='leftMenu'){
463                         return { "margin-top": $scope.drawer_margin_top+"px"};
464                 }else
465                         return;
466         }
467         $scope.adjustHeader=function() {
468                 $scope.showHeader = ($cookies.show_app_header == undefined ? true : $cookies.show_app_header);
469                 
470                 if($scope.showHeader == true) {
471                         $scope.drawer_margin_top = 50;
472                         $scope.drawer_custom_top = 54;
473                         $scope.toggle_drawer_top = 55;
474                 }
475                 else  {
476                         
477                         $scope.drawer_margin_top = 40;
478                         $scope.drawer_custom_top = 0;
479                         $scope.toggle_drawer_top = 10;
480                 }
481                 
482                 
483         }
484         
485         
486                 //$scope.getMenu();
487                 $scope.adjustHeader();
488                 
489
490                 /* **************************************************************************/
491                 /* Logic for the favorite menus is here */
492
493             $scope.loadFavorites = function () {
494                 $log.debug('loadFavorites has happened.');
495                 if ($scope.favoritesMenuItems == '') {
496                     $scope.generateFavoriteItems();
497                     $log.debug('loadFavorites is calling generateFavoriteItems()');
498                 } else {
499                     $log.debug('loadFavorites is NOT calling generateFavoriteItems()');
500                 }
501             }
502             
503             $scope.goToUrl = function (item) {
504                 $log.info("goToUrl called")
505                 $log.info(item);
506
507                 var url = item.url;
508                 var restrictedApp = item.restrictedApp;
509                 $log.debug('Restricted app status is: ' + restrictedApp);
510                 if (!url) {
511                     $log.info('No url found for this application, doing nothing..');
512                     return;
513                 }
514                 if (restrictedApp) {
515                     $window.open(url, '_blank');
516                 } else {
517                     $window.open(url, '_self');
518                 }
519
520             }
521             
522             $scope.submenuLevelAction = function(index, column) {
523                 if ($scope.favoritesMenuItems == '') {
524                     $scope.generateFavoriteItems();
525                     $log.debug('submenuLevelAction is calling generateFavoriteItems()');
526                 }
527                 $log.debug('item hovered/clicked: ' + index + '; column = ' + column);
528                 if (column == 2) {  // 2 is Design
529                     $scope.favoritesWindow = false;
530                     $scope.showFavorites = false;
531                     $scope.emptyFavorites = false;
532                 }
533                 if (index=='Favorites' && $scope.favoriteItemsCount != 0) {
534                     $log.debug('Showing Favorites window');
535                     $scope.favoritesWindow = true;
536                     $scope.showFavorites = true;
537                     $scope.emptyFavorites = false;
538                 }
539                 if (index=='Favorites' && $scope.favoriteItemsCount == 0) {
540                     $log.debug('Hiding Favorites window in favor of No Favorites Window');
541                     $scope.favoritesWindow = true;
542                     $scope.showFavorites = false;
543                     $scope.emptyFavorites = true;
544                 }
545                 if (column > 2) {
546                     $scope.favoritesWindow = false;
547                     $scope.showFavorites = false;
548                     $scope.emptyFavorites = false;
549                 }
550             };
551             
552             $scope.hideFavoritesWindow = function() {
553                 $log.debug('$scope.hideFavoritesWindow has been called');
554                 $scope.showFavorites = false;
555                 $scope.emptyFavorites = false;
556             }
557             
558             $scope.isUrlFavorite = function (menuId) {
559 //                 $log.debug('array objects in menu favorites = ' + $scope.favoriteItemsCount + '; menuId=' + menuId);
560                 var jsonMenu =  JSON.stringify($scope.favoritesMenuItems);
561                 var isMenuFavorite =  jsonMenu.indexOf('menuId\":' + menuId);
562                 if (isMenuFavorite==-1) {
563                     return false;
564                 } else {
565                     return true;
566                 }
567
568             }
569                             
570             $scope.generateFavoriteItems  = function() {
571                 $http({
572                         method: "GET",
573                         url: 'get_favorites',
574                 // TIMEOUT USED FOR LOCAL TESTING ONLY                          
575 //                                              timeout: 100
576                             }).success(function (response) {
577                                                 if (response == '101: Timeout') {
578                                                 $log.error('Timeout attempting to get_favorites_menu');
579                                         } else {
580                                                 if(typeof response != 'undefined' && response.length!=0 && typeof response[0] != 'undefined' && typeof response[0].error!="undefined"){
581                                                     $log.error('REST API failed get_favorites' + response);
582                                                         }else{
583                                                                 $log.debug('get_favorites = ' + JSON.stringify(response));
584                                                                 $scope.favoritesMenuItems = response;
585                                         $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length;
586                                         $log.info('number of favorite menus: ' + $scope.favoriteItemsCount);
587                                 }
588                                                 }
589                                         }).error(function (response){
590                                             $log.error('REST API failed get_favorites' + response);
591
592                                         });
593                 }
594                             
595                                 $scope.createFavoriteErrorMenu=function() {
596                                 $scope.favoritesMenuItems = [
597
598                                                                 ];
599                                 $scope.favoriteItemsCount = Object.keys($scope.favoritesMenuItems).length;
600                                 $log.info('number of favorite menus: ' + $scope.favoriteItemsCount);
601                                 }
602                             
603                 /* end of Favorite Menu code */
604                 /* **************************************************************************/
605
606                 
607                 /* **************************************************************************/
608                 // THIS IS USED FOR LOCAL TESTING ONLY
609                 /* **************************************************************************/
610
611                         $scope.createErrorMenu=function() {
612                 $scope.jsonMenuData = [
613                                    {
614                                     "menuId": 1,
615                                     "column": 2,
616                                     "text": "Design",
617                                     "parentMenuId": null,
618                                     "url": ""
619                                   },
620                                   {
621                                     "menuId": 2,
622                                     "column": 3,
623                                     "text": "Infrastructure Ordering",
624                                     "parentMenuId": null,
625                                     "url": ""
626                                   },
627                                   {
628                                     "menuId": 3,
629                                     "column": 4,
630                                     "text": "Service Creation",
631                                     "parentMenuId": null,
632                                     "url": ""
633                                   },
634                                   {
635                                     "menuId": 4,
636                                     "column": 5,
637                                     "text": "Service Mgmt",
638                                     "parentMenuId": null,
639                                     "url": ""
640                                   },
641                                   {
642                                     "menuId": 90,
643                                     "column": 1,
644                                     "text": "Google",
645                                     "parentMenuId": 1,
646                                     "url": "http://google.com"
647                                   },
648                                   {
649                                     "menuId": 91,
650                                     "column": 1,
651                                     "text": "Mike Little's Coffee Cup",
652                                     "parentMenuId": 2,
653                                     "url": "http://coffee.com"
654                                   },
655                                   {
656                                     "menuId": 92,
657                                     "column": 2,
658                                     "text": "Andy and his Astrophotgraphy",
659                                     "parentMenuId": 3,
660                                     "url": "http://nightskypix.com"
661                                   },
662                                   {
663                                     "menuId": 93,
664                                     "column": 1,
665                                     "text": "JSONLint",
666                                     "parentMenuId": 4,
667                                     "url": "http://jsonlint.com"
668                                   },
669                                   {
670                                     "menuId": 94,
671                                     "column": 2,
672                                     "text": "HROneStop",
673                                     "parentMenuId": 4,
674                                     "url": ""
675                                   },
676                                   {
677                                     "menuId": 95,
678                                     "column": 2,
679                                     "text": "4th Level App4a R16",
680                                     "parentMenuId": 4,
681                                     "url": ""
682                                   },
683                                   {
684                                     "menuId": 96,
685                                     "column": 3,
686                                     "text": "3rd Level App1c R200",
687                                     "parentMenuId": 4,
688                                     "url": "http://app1c.com"
689                                   },
690                                   {
691                                     "menuId": 97,
692                                     "column": 1,
693                                     "text": "3rd Level App4b R16",
694                                     "parentMenuId": 5,
695                                     "url": "http://app4b.com"
696                                   },
697                                   {
698                                     "menuId": 98,
699                                     "column": 2,
700                                     "text": "3rd Level App2b R16",
701                                     "parentMenuId": 5,
702                                     "url": "http://app2b.com"
703                                   },
704                                   {
705                                     "menuId": 99,
706                                     "column": 1,
707                                     "text": "Favorites",
708                                     "parentMenuId": null,
709                                     "url": ""
710                                   }
711                                 ];
712                         $scope.jsonMenuData = unflatten( $scope.jsonMenuData );
713                         $scope.megaMenuDataObject = menuStructureConvert($scope.jsonMenuData);
714 //                      $log.debug(JSON.stringify($scope.jsonMenuData));
715         }
716                 var childItemList="";
717                 var parentList = "";
718                 try{
719                         childItemList = ${menu.childItemList};
720                         parentList = ${menu.parentList};
721                 }catch(err){
722                         console.log("error while getting left menu");
723                 }
724                 
725                 var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1];
726                 
727                 $scope.menuItems = [];
728                 for (var i = 0; i < parentList.length; i++) {
729                         $scope.openCurrentMenu = false;
730                  if(pageUrl==parentList[i].action)
731                                 $scope.openCurrentMenu = true;
732                         $scope.childItemList = childItemList[i];
733                         for(chIndex in  $scope.childItemList){
734                                 if($scope.childItemList.length>0)
735                                         if($scope.childItemList[chIndex].action!=null){
736                                                 if($scope.childItemList[chIndex].action==pageUrl)
737                                                         $scope.openCurrentMenu = true;
738                                         }
739                         }
740                         $scope.item = {
741                                 parentLabel : parentList[i].label,
742                                 parentAction : parentList[i].action,
743                                 parentImageSrc : parentList[i].imageSrc,
744                                 open:$scope.openCurrentMenu,
745                                 childItemList : $scope.childItemList
746                         }
747                         $scope.menuItems.push($scope.item);
748                 }
749                 $scope.arrowShow = true;
750                 $scope.drawerOpen = false;
751                 $scope.subMenuContent = false;
752                 $scope.toggleSubMenu = function() {
753                         $scope.subMenuContent = !$scope.subMenuContent;
754                 };
755
756                 var drawerOpen = 'open';
757                 if (drawerOpen == 'open') {
758                         $scope.drawerOpen = true;
759                         $scope.arrowShow = true;
760                 } else {
761                         $scope.arrowShow = false;
762                 }
763                 $scope.arrowShow = true;
764                 $scope.drawerOpen = false;
765                 $scope.toggleDrawer = function() {
766                         $scope.drawerOpen = !($scope.drawerOpen);
767                         if ($scope.drawerOpen) {
768                                 $scope.arrowShow = true;                                
769                                 if (document.getElementById('mContent')!=null)
770                                         document.getElementById('mContent').style.marginLeft = "210px";                         
771                         } else {
772                                 $scope.arrowShow = false;
773                                 if (document.getElementById('mContent')!=null)
774                                         document.getElementById('mContent').style.marginLeft = "50px";
775                         }
776                 };
777                 //var drawerOpen = getCookie('drawerOpen');
778                 if (drawerOpen == 'open') {
779                         $scope.drawerOpen = true;
780                         $scope.arrowShow = true;
781                 } else {
782                         $scope.arrowShow = false;
783                 }
784                 $timeout(function() {
785                         detectScrollEvent();
786                 }, 800);
787                 
788         });
789         
790         app.filter("ellipsis", function(){
791             return function(text, length){
792                 if (text) {
793                     var ellipsis = text.length > length ? "..." : "";
794                     return text.slice(0, length) + ellipsis;
795                 };
796                 return text;        
797             }
798         });
799 </script>