items out sorting user/berick/lpxxx-items-out-sorting
authorBill Erickson <berickxx@gmail.com>
Mon, 21 Oct 2019 19:32:54 +0000 (15:32 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 21 Oct 2019 19:32:54 +0000 (15:32 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js

index 327eeb5..aed2053 100644 (file)
@@ -99,12 +99,10 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
 
     function fetch_circs(id_list, offset, count) {
         if (!id_list.length || id_list.length < offset + 1) return $q.when();
-
-        var deferred = $q.defer();
         var rendered = 0;
 
         // fetch the lot of circs and stream the results back via notify
-        egCore.pcrud.search('circ', {id : id_list},
+        return egCore.pcrud.search('circ', {id : id_list},
             {   flesh : 4,
                 flesh_fields : {
                     circ : ['target_copy', 'workstation', 'checkin_workstation'],
@@ -125,7 +123,7 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                 // we need an order-by to support paging
                 order_by : {circ : ['xact_start']} 
 
-        }).then(deferred.resolve, null, function(circ) {
+        }).then(null, null, function(circ) {
             circ.circ_lib(egCore.org.get(circ.circ_lib())); // local fleshing
 
             // Translate bib display field JSON blobs to JS.
@@ -145,8 +143,9 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                 return part.label()
             }).join(',');
 
-           // call open-ils to get overdue notice count and  Last notice date
-           
+        // call open-ils to get overdue notice count and  Last notice date
+        
+             
            egCore.net.request(
                'open-ils.actor',
                'open-ils.actor.user.itemsout.notices',
@@ -155,14 +154,17 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
                if (notice.numNotices){
                    circ.action_trigger_event_count = notice.numNotices;
                    circ.action_trigger_latest_event_date = notice.lastDt;
-              }
-               patronSvc.items_out.push(circ);
+               }
            });
 
-              if (rendered++ >= offset && rendered <= count){ deferred.notify(circ) };
-        });
+           if (rendered++ >= offset && rendered <= count) { 
+               patronSvc.items_out.push(circ);
+            }
 
-        return deferred.promise;
+        }).then(function() {
+            // Wrap up with the notifier which performs our client-side sorting
+            return provider.arrayNotifier(patronSvc.items_out, offset, count);
+        });
     }
 
     function fetch_noncat_circs(id_list, offset, count) {
@@ -277,17 +279,14 @@ function($scope , $q , $routeParams , $timeout , egCore , egUser , patronSvc ,
         // notify()'s from egCore.net.request don't leak into the 
         // final set of notifies (i.e. the real responses);
 
-        var deferred = $q.defer();
-        get_circ_ids().then(function() {
+        return get_circ_ids().then(function() {
 
             id_list = $scope[$scope.items_out_display + '_list'];
             $scope.gridDataProvider.grid.totalCount = id_list.length;
             // relay the notified circs back to the grid through our promise
-            fetch_circs(id_list, offset, count).then(
-                deferred.resolve, null, deferred.notify);
+            
+            return fetch_circs(id_list, offset, count);
         });
-
-        return deferred.promise;
     }