From c9a2dbf3e8894062b4b2fb7677aa0a4a80d6f2f4 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 28 Aug 2015 17:42:41 -0400 Subject: [PATCH] webstaff: Enhance grid item selection API for external hooks Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Jason Stephenson --- Open-ILS/src/templates/staff/share/t_autogrid.tt2 | 1 + Open-ILS/web/js/ui/default/staff/services/grid.js | 28 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 index 7a85f51ac6..aaf14aab59 100644 --- a/Open-ILS/src/templates/staff/share/t_autogrid.tt2 +++ b/Open-ILS/src/templates/staff/share/t_autogrid.tt2 @@ -292,6 +292,7 @@ consequences and is unnecessary, avoid it -->
diff --git a/Open-ILS/web/js/ui/default/staff/services/grid.js b/Open-ILS/web/js/ui/default/staff/services/grid.js index fbbdb46e4f..5e399b05ab 100644 --- a/Open-ILS/web/js/ui/default/staff/services/grid.js +++ b/Open-ILS/web/js/ui/default/staff/services/grid.js @@ -29,6 +29,12 @@ angular.module('egGridMod', // Reference to externally provided egGridDataProvider itemsProvider : '=', + // Reference to externally provided item-selection handler + onSelect : '=', + + // Reference to externally provided after-item-selection handler + afterSelect : '=', + // comma-separated list of supported or disabled grid features // supported features: // startSelected : init the grid with all rows selected by default @@ -652,19 +658,28 @@ angular.module('egGridMod', // selects or deselects an item, without affecting the others. // returns true if the item is selected; false if de-selected. + // we overwrite the object so that we can watch $scope.selected grid.toggleSelectOneItem = function(index) { if ($scope.selected[index]) { delete $scope.selected[index]; + $scope.selected = angular.copy($scope.selected); return false; } else { - return $scope.selected[index] = true; + $scope.selected[index] = true; + $scope.selected = angular.copy($scope.selected); + return true; } } + $scope.updateSelected = function () { + return $scope.selected = angular.copy($scope.selected); + }; + grid.selectAllItems = function() { angular.forEach($scope.items, function(item) { $scope.selected[grid.indexValue(item)] = true - }); + }); + $scope.selected = angular.copy($scope.selected); } $scope.$watch('selectAll', function(newVal) { @@ -675,6 +690,13 @@ angular.module('egGridMod', } }); + if ($scope.onSelect) { + $scope.$watch('selected', function(newVal) { + $scope.onSelect(grid.getSelectedItems()); + if ($scope.afterSelect) $scope.afterSelect(); + }); + } + // returns true if item1 appears in the list before item2; // false otherwise. this is slightly more efficient that // finding the position of each then comparing them. @@ -758,6 +780,7 @@ angular.module('egGridMod', $scope.selected[curIdx] = true; if (curIdx == index) break; // all done } + $scope.selected = angular.copy($scope.selected); } } else { @@ -979,6 +1002,7 @@ angular.module('egGridMod', }).finally(function() { console.debug('egGrid.collect() complete'); grid.collecting = false + $scope.selected = angular.copy($scope.selected); }); } -- 2.11.0