3 angular.module('dashboardApp', [
9 'pascalprecht.translate'
11 .config(function($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, $translateProvider) {
15 $locationProvider.html5Mode(true);
16 $httpProvider.interceptors.push('authInterceptor');
18 $translateProvider.useLoaderCache(true).useStaticFilesLoader({
19 prefix: 'assets/langs/locale-',
23 .storagePrefix('twotoc_')
24 .useSanitizeValueStrategy('sanitize')
25 .preferredLanguage('it');
28 .factory('authInterceptor', function($rootScope, $q, $cookies, $injector) {
31 // Add authorization token to headers
32 request: function(config) {
33 config.headers = config.headers || {};
34 if ($cookies.get('token')) {
35 config.headers.Authorization = 'Bearer ' + $cookies.get('token');
40 // Intercept 401s and redirect you to login
41 responseError: function(response) {
42 if (response.status === 401) {
43 (state || (state = $injector.get('$state'))).go('login');
44 // remove any stale tokens
45 $cookies.remove('token');
46 return $q.reject(response);
49 return $q.reject(response);
55 .directive('resizewin', ['$window', function($window) {
56 return function (scope) {
57 var w = angular.element($window);
58 scope.getWindowDimensions = function () {
64 scope.$watch(scope.getWindowDimensions, function (newValue) {
65 scope.windowHeight = newValue.h;
66 scope.windowWidth = newValue.w;
68 scope.style = function (offset) {
70 'height': (newValue.h - offset) + 'px'
71 // 'width': (newValue.w - 100) + 'px'
77 w.bind('resize', function () {
83 .directive('mratio', ['$window', function($window) {
86 link: function(scope, element, attrs) {
88 var w = angular.element($window);
89 scope.getWindowDimensions = function () {
95 scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
96 mRatio(scope, element, attrs);
99 mRatio(scope, element, attrs);
101 function mRatio(scope, element, attrs) {
102 var image = new Image(); // or document.createElement('img')
103 var el_width, el_height, width, height, ratio;
104 el_width = element.width();
105 el_height = element.height();
106 image.onload = function() {
108 height = this.height;
109 ratio = el_width / width;
110 var r_height = height * ratio;
111 if (el_height / height != ratio) {
112 attrs.$set('style', 'height: ' + r_height + 'px');
115 image.src = attrs.src;
121 .run(function($rootScope, $state, Auth) {
122 // Redirect to login if route requires auth and the user is not logged in
123 $rootScope.$on('$stateChangeStart', function(event, next) {
124 if (next.authenticate) {
125 Auth.isLoggedIn(function(loggedIn) {
127 event.preventDefault();