2 * App to drive the base page.
7 angular.module('egHome', ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod'])
10 ['$routeProvider','$locationProvider',
11 function($routeProvider , $locationProvider) {
12 $locationProvider.html5Mode(true);
15 * Route resolvers allow us to run async commands
16 * before the page controller is instantiated.
18 var resolver = {delay : ['egCore',
19 function(egCore) {return egCore.startup.go()}]};
21 $routeProvider.when('/login', {
22 templateUrl: './t_login',
23 controller: 'LoginCtrl',
28 $routeProvider.otherwise({
29 templateUrl : './t_splash',
30 controller : 'SplashCtrl',
37 * Reads the login form and submits the login request
39 .controller('LoginCtrl',
40 /* inject services into our controller. Spelling them
41 * out like this allows the auto-magic injector to work
42 * even if the code has been minified */
43 ['$scope','$location','$window','egCore',
44 function($scope , $location , $window , egCore) {
45 $scope.focusMe = true;
47 // if the user is already logged in, jump to splash page
48 if (egCore.auth.user()) $location.path('/');
50 egCore.hatch.getItem('eg.workstation.all')
52 if (all && all.length) {
53 $scope.workstations = all.map(function(a) { return a.name });
55 if (ws = $location.search().ws) {
56 // user requested a workstation via URL
57 var match = all.filter(
58 function(w) {return ws == w.name} )[0];
61 // requested WS registered on this client
62 $scope.args = {workstation : match.name};
64 // the requested WS is not registered on this client
65 $scope.wsNotRegistered = true;
68 // no workstation requested; use the default
69 egCore.hatch.getItem('eg.workstation.default')
71 $scope.args = {workstation : ws}
77 $scope.login = function(args) {
78 $scope.loginFailed = false;
80 if (!args) args = {}; // see FF note below
84 Issues with form autofill / auto-complete
85 https://github.com/angular/angular.js/issues/1460
86 http://timothy.userapp.io/post/63412334209/form-autocomplete-and-remember-password-with-angularjs
87 For now, since FF will save the values, we should
88 honor them, even if it's hacky. */
89 args.username = document.getElementById("login-username").value;
90 args.password = document.getElementById("login-password").value;
93 if (! (args.username && args.password) ) return;
96 egCore.auth.login(args).then(
99 // after login, send the user back to the originally
100 // requested page or, if none, the home page.
101 // TODO: this is a little hinky because it causes 2
102 // redirects if no route_to is defined. Improve.
103 $window.location.href =
104 $location.search().route_to ||
105 $location.path('/').absUrl()
108 $scope.args.password = '';
109 $scope.loginFailed = true;
110 $scope.focusMe = true;
118 * Splash page dynamic content.
120 .controller('SplashCtrl', ['$scope',
122 console.log('SplashCtrl');