webstaff: Teach the grid how to flesh the last step in a path if it is unfleshed
authorMike Rylander <mrylander@gmail.com>
Tue, 18 Aug 2015 21:26:58 +0000 (17:26 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:15 +0000 (15:44 -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/web/js/ui/default/staff/services/grid.js

index c93bca2..b7c1ce3 100644 (file)
@@ -979,6 +979,7 @@ angular.module('egGridMod',
         require : '^egGrid',
         restrict : 'AE',
         scope : {
+            flesher: '=', // optional; function that can flesh a linked field, given the value
             name  : '@', // required; unique name
             path  : '@', // optional; flesh path
             ignore: '@', // optional; fields to ignore when path is a wildcard
@@ -1241,6 +1242,7 @@ angular.module('egGridMod',
         // the fields over that we need (so the scope object can go away).
         cols.cloneFromScope = function(colSpec) {
             return {
+                flesher  : colSpec.flesher,
                 name  : colSpec.name,
                 label : colSpec.label,
                 path  : colSpec.path,
@@ -1421,15 +1423,18 @@ angular.module('egGridMod',
             // TODO: consider a caching layer to speed up template 
             // rendering, particularly for nested objects?
             gridData.itemFieldValue = function(item, column) {
+                var val;
                 if (column.name in item) {
                     if (typeof item[column.name] == 'function') {
-                        return item[column.name]();
+                        val = item[column.name]();
                     } else {
-                        return item[column.name];
+                        val = item[column.name];
                     }
                 } else {
-                    return gridData.nestedItemFieldValue(item, column);
+                    val = gridData.nestedItemFieldValue(item, column);
                 }
+
+                return val;
             }
 
             // TODO: deprecate me
@@ -1445,6 +1450,8 @@ angular.module('egGridMod',
             // value is an IDL field, run the value through its
             // corresponding output filter.
             gridData.nestedItemFieldValue = function(obj, column) {
+                item = obj; // keep a copy around
+
                 if (obj === null || obj === undefined || obj === '') return '';
                 if (!column.path) return obj;
 
@@ -1453,9 +1460,13 @@ angular.module('egGridMod',
 
                 angular.forEach(parts, function(step, idx) {
                     // object is not fleshed to the expected extent
-                    if (!obj || typeof obj != 'object') {
-                        obj = '';
-                        return;
+                    if (typeof obj != 'object') {
+                        if (typeof obj != 'undefined' && column.flesher) {
+                            obj = column.flesher(obj, column, item);
+                        } else {
+                            obj = '';
+                            return;
+                        }
                     }
 
                     var cls = obj.classname;