text: 'use strict';
  
  /* Controllers */
  
  angular.module('app')
    .controller('AppCtrl', ['$scope', '$translate', '$localStorage', '$window', 
      function(              $scope,   $translate,   $localStorage,   $window ) {
        // add 'ie' classes to html
        var isIE = !!navigator.userAgent.match(/MSIE/i);
        isIE && angular.element($window.document.body).addClass('ie');
        isSmartDevice( $window ) && angular.element($window.document.body).addClass('smart');
  
        // config
        $scope.app = {
          name: 'X-Admin',
          version: '1.0',        
          settings: {
            headerFixed: true,
            asideFixed: false,
            asideFolded: false,
            asideDock: false,
            container: false
          }
        }
  
        if ( angular.isDefined($localStorage.settings) ) {
          $scope.app.settings = $localStorage.settings;
        } else {
          $localStorage.settings = $scope.app.settings;
        }
        $scope.$watch('app.settings', function(){
          if( $scope.app.settings.asideDock  &&  $scope.app.settings.asideFixed ){
            $scope.app.settings.headerFixed = true;
          }
          $localStorage.settings = $scope.app.settings;
        }, true);
  
        $scope.lang = { isopen: false };
        $scope.langs = {en:'English', zh_CN:'简体中文'};
        $scope.selectLang = $scope.langs[$translate.proposedLanguage()] || "English";
        $scope.setLang = function(langKey, $event) {
          $scope.selectLang = $scope.langs[langKey];
          $translate.use(langKey);
          $scope.lang.isopen = !$scope.lang.isopen;
        };
  
        function isSmartDevice( $window )
        {
            // Adapted from http://www.detectmobilebrowsers.com
            var ua = $window['navigator']['userAgent'] || $window['navigator']['vendor'] || $window['opera'];
            // Checks for iOs, Android, Blackberry, Opera Mini, and Windows mobile devices
            return (/iPhone|iPod|iPad|Silk|Android|BlackBerry|Opera Mini|IEMobile/).test(ua);
        }
  
    }]);