LP#1402797 Should prompt when there is unsaved data, but does not. More to do...
authorMike Rylander <mrylander@gmail.com>
Thu, 12 Feb 2015 00:47:59 +0000 (19:47 -0500)
committerBill Erickson <berickxx@gmail.com>
Wed, 25 Feb 2015 16:16:09 +0000 (11:16 -0500)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 6b517ab..ae699b2 100644 (file)
@@ -244,6 +244,9 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 $scope.in_undo = false;
                 $scope.in_redo = false;
                 $scope.record = new MARC.Record();
+                $scope.save_stack_depth = 0;
+                $scope.controlfields = [];
+                $scope.datafields = [];
 
                 $scope.onKeydown = function (event) {
                     var event_return = true;
@@ -286,6 +289,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                         $scope.record = new MARC.Record({ marcxml : $scope.bre.marc() });
                         $scope.controlfields = $scope.record.fields.filter(function(f){ return f.isControlfield() });
                         $scope.datafields = $scope.record.fields.filter(function(f){ return !f.isControlfield() });
+                        $scope.save_stack_depth = $scope.record_undo_stack.length;
                     }).then(setCaret);
                 }
 
@@ -296,6 +300,15 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                             target: $scope.current_event_target,
                             pos: $scope.current_event_target_cursor_pos
                         });
+
+                        if ($scope.record_undo_stack.length != $scope.save_stack_depth) {
+                            console.log('should get a listener... does not');
+                            $('body').on('beforeunload', function(){
+                                return 'There is unsaved data in this record.'
+                            });
+                        } else {
+                            $('body').off('beforeunload');
+                        }
                     }
 
                     if ($scope.record_undo_stack.length > $scope.max_undo)
@@ -369,10 +382,6 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     }
                 );
 
-
-                $scope.controlfields = [];
-                $scope.datafields = [];
-
                 if ($scope.recordId)
                     loadRecord();