webstaff: Toward dirty data flag and better prev/next/start/end buttons
authorMike Rylander <mrylander@gmail.com>
Thu, 12 Mar 2015 02:26:08 +0000 (22:26 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Wed, 19 Aug 2015 17:39:13 +0000 (13:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/catalog/t_catalog.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 89fe91a..8a585d7 100644 (file)
@@ -24,7 +24,7 @@
     <button type="button" ng-disabled="from_route" class="btn btn-default" ng-click="opac_call('rdetailEnd')">
        [% l('End') %]
     </button>
-    <button type="button" ng-disabled="from_route" class="btn btn-default" ng-click="opac_call('rdetailBackToResults')">
+    <button type="button" ng-disabled="from_route" class="btn btn-default" ng-click="opac_call('rdetailBackToResults', true)">
        [% l('Back To Results') %]
     </button>
   </div> <!-- padding -->
@@ -64,7 +64,7 @@
   </div>
   <!-- ng-if the remaining tabs so they can be instantiated on demand -->
   <div ng-if="record_tab == 'marc_edit'">
-    <eg-marc-edit-record record-id="record_id"></eg-marc-edit-record>
+    <eg-marc-edit-record dirty-flag="stop_unload" record-id="record_id"></eg-marc-edit-record>
   </div>
   <div ng-if="record_tab == 'marc_html'">
     <eg-record-html record-id="record_id"></eg-record-html>
index c6487e2..64d4efd 100644 (file)
@@ -130,10 +130,26 @@ function($scope , $routeParams , $location , $q , egCore , egHolds,
 
     // will hold a ref to the opac iframe
     $scope.opac_iframe = null;
-    $scope.opac_call = function (thing) {
-        if ($scope.opac_iframe) $scope.opac_iframe.contentWindow[thing]()
+    $scope.opac_call = function (opac_frame_function, force_opac_tab) {
+        if ($scope.opac_iframe) {
+            if (force_opac_tab) $scope.record_tab = 'catalog';
+            $scope.opac_iframe.contentWindow[opac_frame_function]();
+        }
     }
 
+    $scope.stop_unload = false;
+    $scope.$watch('stop_unload',
+        function(newVal, oldVal) {
+            if (newVal && newVal != oldVal && $scope.opac_iframe) {
+                $($scope.opac_iframe.contentWindow).on('beforeunload', function(){
+                    return 'There is unsaved data in this record.'
+                });
+            } else {
+                $($scope.opac_iframe.contentWindow).off('beforeunload');
+            }
+        }
+    );
+
     // Set the "last bib" cookie, if we have that
     if ($scope.record_id)
         egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
index 641bdd9..65c36a1 100644 (file)
@@ -274,7 +274,12 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
         templateUrl : './cat/share/t_marcedit',
         restrict: 'E',
         replace: true,
-        scope: { recordId : '=', recordType : '@', maxUndo : '@' },
+        scope: {
+            dirtyFlag : '=',
+            recordId : '=',
+            recordType : '@',
+            maxUndo : '@'
+        },
         link: function (scope, element, attrs) {
 
             element.bind('click', function(e) {;
@@ -663,14 +668,13 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                             $scope.force_render = false;
                         }
 
-                        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.save_stack_depth) {
+                        console.log('should get a listener... does not');
+                        $scope.dirtyFlag = true;
+                    } else {
+                        $scope.dirtyFlag = false;
                     }
 
                     if ($scope.record_undo_stack.length > $scope.max_undo)