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 $scope.workstations = [];
49 // if the user is already logged in, jump to splash page
50 if (egCore.auth.user()) $location.path('/');
52 egCore.hatch.getItem('eg.workstation.all')
54 if (all && all.length) {
55 $scope.workstations = all.map(function(a) { return a.name });
57 if (ws = $location.search().ws) {
58 // user requested a workstation via URL
59 var match = all.filter(
60 function(w) {return ws == w.name} )[0];
63 // requested WS registered on this client
64 $scope.args = {workstation : match.name};
66 // the requested WS is not registered on this client
67 $scope.wsNotRegistered = true;
70 // no workstation requested; use the default
71 egCore.hatch.getItem('eg.workstation.default')
73 $scope.args = {workstation : ws}
79 $scope.login = function(args) {
80 $scope.loginFailed = false;
82 if (!args) args = {}; // see FF note below
86 Issues with form autofill / auto-complete
87 https://github.com/angular/angular.js/issues/1460
88 http://timothy.userapp.io/post/63412334209/form-autocomplete-and-remember-password-with-angularjs
89 For now, since FF will save the values, we should
90 honor them, even if it's hacky. */
91 args.username = document.getElementById("login-username").value;
92 args.password = document.getElementById("login-password").value;
95 if (! (args.username && args.password) ) return;
97 // if at least one workstation exists, it must be used.
98 if (!args.workstation && $scope.workstations.length > 0) return;
101 egCore.auth.login(args).then(
104 // After login, send the user to:
105 // 1. The WS admin page for WS maintenance.
106 // 2. The page originally requested by the caller
109 // NOTE: using $location.path(...) results in
110 // confusing intermediate page loads, since
111 // path(...) is a setter function. Build the URL by
112 // hand instead from the configured base path.
113 var route_to = egCore.env.basePath;
115 if (result.invalid_workstation) {
116 // route to WS admin page to delete the offending
117 // WS and create a new one.
119 'admin/workstation/workstations?remove='
120 + encodeURIComponent(args.workstation);
122 } else if ($location.search().route_to) {
123 // Route to the originally requested page.
124 route_to = $location.search().route_to;
127 $window.location.href = route_to;
130 $scope.args.password = '';
131 $scope.loginFailed = true;
132 $scope.focusMe = true;
140 * Splash page dynamic content.
142 .controller('SplashCtrl', ['$scope', '$window', function($scope, $window) {
143 console.log('SplashCtrl');
144 $scope.focus_search = true;
146 $scope.catalog_search = function($event) {
147 $scope.focus_search = true;
148 if (!$scope.cat_query) return;
149 if ($event && $event.keyCode != 13) return; // input ng-keypress
150 $window.location.href =
151 '/eg/staff/cat/catalog/results?query=' +
152 encodeURIComponent($scope.cat_query);