grid nested wildcard fields
authorBill Erickson <berick@esilibrary.com>
Wed, 25 Jun 2014 18:29:44 +0000 (14:29 -0400)
committerBill Erickson <berick@esilibrary.com>
Wed, 25 Jun 2014 18:29:44 +0000 (14:29 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/grid.js

index a21ba78..fd71ac4 100644 (file)
@@ -647,7 +647,6 @@ angular.module('egGridMod',
                 // the columns array, then force a page refresh
                 grid.columnsProvider.columns.splice(srcIdx, 1);
                 grid.columnsProvider.columns.splice(targetIdx, 0, srcCol);
-                console.log(JSON.stringify(grid.columnsProvider.columns,'',2));
                 $scope.$apply(); 
             }
 
@@ -792,6 +791,13 @@ angular.module('egGridMod',
             flex  : '@',  // optional; default flex width
             dateformat : '@', // optional: passed down to egGridValueFilter
 
+            // if a field is part of an IDL object, but we are unable to
+            // determine the class, because it's nested within a hash
+            // (i.e. we can't navigate directly to the object via the IDL),
+            // idlClass lets us specify the class.  This is particularly
+            // useful for nested wildcard fields.
+            parentIdlClass : '@', 
+
             // optional: for non-IDL columns, specifying a datatype
             // lets the caller control which display filter is used.
             // datatype should match the standard IDL datatypes.
@@ -946,27 +952,37 @@ angular.module('egGridMod',
         cols.expandPath = function(colSpec) {
 
             var dotpath = colSpec.path.replace(/\.\*$/,'');
-            var class_obj = egCore.idl.classes[cols.idlClass];
-            var path_parts = dotpath.split(/\./);
-
-            // find the IDL class definition for the last element in the
-            // path before the .*
             var class_obj;
-            for (var path_idx in path_parts) {
-                var part = path_parts[path_idx];
-                var idl_field = class_obj.field_map[part];
 
-                // unless we're at the end of the list, this field should
-                // link to another class.
-                if (idl_field && idl_field['class'] && (
-                    idl_field.datatype == 'link' || 
-                    idl_field.datatype == 'org_unit')) {
-                    class_obj = egCore.idl.classes[idl_field['class']];
-                } else {
-                    if (path_idx < (path_parts.length - 1)) {
-                        // we ran out of classes to hop through before
-                        // we ran out of path components
-                        console.error("egGrid: invalid IDL path: " + path);
+            if (colSpec.parentIdlClass) {
+                class_obj = egCore.idl.classes[colSpec.parentIdlClass];
+
+            } else {
+
+                class_obj = egCore.idl.classes[cols.idlClass];
+                if (!class_obj) return;
+
+                var path_parts = dotpath.split(/\./);
+
+                // find the IDL class definition for the last element in the
+                // path before the .*
+                var class_obj;
+                for (var path_idx in path_parts) {
+                    var part = path_parts[path_idx];
+                    var idl_field = class_obj.field_map[part];
+
+                    // unless we're at the end of the list, this field should
+                    // link to another class.
+                    if (idl_field && idl_field['class'] && (
+                        idl_field.datatype == 'link' || 
+                        idl_field.datatype == 'org_unit')) {
+                        class_obj = egCore.idl.classes[idl_field['class']];
+                    } else {
+                        if (path_idx < (path_parts.length - 1)) {
+                            // we ran out of classes to hop through before
+                            // we ran out of path components
+                            console.error("egGrid: invalid IDL path: " + path);
+                        }
                     }
                 }
             }
@@ -982,7 +998,8 @@ angular.module('egGridMod',
 
                     var col = cols.cloneFromScope(colSpec);
                     col.path = dotpath + '.' + field.name;
-                    cols.add(col, null, true);
+                    cols.add(col, false, true, 
+                        {idl_field : field, idl_class : class_obj});
                 });
 
             } else {
@@ -1011,7 +1028,8 @@ angular.module('egGridMod',
                 nonsortable      : colSpec.nonsortable,
                 multisortable    : colSpec.multisortable,
                 nonmultisortable : colSpec.nonmultisortable,
-                dateformat       : colSpec.dateformat
+                dateformat       : colSpec.dateformat,
+                parentIdlClass   : colSpec.parentIdlClass
             };
         }
 
@@ -1019,7 +1037,7 @@ angular.module('egGridMod',
         // Add a column to the columns collection.
         // Columns may come from a slim eg-columns-field or 
         // directly from the IDL.
-        cols.add = function(colSpec, fromIDL, fromExpand) {
+        cols.add = function(colSpec, fromIDL, fromExpand, idl_info) {
 
             // First added column with the specified path takes precedence.
             // This allows for specific definitions followed by wildcard
@@ -1055,11 +1073,11 @@ angular.module('egGridMod',
             if (column.visible) 
                 cols.stockVisible.push(column.name);
 
-            if (fromIDL) return;
-            if (!cols.idlClass) return; // ad-hoc object
+            if (fromIDL) return; // directly from egIDL.  nothing left to do.
 
             // lookup the matching IDL field
-            var idl_info = cols.idlFieldFromPath(column.path);
+            if (!idl_info && cols.idlClass) 
+                idl_info = cols.idlFieldFromPath(column.path);
 
             if (!idl_info) {
                 // column is not represented within the IDL
@@ -1073,7 +1091,7 @@ angular.module('egGridMod',
                 column.label = idl_info.idl_field.label || column.name;
                 /*
                 // append class label to column label to better differentiate
-                // columsn in the selector.
+                // columns in the selector.
                 // Disabled for now, since it results in columns w/ really
                 // long names, making the grid unappealing when any of
                 // these colmns are selected.