From d69daf1e7ac4bd41c186224fcf66a180fb088524 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Wed, 11 Feb 2015 19:47:59 -0500 Subject: [PATCH] LP#1402797 Should prompt when there is unsaved data, but does not. More to do... Signed-off-by: Mike Rylander Signed-off-by: Bill Erickson --- .../web/js/ui/default/staff/cat/services/marcedit.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js index 6b517ab1b8..ae699b25b5 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js @@ -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(); -- 2.11.0