walnut_launchpad.html/js/app.js

155 lines
3.9 KiB
JavaScript
Raw Normal View History

2017-08-09 04:23:19 +00:00
var app = angular.module('launchpad', ['ui.router', 'LocalStorageModule']);
app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', function($stateProvider, $urlRouterProvider, localStorageServiceProvider){
2017-08-09 18:41:43 +00:00
localStorageServiceProvider.setPrefix('launchpad').setStorageType('sessionStorage');
2017-08-09 04:23:19 +00:00
2017-08-09 18:41:43 +00:00
$urlRouterProvider.otherwise('/splash-page');
2017-08-08 06:35:11 +00:00
2017-08-09 18:41:43 +00:00
$stateProvider
.state('splash-page', {
2017-08-10 17:36:59 +00:00
data: { 'requiresLogin': false },
2017-08-09 18:41:43 +00:00
params: {
'toState': 'launchpad-home', // default state to proceed to after login
'toParams': {}
},
2017-08-10 17:36:59 +00:00
url: '/splash-page',
2017-08-09 18:41:43 +00:00
templateUrl: '/templates/splash-page.html',
})
.state('app',{
url: '/launchpad-',
views: {
'header': {
templateUrl: '/templates/partials/header.html',
controller: 'HomeController',
controllerAs: 'vm'
},
'menu': {
templateUrl: '/templates/partials/menu.html'
},
'content': {
templateUrl: '/templates/home.html'
},
'notifications': {
templateUrl: '/templates/partials/notifications.html'
}
2017-08-10 17:36:59 +00:00
},
data: { 'requiresLogin': true },
params: {
'toState': '',
'toParams': {}
2017-08-09 18:41:43 +00:00
}
})
.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'
}
}
})
.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'
}
}
});
2017-08-10 17:36:59 +00:00
}]);
app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
2017-08-09 18:41:43 +00:00
// Change title based on the `data` object in routes
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
2017-08-10 17:36:59 +00:00
console.log('toState', toState);
console.log('toParams', toParams);
console.log('fromState', fromState);
console.log('fromParams', fromParams);
2017-08-09 04:23:19 +00:00
2017-08-10 17:36:59 +00:00
var requiresLogin = toState.data.requiresLogin;
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
$state.go('splash-page', {'toState': toState.name, 'toParams': toParams});
} else {
// if ($state.params.toState === undefined && $state.params.toParams === undefined) {
// console.log('set a route');
// }
console.log('TOSTATE: ',$state.params.toState);
console.log('TOPARAMS: ',$state.params.toParams);
// $state.go($state.params.toState, $state.params.toParams);
}
});
2017-08-09 04:23:19 +00:00
}]);