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',
27 $routeProvider.when('/about', {
28 templateUrl: './t_about',
29 controller: 'AboutCtrl',
34 $routeProvider.otherwise({
35 templateUrl : './t_splash',
36 controller : 'SplashCtrl',
43 * Reads the login form and submits the login request
45 .controller('LoginCtrl',
46 /* inject services into our controller. Spelling them
47 * out like this allows the auto-magic injector to work
48 * even if the code has been minified */
49 ['$scope','$location','$window','egCore','egLovefield',
50 function($scope , $location , $window , egCore , egLovefield) {
51 egLovefield.havePendingOfflineXacts() .then(
52 function(eh){ $scope.pendingXacts = eh; },
53 function() {} // SharedWorker not supported
56 $scope.focusMe = true;
58 $scope.workstations = [];
60 egCore.strings.setPageTitle(
61 egCore.strings['PAGE_TITLE_LOGIN']);
63 // if the user is already logged in, jump to splash page
64 if (egCore.auth.user()) $location.path('/');
66 egCore.hatch.getWorkstations()
68 if (all && all.length) {
69 $scope.workstations = all.map(function(a) { return a.name });
71 if (ws = $location.search().ws) {
72 // user requested a workstation via URL
73 var match = all.filter(
74 function(w) {return ws == w.name} )[0];
77 // requested WS registered on this client
78 $scope.args = {workstation : match.name};
80 // the requested WS is not registered on this client
81 $scope.wsNotRegistered = true;
84 // no workstation requested; use the default
85 egCore.hatch.getDefaultWorkstation()
87 $scope.args = {workstation : ws}
93 $scope.login = function(args) {
94 $scope.loginFailed = false;
96 if (!args) args = {}; // see FF note below
100 Issues with form autofill / auto-complete
101 https://github.com/angular/angular.js/issues/1460
102 http://timothy.userapp.io/post/63412334209/form-autocomplete-and-remember-password-with-angularjs
103 For now, since FF will save the values, we should
104 honor them, even if it's hacky. */
105 args.username = document.getElementById("login-username").value;
106 args.password = document.getElementById("login-password").value;
109 if (! (args.username && args.password) ) return;
111 // if at least one workstation exists, it must be used.
112 if (!args.workstation && $scope.workstations.length > 0) return;
115 egCore.auth.login(args).then(
118 // After login, send the user to:
119 // 1. The WS admin page for WS maintenance.
120 // 2. The page originally requested by the caller
123 // NOTE: using $location.path(...) results in
124 // confusing intermediate page loads, since
125 // path(...) is a setter function. Build the URL by
126 // hand instead from the configured base path.
127 var route_to = egCore.env.basePath;
129 if (result.invalid_workstation) {
130 // route to WS admin page to delete the offending
131 // WS and create a new one.
133 'admin/workstation/workstations?remove='
134 + encodeURIComponent(args.workstation);
136 } else if ($location.search().route_to) {
137 // Route to the originally requested page.
138 route_to = $location.search().route_to;
141 $window.location.href = route_to;
144 $scope.args.password = '';
145 $scope.loginFailed = true;
146 $scope.focusMe = true;
154 * Splash page dynamic content.
156 .controller('SplashCtrl', ['$scope', '$window','egCore',
157 function($scope, $window,egCore) {
159 $scope.focus_search = true;
161 egCore.strings.setPageTitle(
162 egCore.strings['PAGE_TITLE_SPLASH']);
164 $scope.catalog_search = function($event) {
165 $scope.focus_search = true;
166 if (!$scope.cat_query) return;
167 if ($event && $event.keyCode != 13) return; // input ng-keypress
168 $window.location.href =
169 '/eg2/staff/catalog/search?query=' +
170 encodeURIComponent($scope.cat_query);
174 .controller('AboutCtrl', [
175 '$scope','$location','egCore',
176 function($scope , $location , egCore) {
179 server : $location.host()
183 'open-ils.actor','opensrf.open-ils.system.ils_version')
184 .then(function(version) {
185 $scope.context.version = version;
189 egCore.strings.setPageTitle(
190 egCore.strings['PAGE_TITLE_ABOUT']);