(function () {
    angular.module('app', ['ionic', 'app.controllers', 'app.services', 'app.filters', 'app.directives'])
   .config(["$ionicConfigProvider", function ($ionicConfigProvider) {
       //ionic全局配置
       $ionicConfigProvider.views.maxCache(10);
       $ionicConfigProvider.platform.android.tabs.position('bottom');
       $ionicConfigProvider.platform.android.navBar.alignTitle("center");
       $ionicConfigProvider.backButton.text('后退').icon('ion-chevron-left');
       $ionicConfigProvider.form.checkbox("circle");
       $ionicConfigProvider.templates.maxPrefetch(0);
   }])
 .config(["$httpProvider", function ($httpProvider) {
     //http配置
     $httpProvider.defaults.headers.common['Authorization'] = 'Bearer ' + window.localStorage['token'];
 }])
.run(["$ionicPlatform", "$location", "msg", "$rootScope", "$timeout", "$ionicHistory", "userService","$state",
    function ($ionicPlatform, $location, msg, $rootScope, $timeout, $ionicHistory, userService, $state) {
    $ionicPlatform.registerBackButtonAction(function (e) {
        if ($location.path().indexOf("wl/") != -1) {
            if ($rootScope.backButtonPressedOnceToExit) {
                ionic.Platform.exitApp();
                $rootScope.$destroy()
            } else {
                $rootScope.backButtonPressedOnceToExit = true;
                msg.text("再按一次退出系统",true);
                $timeout(function () {
                    $rootScope.backButtonPressedOnceToExit = false
                }, 3000)
            }
        } else if ($ionicHistory.backView()) {
            $ionicHistory.goBack()
        }
        $ionicPlatform.preventDefault();
        $ionicPlatform.stopPropagation();
        return false
    }, 101);
    $ionicPlatform.ready(function () {
        if (window.cordova && cordova.platformId === 'ios' && window.cordova.plugins && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);
        }
        if (window.StatusBar) {
            StatusBar.styleDefault();
        }
        if (!userService.isLogin()) {
            $state.go('login');
        }
    });
}]);
 angular.module("app.controllers", []);
 angular.module("app.services", []);
 angular.module("app.filters", []);
 angular.module("app.directives", []);
})();
