From: Kyle Huckins <khuckins@catalyte.io>
Date: Wed, 17 Apr 2019 22:55:49 +0000 (+0000)
Subject: lp1538678 Apply Warning Prompt when leaving dirty MARC editor
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d13e2e16963de592bdf71a9795e26acc1b4af2b6;p=evergreen%2Fjoelewis.git

lp1538678 Apply Warning Prompt when leaving dirty MARC editor

- 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>
---

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 4d2f9c97a5..81ff40d8b9 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
@@ -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) {