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 // if the user is already logged in, jump to splash page
61 if (egCore.auth.user()) $location.path('/');
63 egCore.hatch.getItem('eg.workstation.all')
65 if (all && all.length) {
66 $scope.workstations = all.map(function(a) { return a.name });
68 if (ws = $location.search().ws) {
69 // user requested a workstation via URL
70 var match = all.filter(
71 function(w) {return ws == w.name} )[0];
74 // requested WS registered on this client
75 $scope.args = {workstation : match.name};
77 // the requested WS is not registered on this client
78 $scope.wsNotRegistered = true;
81 // no workstation requested; use the default
82 egCore.hatch.getItem('eg.workstation.default')
84 $scope.args = {workstation : ws}
90 $scope.login = function(args) {
91 $scope.loginFailed = false;
93 if (!args) args = {}; // see FF note below
97 Issues with form autofill / auto-complete
98 https://github.com/angular/angular.js/issues/1460
99 http://timothy.userapp.io/post/63412334209/form-autocomplete-and-remember-password-with-angularjs
100 For now, since FF will save the values, we should
101 honor them, even if it's hacky. */
102 args.username = document.getElementById("login-username").value;
103 args.password = document.getElementById("login-password").value;
106 if (! (args.username && args.password) ) return;
108 // if at least one workstation exists, it must be used.
109 if (!args.workstation && $scope.workstations.length > 0) return;
112 egCore.auth.login(args).then(
115 // After login, send the user to:
116 // 1. The WS admin page for WS maintenance.
117 // 2. The page originally requested by the caller
120 // NOTE: using $location.path(...) results in
121 // confusing intermediate page loads, since
122 // path(...) is a setter function. Build the URL by
123 // hand instead from the configured base path.
124 var route_to = egCore.env.basePath;
126 if (result.invalid_workstation) {
127 // route to WS admin page to delete the offending
128 // WS and create a new one.
130 'admin/workstation/workstations?remove='
131 + encodeURIComponent(args.workstation);
133 } else if ($location.search().route_to) {
134 // Route to the originally requested page.
135 route_to = $location.search().route_to;
138 $window.location.href = route_to;
141 $scope.args.password = '';
142 $scope.loginFailed = true;
143 $scope.focusMe = true;
151 * Splash page dynamic content.
153 .controller('SplashCtrl', ['$scope', '$window', function($scope, $window) {
154 console.log('SplashCtrl');
155 $scope.focus_search = true;
157 $scope.catalog_search = function($event) {
158 $scope.focus_search = true;
159 if (!$scope.cat_query) return;
160 if ($event && $event.keyCode != 13) return; // input ng-keypress
161 $window.location.href =
162 '/eg/staff/cat/catalog/results?query=' +
163 encodeURIComponent($scope.cat_query);
167 .controller('AboutCtrl', [
168 '$scope','$location','egCore',
169 function($scope , $location , egCore) {
172 server : $location.host()
176 'open-ils.actor','opensrf.open-ils.system.ils_version')
177 .then(function(version) {
178 $scope.context.version = version;