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','egLovefield',
44 function($scope , $location , $window , egCore , egLovefield) {
45 egLovefield.havePendingOfflineXacts() .then(function(eh){
46 $scope.pendingXacts = eh;
49 $scope.focusMe = true;
51 $scope.workstations = [];
53 // if the user is already logged in, jump to splash page
54 if (egCore.auth.user()) $location.path('/');
56 egCore.hatch.getItem('eg.workstation.all')
58 if (all && all.length) {
59 $scope.workstations = all.map(function(a) { return a.name });
61 if (ws = $location.search().ws) {
62 // user requested a workstation via URL
63 var match = all.filter(
64 function(w) {return ws == w.name} )[0];
67 // requested WS registered on this client
68 $scope.args = {workstation : match.name};
70 // the requested WS is not registered on this client
71 $scope.wsNotRegistered = true;
74 // no workstation requested; use the default
75 egCore.hatch.getItem('eg.workstation.default')
77 $scope.args = {workstation : ws}
83 $scope.login = function(args) {
84 $scope.loginFailed = false;
86 if (!args) args = {}; // see FF note below
90 Issues with form autofill / auto-complete
91 https://github.com/angular/angular.js/issues/1460
92 http://timothy.userapp.io/post/63412334209/form-autocomplete-and-remember-password-with-angularjs
93 For now, since FF will save the values, we should
94 honor them, even if it's hacky. */
95 args.username = document.getElementById("login-username").value;
96 args.password = document.getElementById("login-password").value;
99 if (! (args.username && args.password) ) return;
101 // if at least one workstation exists, it must be used.
102 if (!args.workstation && $scope.workstations.length > 0) return;
105 egCore.auth.login(args).then(
108 // After login, send the user to:
109 // 1. The WS admin page for WS maintenance.
110 // 2. The page originally requested by the caller
113 // NOTE: using $location.path(...) results in
114 // confusing intermediate page loads, since
115 // path(...) is a setter function. Build the URL by
116 // hand instead from the configured base path.
117 var route_to = egCore.env.basePath;
119 if (result.invalid_workstation) {
120 // route to WS admin page to delete the offending
121 // WS and create a new one.
123 'admin/workstation/workstations?remove='
124 + encodeURIComponent(args.workstation);
126 } else if ($location.search().route_to) {
127 // Route to the originally requested page.
128 route_to = $location.search().route_to;
131 $window.location.href = route_to;
134 $scope.args.password = '';
135 $scope.loginFailed = true;
136 $scope.focusMe = true;
144 * Splash page dynamic content.
146 .controller('SplashCtrl', ['$scope', '$window', function($scope, $window) {
147 console.log('SplashCtrl');
148 $scope.focus_search = true;
150 $scope.catalog_search = function($event) {
151 $scope.focus_search = true;
152 if (!$scope.cat_query) return;
153 if ($event && $event.keyCode != 13) return; // input ng-keypress
154 $window.location.href =
155 '/eg/staff/cat/catalog/results?query=' +
156 encodeURIComponent($scope.cat_query);