WIP use BroadcastChannel API to refresh holdings after VolcopyEditor update in child tab user/cesardv/lp1684202-bChannel_refresh_holdings_onvolcopy_tabsave
authorCesar Velez <cesar.velez@equinoxinitiative.org>
Fri, 17 Aug 2018 11:15:57 +0000 (07:15 -0400)
committerCesar Velez <cesar.velez@equinoxinitiative.org>
Wed, 5 Sep 2018 14:31:05 +0000 (10:31 -0400)
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js

index 43af4d5..34df7bf 100644 (file)
@@ -729,6 +729,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     // ------------------------------------------------------------------
     // Holdings
 
+
     $scope.holdingsGridControls = {
         activateItem : function (item) {
             $scope.selectedHoldingsVolCopyEdit();
@@ -1077,6 +1078,28 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         });
     }
 
+    var holdings_bChannel = undefined;
+    // subscribe to BroadcastChannel for any child VolCopy tabs
+    // refresh grid if needed to show new updates
+    // if ($scope.record_tab === 'holdings'){
+    $scope.$watch('record_tab', function(n){
+    
+        if (n === 'holdings'){
+            // we're in holdings tab, connect 2 bChannel
+            holdings_bChannel = new BroadcastChannel('volcopy_update');
+            holdings_bChannel.onmessage = function(e){
+                console.log("Getting Broadcast from volcopy_update for bib=" + e.data.record);
+                if ($scope.record_id == e.data.record){ // it's for us, refresh grid!
+                    $scope.holdings_record_id_changed($scope.record_id);
+                }
+            };
+
+        } else if (holdings_bChannel){ // we're leaving holding tab, close bChannel
+            holdings_bChannel.close();
+        }
+    
+    });
+
     // refresh the list of holdings when the record_id is changed.
     $scope.holdings_record_id_changed = function(id) {
         if ($scope.record_id != id) $scope.record_id = id;
index 72fee0e..3f4713a 100644 (file)
@@ -1835,7 +1835,14 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                             }
                         });
                     } else {
-                        $timeout(function(){$window.close()});
+                        $timeout(function(){
+                            var bChannel = new BroadcastChannel("volcopy_update");
+                            var bre_id = cnList && cnList.length > 0 ? cnList[0].record() : -1;
+                            var msg = {copies: copy_ids, record: bre_id};
+                            bChannel.postMessage(msg);
+
+                            $window.close();
+                        });
                     }
                 }
             });