195 lines
4.8 KiB
JavaScript
Raw Normal View History

2017-09-29 00:01:28 +00:00
(function () {
'use strict';
var angular = window.angular;
var OAUTH3 = window.OAUTH3;
2017-10-04 16:27:36 -06:00
var app = window.app = angular.module('launchpad', ['oauth3.org', 'ui.router', 'LocalStorageModule', 'angucomplete-alt', 'ez.fileTree', 'ui.multiselect']);
2017-09-29 00:01:28 +00:00
app.directive('daplieFileChange', function () {
return {
restrict: 'A',
require:"ngModel",
link: function (scope, element, attrs, ngModel) {
element.bind('change', function (event) {
var files = event.target.files;
ngModel.$setViewValue(files[0]);
scope.$eval(attrs.daplieFileChange);
});
}
};
});
2017-10-30 15:45:58 -06:00
app.config([
'$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider', '$urlMatcherFactoryProvider',
function ($stateProvider, $urlRouterProvider, localStorageServiceProvider, $urlMatcherFactoryProvider) {
$urlMatcherFactoryProvider.strictMode(false);
2017-08-09 12:41:43 -06:00
localStorageServiceProvider.setPrefix('launchpad').setStorageType('sessionStorage');
2017-08-08 22:23:19 -06:00
2017-08-09 12:41:43 -06:00
$urlRouterProvider.otherwise('/splash-page');
2017-10-30 15:45:58 -06:00
2017-08-09 12:41:43 -06:00
$stateProvider
2017-08-11 21:49:18 -06:00
.state('splash-page', {
2017-10-30 15:45:58 -06:00
data: { requiresLogin: false, session: null },
2017-08-11 21:49:18 -06:00
url: '/splash-page',
templateUrl: '/templates/splash-page.html',
2017-08-21 16:06:38 -06:00
controller: 'loginCtrl as vm'
2017-08-11 21:49:18 -06:00
})
2017-08-09 12:41:43 -06:00
.state('app',{
2017-08-24 16:51:19 -06:00
data: { requiresLogin: true, session: null },
2017-08-11 15:37:06 -06:00
url: '/',
2017-08-21 16:06:38 -06:00
controller: 'loginCtrl as vm',
2017-08-09 12:41:43 -06:00
views: {
'header': {
templateUrl: '/templates/partials/header.html',
},
'menu': {
templateUrl: '/templates/partials/menu.html'
},
'content': {
templateUrl: '/templates/home.html'
}
2017-08-11 13:21:35 -06:00
}
2017-08-09 12:41:43 -06:00
})
.state('app.home', {
url: 'home',
views: {
'content@': {
templateUrl: 'templates/home.html',
2017-08-21 14:28:58 -06:00
controller: 'loginCtrl as vm'
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.bolt', {
url: 'bolt',
views: {
'content@': {
templateUrl: 'templates/bolt.html',
2017-08-21 14:28:58 -06:00
controller: 'boltCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.files', {
url: 'files',
views: {
'content@': {
templateUrl: 'templates/files.html',
2017-08-21 14:28:58 -06:00
controller: 'fileCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.contacts', {
url: 'contacts',
views: {
'content@': {
templateUrl: 'templates/contacts.html',
2017-08-21 14:28:58 -06:00
controller: 'contactCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.music', {
url: 'music',
views: {
'content@': {
templateUrl: 'templates/music.html',
2017-08-21 14:28:58 -06:00
controller: 'musicCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.email', {
url: 'email',
views: {
'content@': {
templateUrl: 'templates/email.html',
2017-08-21 14:28:58 -06:00
controller: 'emailCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.website', {
url: 'website',
views: {
'content@': {
templateUrl: 'templates/website.html',
2017-08-21 14:28:58 -06:00
controller: 'websiteCtrl as vm',
2017-08-09 12:41:43 -06:00
}
}
})
.state('app.dns', {
url: 'dns',
views: {
'content@': {
templateUrl: 'templates/dns.html',
controller: 'dnsCtrl',
2017-08-09 12:41:43 -06:00
}
}
2017-08-18 15:13:43 -06:00
})
2017-10-21 01:24:24 -06:00
.state('app.applications', {
url: 'apps',
views: {
'content@': {
templateUrl: 'templates/applications.html',
controller: '',
}
}
})
.state('app.devices', {
url: 'devices',
views: {
'content@': {
templateUrl: 'templates/devices.html',
controller: '',
}
}
})
2017-08-18 15:13:43 -06:00
.state('app.account-settings', {
url: 'account-settings',
views: {
'content@': {
templateUrl: 'templates/account-settings.html',
2017-09-29 00:01:28 +00:00
controller: 'profileCtrl as vm',
2017-08-18 15:13:43 -06:00
}
}
2017-08-09 12:41:43 -06:00
});
2017-08-10 11:36:59 -06:00
}]);
2017-08-24 16:51:19 -06:00
app.run(['$rootScope', '$state', 'Auth', '$location', function($rootScope, $state, Auth, $location) {
$rootScope.urlArray = [];
2017-10-31 12:24:52 -06:00
$rootScope.urlCrumbs = [];
2017-10-30 15:45:58 -06:00
$rootScope.urlInfo = {
url: $location.$$url,
path: $location.$$path,
params: $location.$$search
};
2017-10-31 12:24:52 -06:00
debugger;
2017-08-09 12:41:43 -06:00
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
2017-08-10 11:36:59 -06:00
var requiresLogin = toState.data.requiresLogin;
2017-10-31 12:24:52 -06:00
toState.data.session = $location.search();
$rootScope.redirectedURL = toState.url;
2017-08-28 16:18:33 -06:00
var query = $location.search();
$rootScope.urlArray.push($rootScope.redirectedURL);
2017-10-31 12:24:52 -06:00
$rootScope.urlCrumbs.push($rootScope.urlInfo);
debugger;
2017-08-10 16:33:54 -06:00
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
2017-08-25 16:32:12 -06:00
if (!angular.equals(toState.data.session, {})) {
2017-10-31 12:24:52 -06:00
debugger;
if (toState.data.session.refresh !== undefined) {
toState.data.session.token = OAUTH3.jwt.decode(query.access_token);
toState.data.session.refresh = OAUTH3.jwt.decode(query.refresh_token);
Auth.add(query);
$state.go('app.' + $rootScope.redirectedURL);
} else {
$state.go('splash-page', { 'toState': toState.name });
debugger;
}
2017-08-29 09:34:58 -06:00
} else {
$state.go('splash-page', { 'toState': toState.name });
2017-08-25 16:32:12 -06:00
}
2017-08-10 16:33:54 -06:00
}
2017-10-30 15:45:58 -06:00
2017-08-10 11:36:59 -06:00
});
2017-08-08 22:23:19 -06:00
}]);
2017-09-29 00:01:28 +00:00
}());