webstaff: teach egGrid action menus how to conditionally disable items
authorGalen Charlton <gmc@esilibrary.com>
Thu, 23 Jul 2015 17:49:36 +0000 (17:49 +0000)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:19 +0000 (13:39 -0400)
It is now possible to pass a function to specify if an action
menu item should be disabled:

  <eg-grid-action handler="do_stuff" disabled="cant_do_stuff"
    label="[% l('Do Stuff') %]"></eg-grid-action>

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 53265c6..36c5da2 100644 (file)
@@ -90,9 +90,9 @@
         <li ng-repeat-start="group in actionGroups">
           <span style="padding-left: 1em;" ng-if="group.label"><strong><u>{{group.label}}</u></strong></span>
         </li>
-        <li ng-repeat="action in group.actions" ng-class="{divider: action.divider}" ng-hide="actionHide(action)">
+        <li ng-repeat="action in group.actions" ng-class="{divider: action.divider, disabled: actionDisable(action)}" ng-hide="actionHide(action)">
           <a ng-if="!action.divider" href
-            ng-click="actionLauncher(action)">{{action.label}}</a>
+            ng-click="!actionDisable(action) && actionLauncher(action)">{{action.label}}</a>
         </li>
         <span ng-repeat-end/>
       </ul>
index ce0542f..1418106 100644 (file)
@@ -516,6 +516,14 @@ angular.module('egGridMod',
                 return action.hide(action);
             }
 
+            // fires the disable handler function for a context action
+            $scope.actionDisable = function(action) {
+                if (!action.disabled) {
+                    return false;
+                }
+                return action.disabled(action);
+            }
+
             // fires the action handler function for a context action
             $scope.actionLauncher = function(action) {
                 if (!action.handler) {
@@ -1011,6 +1019,7 @@ angular.module('egGridMod',
             label   : '@', // Action label
             handler : '=',  // Action function handler
             hide    : '=',
+            disabled : '=', // function
             divider : '='
         },
         link : function(scope, element, attrs, egGridCtrl) {
@@ -1019,7 +1028,8 @@ angular.module('egGridMod',
                 group : scope.group,
                 label : scope.label,
                 divider : scope.divider,
-                handler : scope.handler
+                handler : scope.handler,
+                disabled : scope.disabled,
             });
             scope.$destroy();
         }