walnut_launchpad.html/js/app.js

140 lines
3.3 KiB
JavaScript

var app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule']);
var redirected = false;
var redirectedURL;
var urlArray = [];
app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){
localStorageServiceProvider.setPrefix('launchpad').setStorageType('sessionStorage');
$urlRouterProvider.otherwise('/splash-page');
$stateProvider
.state('splash-page', {
data: { requiresLogin: false },
url: '/splash-page',
templateUrl: '/templates/splash-page.html',
})
.state('app',{
data: { requiresLogin: true },
url: '/',
views: {
'header': {
templateUrl: '/templates/partials/header.html',
controller: 'HomeController',
controllerAs: 'vm'
},
'menu': {
templateUrl: '/templates/partials/menu.html'
},
'content': {
templateUrl: '/templates/home.html'
}
}
})
.state('app.home', {
url: 'home',
views: {
'content@': {
templateUrl: 'templates/home.html',
controller: 'HomeController',
controllerAs: 'vm'
}
}
})
.state('app.bolt', {
url: 'bolt',
views: {
'content@': {
templateUrl: 'templates/bolt.html',
controller: 'BoltController',
controllerAs: 'vm'
}
}
})
.state('app.files', {
url: 'files',
views: {
'content@': {
templateUrl: 'templates/files.html',
controller: 'FilesController'
}
}
})
.state('app.contacts', {
url: 'contacts',
views: {
'content@': {
templateUrl: 'templates/contacts.html',
controller: 'ContactController'
}
}
})
.state('app.contacts.detail', {
url: '/:id',
/*
templateUrl: 'templates/partials/subscriber-detail.html',
controller: 'SubscriberDetailController'
*/
views: {
'detail@app.contacts': {
templateUrl: 'templates/partials/contact-detail.html',
controller: 'ContactDetailController'
}
}
})
.state('app.music', {
url: 'music',
views: {
'content@': {
templateUrl: 'templates/music.html',
controller: 'MusicController'
}
}
})
.state('app.email', {
url: 'email',
views: {
'content@': {
templateUrl: 'templates/email.html',
controller: 'EmailController'
}
}
})
.state('app.website', {
url: 'website',
views: {
'content@': {
templateUrl: 'templates/website.html',
controller: 'WebsiteController'
}
}
})
.state('app.dns', {
url: 'dns',
views: {
'content@': {
templateUrl: 'templates/dns.html',
controller: 'DnsController'
}
}
});
}]);
app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
var requiresLogin = toState.data.requiresLogin;
if (!Auth.isLoggedIn()) { redirected = true; }
// set url
redirectedURL = toState.url;
urlArray.push(redirectedURL);
if (urlArray.length > 1) {
redirectedURL = urlArray[0];
urlArray = [];
}
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
$state.go('splash-page', { 'toState': toState.name });
}
});
}]);