webstaff: teach egGrid how to disable multiselect
authorGalen Charlton <gmc@esilibrary.com>
Fri, 17 Jul 2015 19:22:36 +0000 (19:22 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:19 +0000 (13:39 -0400)
For grids where it makes sense to allow only one row to be
selected at a time, egGrid now supports a "-multiselect"
feature that:

  * disables generation of the checkbox column
  * disables control-/shift/command-click to multiselect

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/share/t_autogrid.tt2
Open-ILS/web/js/ui/default/staff/services/grid.js

index 3d021a2..53265c6 100644 (file)
     <div class="eg-grid-cell eg-grid-cell-stock">
       <div title="[% l('Row Number Column') %]">[% l('#') %]</div>
     </div>
-    <div class="eg-grid-cell eg-grid-cell-stock">
+    <div class="eg-grid-cell eg-grid-cell-stock" ng-show="canMultiSelect">
       <div>
         <input title="[% l('Row Selector Column') %]"
           focus-me="gridControls.focusRowSelector"
         </a>
         <div ng-hide="gridControls.activateItem">{{$index + offset() + 1}}</div>
       </div>
-      <div class="eg-grid-cell eg-grid-cell-stock">
+      <div class="eg-grid-cell eg-grid-cell-stock" ng-show="canMultiSelect">
         <!-- ng-click=handleRowClick here has unintended 
              consequences and is unnecessary, avoid it -->
         <div>
index e2c1c52..ce0542f 100644 (file)
@@ -34,6 +34,9 @@ angular.module('egGridMod',
             //  -display : columns are hidden by default
             //  -sort    : columns are unsortable by default 
             //  -multisort : sort priorities config disabled by default
+            //  -multiselect : only one row at a time can be selected;
+            //                 choosing this also disables the checkbox
+            //                 column
             features : '@',
 
             // optional primary grid label
@@ -143,6 +146,7 @@ angular.module('egGridMod',
                     defaultToNoSort : (features.indexOf('-sort') > -1),
                     defaultToNoMultiSort : (features.indexOf('-multisort') > -1)
                 });
+                $scope.canMultiSelect = (features.indexOf('-multiselect') == -1);
 
                 $scope.handleAutoFields = function() {
                     if ($scope.autoFields) {
@@ -666,6 +670,12 @@ angular.module('egGridMod',
 
                 var origSelected = Object.keys($scope.selected);
 
+                if (!$scope.canMultiSelect) {
+                    grid.selectOneItem(index);
+                    grid.lastSelectedItemIndex = index;
+                    return;
+                }
+
                 if ($event.ctrlKey || $event.metaKey /* mac command */) {
                     // control-click
                     if (grid.toggleSelectOneItem(index))