(function () { 'use strict'; angular .module('hyperion') .controller('system.SidebarController', ['$scope', '$sessionStorage', '$timeout', 'CONFIG', function($scope, $sessionStorage, $timeout, CONFIG) { $(document).ready(function() { // once #sidebar object is ready to manipulate... $('#sidebar').ready(function() { $timeout(function() { // SHOW CORRECT VERSION [small|large] OF MENU $("ul.menu").css('background', 'none'); // hide logo image $("ul.menu li").hide(); // hide list elements $("ul.menu li").find("span.large").hide(); // hide LARGE MENU elements $("ul.menu li").find("span.small").hide(); // hide SMALL MENU elements if($sessionStorage.currentUser !== undefined) { // check is $sessionStorage has currentUser element (set in authenticationService:Login()) if($sessionStorage.currentUser.smallMenu) { // check smallMenu value (default:false) // if SMALL MENU: $("#sidebar").css('left', -(parseInt($('#sidebar').width(),10)-50)); // move #sidebar left $("ul.menu").css('background', 'url(\'../image/sidebar_logo_small.svg\') no-repeat right bottom'); // show small logo $("ul.menu li").find("span.small").show(); // show SMALL MENU elements } else { // if LARGE MENU: $("ul.menu").css('background', 'url(\'../image/sidebar_logo.svg\') no-repeat center bottom'); // show large logo $("ul.menu li").find("span.large").show(); // show LARGE MENU elements } $("ul.menu li").not('.spinner').show(); // show list elements $("ul.menu").fadeIn(CONFIG.UI_SPEED); // animate show whole menu } else { console.error('currentUser is undefined!'); // SHOW LARGE MENU as DEFAULT $("ul.menu").css('background', 'url(\'../image/sidebar_logo.svg\') no-repeat center bottom'); // show large logo $("ul.menu li").find("span.large").show(); // show LARGE MENU elements $("ul.menu li").not('.spinner').show(); // show list elements $("ul.menu").fadeIn(CONFIG.UI_SPEED); // animate show whole menu } // RESTORE CURRENT SESSION MENU STATE AFTER REFRESH (Ctrl+R/F5) if($sessionStorage.menuActiveElement !== undefined) { if(!isNaN($sessionStorage.menuActiveElement.major)) { $(".menu > li").each(function() { if($(this).index() === $sessionStorage.menuActiveElement.major) { $(this).children('a').children('span').each(function(){ // light up active top level 'simple' element $(this).addClass('active'); }); if($(this).find('span').hasClass('parentclosed')) { // check if it's complex element $(this).find('span.parentclosed').each(function(){ $(this).removeClass('parentclosed').addClass('parentopen').addClass('active'); }); $(this).find('span.parentopen').nextAll("ul.submenu:first").slideDown(CONFIG.UI_SPEED); } } else { $(this).find('span').each(function(){ $(this).removeClass('active'); }); } }) } } else { $("ul.menu").find('li:first a').children('span').each(function(){ // light up active top level 'simple' element $(this).addClass('active'); }); $sessionStorage.menuActiveElement = { major:0, minor:-1 }; } }, 500); }); // return element