webstaff: Teach autogrid about grouping Actions menu options
authorMike Rylander <mrylander@gmail.com>
Fri, 6 Mar 2015 20:54:16 +0000 (15:54 -0500)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:12 +0000 (13:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
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 03aa65e..86f2723 100644 (file)
     </button>
 
     <!-- actions drop-down menu -->
-    <div class="btn-group" ng-if="actions.length" dropdown>                                                  
+    <div class="btn-group" ng-if="actionGroups.length > 1 || actionGroups[0].actions.length" dropdown>                                                  
       <button type="button" class="btn btn-default dropdown-toggle">
         [% l('Actions') %] <span class="caret"></span>                       
       </button>                                                              
       <ul class="dropdown-menu pull-right grid-action-dropdown">                                  
-        <li ng-repeat="action in actions" ng-class="{divider: action.divider}" ng-hide="actionHide(action)">
+        <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)">
           <a ng-if="!action.divider" href
             ng-click="actionLauncher(action)">{{action.label}}</a>
         </li>
+        <span ng-repeat-end/>
       </ul>
     </div>
 
index 2c1a482..68c996f 100644 (file)
@@ -106,7 +106,7 @@ angular.module('egGridMod',
                 $scope.showGridConf = false;
                 grid.totalCount = -1;
                 $scope.selected = {};
-                $scope.actions = []; // actions for selected items
+                $scope.actionGroups = [{actions:[]}]; // Grouped actions for selected items
                 $scope.menuItems = []; // global actions
 
                 // remove some unneeded values from the scope to reduce bloat
@@ -280,7 +280,19 @@ angular.module('egGridMod',
 
             // add a selected-items action
             grid.addAction = function(act) {
-                $scope.actions.push(act);
+                var done = false;
+                $scope.actionGroups.forEach(function(g){
+                    if (g.label === act.group) {
+                        g.actions.push(act);
+                        done = true;
+                    }
+                });
+                if (!done) {
+                    $scope.actionGroups.push({
+                        label : act.group,
+                        actions : [ act ]
+                    });
+                }
             }
 
             // remove the stored column configuration preferenc, then recover 
@@ -972,6 +984,7 @@ angular.module('egGridMod',
         restrict : 'AE',
         transclude : true,
         scope : {
+            group   : '@', // Action group, ungrouped if not set
             label   : '@', // Action label
             handler : '=',  // Action function handler
             hide    : '=',
@@ -980,6 +993,7 @@ angular.module('egGridMod',
         link : function(scope, element, attrs, egGridCtrl) {
             egGridCtrl.addAction({
                 hide  : scope.hide,
+                group : scope.group,
                 label : scope.label,
                 divider : scope.divider,
                 handler : scope.handler