web staff autogrid; sorting
authorBill Erickson <berick@esilibrary.com>
Mon, 24 Mar 2014 00:27:58 +0000 (20:27 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 24 Mar 2014 00:27:58 +0000 (20:27 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/parts/column_picker.tt2
Open-ILS/src/templates/staff/parts/t_autogrid.tt2
Open-ILS/web/js/ui/default/staff/services/autogrid.js

index 4359284..15ce9c5 100644 (file)
@@ -14,9 +14,10 @@ dropdowns, etc. to the btn-group
     data-toggle="dropdown"> <span class="caret"></span>
   </button>
   <ul class="dropdown-menu pull-right">
-    <li><a href='' ng-click="showGridConf = !showGridConf">
-          <span class="glyphicon glyphicon-wrench"></span>
-          [% l('Configure Columns') %]
+    <li>
+      <a href='' ng-click="toggleGridConf()">
+        <span class="glyphicon glyphicon-wrench"></span>
+        [% l('Configure Columns') %]
       </a>
     </li>
     <li role="presentation" class="divider"></li>
index e49d539..15c8b55 100644 (file)
       style="flex:{{column.flexWidth}}"
       ng-show="dataList.displayColumns[column.name]">
       <div style="width:100%;text-align:center">
-        <a href="javascript:;" title="[% l('Make column wider') %]"
+        <a href="" title="[% l('Make column wider') %]"
           ng-click="column.flexWidth = column.flexWidth + 1">
           <span class="glyphicon glyphicon-fast-forward"></span>
         </a>
       </div>
       <div style="width:100%;text-align:center;border-top:1px solid #ccc">
-        <a href="javascript:;" title="[% l('Make column narrower') %]"
+        <a href="" title="[% l('Make column narrower') %]"
           ng-click="column.flexWidth = column.flexWidth - 1">
           <span class="glyphicon glyphicon-fast-backward"></span>
         </a>
       </div>
       <div style="width:100%;text-align:center;border-top:1px solid #ccc">
         <input type='number' ng-model="column.sortPriority" 
-          title="[% l('Sort Priority') %]" style='width:3em'/>
+          title="[% l('Sort Priority') %]" style='width:2.3em'/>
       </div>
     </div>
   </div>
@@ -97,7 +97,8 @@
     <div class="eg-grid-cell eg-grid-cell-1">
       <!-- ng-click=handleRowClick here has unintended 
            consequences and is unnecessary, avoid it -->
-      <input type='checkbox' ng-model="dataList.selected[dataList.indexValue(item)]"/>
+      <input type='checkbox'  
+        ng-model="dataList.selected[dataList.indexValue(item)]"/>
     </div>
     <div class="eg-grid-cell"
         ng-click="handleRowClick($event, item)"
index 3796a7c..71a2e98 100644 (file)
@@ -70,6 +70,38 @@ angular.module('egGridMod', ['egCoreMod', 'egListMod', 'egUiMod', 'ui.bootstrap'
                 $scope.fetchData();
             }
 
+            // maps numeric sort priority to flattener sort blob
+            this.compileSort = function() {
+
+                var sortList = $scope.dataList.allColumns.filter(
+                    function(col) { return Number(col.sortPriority) }
+                ).sort( 
+                    function(a, b) { 
+                        return 
+                            Math.abs(a.sortPriority) < Math.abs(b.sortPriority)
+                            ? -1 : 1;
+                    }
+                );
+
+                $scope.sort = sortList.map(function(col) {
+                    var blob = {};
+                    blob[col.name] = col.sortPriority < 0 ? 'desc' : 'asc';
+                    return blob;
+                });
+                console.log(js2JSON($scope.sort));
+            },
+
+            $scope.toggleGridConf = function() {
+                if ($scope.showGridConf) {
+                    $scope.showGridConf = false;
+                    // configuration done; reload data
+                    self.compileSort();
+                    $scope.fetchData();
+                } else {
+                    $scope.showGridConf = true;
+                }
+            }
+
             /**
              * Adds a column from an eg-grid-field or directly from 
              * an IDL field via compileAutoFields.