LP#1402797 patron search form focus repairs cont.
authorBill Erickson <berickxx@gmail.com>
Fri, 2 Jan 2015 16:21:43 +0000 (11:21 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 12 Feb 2015 17:03:04 +0000 (12:03 -0500)
Building on Mike's original work, use Angular ng-mouseover and the
Angular $document built-in.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/templates/staff/circ/patron/t_search.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index b2034f9..bc4e92a 100644 (file)
             ng-model="searchArgs.second_given_name" placeholder="[% l('Middle Name') %]"/>
         </div>
 
             ng-model="searchArgs.second_given_name" placeholder="[% l('Middle Name') %]"/>
         </div>
 
-        <div class="col-md-2" onmouseover="window.prevElement=document.activeElement">
+        <div class="col-md-2" ng-mouseover="setLastFormElement()">
           <input type="submit" class="btn btn-default" value="[% l('Search') %]"/>
         </div>
 
           <input type="submit" class="btn btn-default" value="[% l('Search') %]"/>
         </div>
 
-        <div class="col-md-2" onmouseover="window.prevElement=document.activeElement">
+        <div class="col-md-2" ng-mouseover="setLastFormElement()">
           <input type="reset" class="btn btn-default" ng-click="clearForm()" 
             value="[% l('Clear Form') %]"/>
         </div>
 
         <div class="col-md-2">
           <button class="btn btn-default" ng-click="applyShowExtras($event, true)" 
           <input type="reset" class="btn btn-default" ng-click="clearForm()" 
             value="[% l('Clear Form') %]"/>
         </div>
 
         <div class="col-md-2">
           <button class="btn btn-default" ng-click="applyShowExtras($event, true)" 
-            onmouseover="window.prevElement=document.activeElement"
+            ng-mouseover="setLastFormElement()"
             title="[% l('Show More Fields') %]" ng-show="!showExtras">
             <span class="glyphicon glyphicon-circle-arrow-down"></span>
           </button>
           <button class="btn btn-default" ng-click="applyShowExtras($event, false)" 
             title="[% l('Show More Fields') %]" ng-show="!showExtras">
             <span class="glyphicon glyphicon-circle-arrow-down"></span>
           </button>
           <button class="btn btn-default" ng-click="applyShowExtras($event, false)" 
-            onmouseover="window.prevElement=document.activeElement"
+            ng-mouseover="setLastFormElement()"
             title="[% l('Show Fewer Fields') %]" ng-show="showExtras">
             <span class="glyphicon glyphicon-circle-arrow-up"></span>
           </button>
             title="[% l('Show Fewer Fields') %]" ng-show="showExtras">
             <span class="glyphicon glyphicon-circle-arrow-up"></span>
           </button>
index 3ce36c5..d8b373a 100644 (file)
@@ -716,9 +716,9 @@ function($scope , $location , egCore , egConfirmDialog , egUser , patronSvc) {
  */
 .controller('PatronSearchCtrl',
        ['$scope','$q','$routeParams','$timeout','$window','$location','egCore',
  */
 .controller('PatronSearchCtrl',
        ['$scope','$q','$routeParams','$timeout','$window','$location','egCore',
-       '$filter','egUser', 'patronSvc','egGridDataProvider',
+       '$filter','egUser', 'patronSvc','egGridDataProvider','$document',
 function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
 function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
-        $filter,  egUser,  patronSvc , egGridDataProvider) {
+        $filter,  egUser,  patronSvc , egGridDataProvider , $document) {
 
     $scope.initTab('search');
     $scope.focusMe = true;
 
     $scope.initTab('search');
     $scope.focusMe = true;
@@ -727,6 +727,9 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
         home_ou : egCore.org.tree()
     };
 
         home_ou : egCore.org.tree()
     };
 
+    // last used patron search form element
+    var lastFormElement;
+
     $scope.gridControls = {
         activateItem : function(item) {
             $location.path('/circ/patron/' + item.id() + '/checkout');
     $scope.gridControls = {
         activateItem : function(item) {
             $location.path('/circ/patron/' + item.id() + '/checkout');
@@ -886,7 +889,7 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
 
     $scope.clearForm = function () {
         $scope.searchArgs={};
 
     $scope.clearForm = function () {
         $scope.searchArgs={};
-        window.prevElement.focus();
+        if (lastFormElement) lastFormElement.focus();
     }
 
     $scope.applyShowExtras = function($event, bool) {
     }
 
     $scope.applyShowExtras = function($event, bool) {
@@ -897,7 +900,7 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
             $scope.showExtras = false;
             egCore.hatch.removeItem('eg.circ.patron.search.show_extras');
         }
             $scope.showExtras = false;
             egCore.hatch.removeItem('eg.circ.patron.search.show_extras');
         }
-        window.prevElement.focus();
+        if (lastFormElement) lastFormElement.focus();
         $event.preventDefault();
     }
 
         $event.preventDefault();
     }
 
@@ -960,12 +963,16 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
         return sort;
     }
 
         return sort;
     }
 
+    $scope.setLastFormElement = function() {
+        lastFormElement = $document[0].activeElement;
+    }
+
     // search form submit action; tells the results grid to
     // refresh itself.
     $scope.search = function(args) { // args === $scope.searchArgs
         if (args && Object.keys(args).length) 
             $scope.gridControls.refresh();
     // search form submit action; tells the results grid to
     // refresh itself.
     $scope.search = function(args) { // args === $scope.searchArgs
         if (args && Object.keys(args).length) 
             $scope.gridControls.refresh();
-        window.prevElement.focus();
+        if (lastFormElement) lastFormElement.focus();
     }
 
     // TODO: move this into the (forthcoming) grid row activate action
     }
 
     // TODO: move this into the (forthcoming) grid row activate action