lp1538678 Apply Warning Prompt when leaving dirty MARC editor
authorKyle Huckins <khuckins@catalyte.io>
Wed, 17 Apr 2019 22:55:49 +0000 (22:55 +0000)
committerBill Erickson <berickxx@gmail.com>
Mon, 20 May 2019 20:49:19 +0000 (16:49 -0400)
- Check for unsaved user input when leaving the Create New
MARC Record UI, and warn if it exists.

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>

 Changes to be committed:
modified:   services/marcedit.js

Signed-off-by: Bill Erickson <berickxx@gmail.com>

Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 4d2f9c9..81ff40d 100644 (file)
@@ -704,6 +704,19 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 if (typeof $scope.onSaveCallback !== 'undefined' && !angular.isArray($scope.onSaveCallback))
                     $scope.onSaveCallback = [ $scope.onSaveCallback ];
 
+                $scope.$watch('dirtyFlag',
+                    function(newVal, oldVal) {
+                        if (newVal && newVal != oldVal && !$scope.opac_iframe) {
+                            $($window).on('beforeunload', function(){
+                                return 'There is unsaved data in this record.'
+                            });
+                        } else {
+                            if (!$scope.opac_iframe)
+                                $($window).off('beforeunload');
+                        }
+                    }
+                );
+
                 MARC21.Record.delimiter = '$';
 
                 $scope.enable_fast_add = false;
@@ -1426,6 +1439,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                         return egCore.pcrud.create(
                             $scope.Record()
                         ).then(function(bre) {
+                            $scope.dirtyFlag = false;
                             $scope.recordId = bre.id(); 
                             $scope.caretRecId = $scope.recordId;
                             if ($scope.enable_fast_add) {