webstaff: Grid supports automatic refresh with query change
authorBill Erickson <berickxx@gmail.com>
Wed, 11 Feb 2015 15:43:43 +0000 (10:43 -0500)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:11 +0000 (13:39 -0400)
Adds a new gridControls function watchQuery(), which returns the
contents of the grid query.  When the contents change, the grid
automatically redraws.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/web/js/ui/default/staff/services/grid.js

index ccb9b40..2c1a482 100644 (file)
@@ -53,6 +53,13 @@ angular.module('egGridMod',
             //  itemRetrieved     : function(item) {}
             //  allItemsRetrieved : function() {}
             //
+            //  ---
+            //  If defined, the grid will watch the return value from
+            //  the function defined at watchQuery on each digest and 
+            //  re-draw the grid when query changes occur.
+            //
+            //  watchQuery : function() { /* return grid query */ }
+            //
             //  ---------------
             //  These functions are defined by the grid and thus
             //  replace any values defined for these attributes from the
@@ -214,6 +221,17 @@ angular.module('egGridMod',
                     controls.refresh();
                 }
 
+                if (controls.watchQuery) {
+                    // capture the initial query value
+                    grid.dataProvider.query = controls.watchQuery();
+
+                    // watch for changes
+                    $scope.gridWatchQuery = controls.watchQuery;
+                    $scope.$watch('gridWatchQuery()', function(newv) {
+                        controls.setQuery(newv);
+                    }, true);
+                }
+
                 // if the caller provided a functional setSort
                 // extract the value before replacing it
                 grid.dataProvider.sort =