grid persist only stores necessary data
authorBill Erickson <berick@esilibrary.com>
Tue, 8 Jul 2014 18:16:53 +0000 (14:16 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 8 Jul 2014 18:16:53 +0000 (14:16 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/grid.js

index 9c01269..416afb6 100644 (file)
@@ -277,19 +277,20 @@ angular.module('egGridMod',
                         "Cannot save settings without a grid persist-key");
                     return;
                 }
-                var conf = grid.columnsProvider.columns.map(
-                    function(col) {
-                        var c = {
-                            name : col.name,
-                            flex : col.flex,
-                        };
-                        // preserve prefs space by only storing values that
-                        // are non-default
-                        if (Number(col.sort)) c.sort = Number(col.sort);
-                        if (Boolean(col.visible)) c.visible = true;
-                        return c;
-                    }
-                );
+
+                // only store information about visible columns.
+                var conf = grid.columnsProvider.columns.filter(
+                    function(col) {return Boolean(col.visible) });
+
+                // now scrunch the data down to just the needed info
+                conf = conf.map(function(col) {
+                    var c = {name : col.name}
+                    // Apart from the name, only store non-default values.
+                    // No need to store col.visible, since that's implicit
+                    if (col.flex != 2) c.flex = col.flex;
+                    if (Number(col.sort)) c.sort = Number(c.sort);
+                    return c;
+                });
 
                 egCore.hatch.setItem('eg.grid.' + grid.persistKey, conf)
                 .then(function() { 
@@ -323,19 +324,23 @@ angular.module('egGridMod',
                             return;
                         }
 
-                        grid_col.flex = col.flex;
+                        grid_col.flex = col.flex || 2;
                         grid_col.sort = col.sort || 0;
-                        grid_col.visible = col.visible || false;
+                        // all saved columns are assumed to be true
+                        grid_col.visible = true;
                         new_cols.push(grid_col);
                     });
 
-                    // check for new columns which are not yet expressed
-                    // within the saved configuration and tack them onto
-                    // the end of the columns list
+                    // columns which are not expressed within the saved 
+                    // configuration are marked as non-visible and 
+                    // appended to the end of the new list of columns.
                     angular.forEach(columns, function(col) {
                         var found = conf.filter(
                             function(c) {return (c.name == col.name)})[0];
-                        if (!found) new_cols.push(col);
+                        if (!found) {
+                            col.visible = false;
+                            new_cols.push(col);
+                        }
                     });
 
                     grid.columnsProvider.columns = new_cols;