LP#1676608: conditionally enable manage copy alerts button on item status details
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 7 Feb 2018 21:30:04 +0000 (16:30 -0500)
committerMike Rylander <mrylander@gmail.com>
Wed, 28 Feb 2018 15:26:42 +0000 (10:26 -0500)
The 'Manage' button for copy alerts on the Item Status Detail view
is now enabled only if there is at least one active copy alert. This
patch also tweaks how the copy alert dialogs sequence record update
and modal-closing so that the caller can be sure that the transaction
has committed.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/cat/item/t_summary_pane.tt2
Open-ILS/web/js/ui/default/staff/cat/item/app.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index a5dbbdd..3ef0b35 100644 (file)
     <div class="flex-cell">[% l('Copy Alerts') %]</div>
     <div class="flex-cell" id="item-status-alert-msg">
       <button class="btn btn-default" ng-click="addCopyAlerts(copy.id())" >[% l('Add') %]</button>
-      <button class="btn btn-default" ng-click="manageCopyAlerts(copy.id())" >[% l('Manage') %]</button>
+      <button class="btn btn-default" ng-disabled="!copy_alert_count" ng-click="manageCopyAlerts(copy.id())" >[% l('Manage') %]</button>
     </div>
     <!-- hack to adjust positioning -->
     <div class="flex-cell"></div>
index 2a3d7a7..1effdca 100644 (file)
@@ -566,6 +566,9 @@ function($scope , $q , $location , $routeParams , $timeout , $window , egCore ,
 
     // use the cached record info
     if (itemSvc.copy) {
+        $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
+            return !aca.ack_time();
+        }).length;
         $scope.recordId = itemSvc.copy.call_number().record().id();
         $scope.args.recordId = $scope.recordId;
         $scope.args.cnId = itemSvc.copy.call_number().id();
@@ -588,6 +591,9 @@ function($scope , $q , $location , $routeParams , $timeout , $window , egCore ,
         // regardless of whether it matches the current item.
         if (!barcode && itemSvc.copy && itemSvc.copy.id() == copyId) {
             $scope.copy = itemSvc.copy;
+            $scope.copy_alert_count = itemSvc.copy.copy_alerts().filter(function(aca) {
+                return !aca.ack_time();
+            }).length;
             $scope.recordId = itemSvc.copy.call_number().record().id();
             $scope.args.recordId = $scope.recordId;
             $scope.args.cnId = itemSvc.copy.call_number().id();
@@ -620,6 +626,10 @@ function($scope , $q , $location , $routeParams , $timeout , $window , egCore ,
 
 
             $scope.copy = copy;
+            $scope.copy_alert_count = copy.copy_alerts().filter(function(aca) {
+                return !aca.ack_time();
+            }).length;
+console.debug($scope.copy_alert_count);
             $scope.recordId = copy.call_number().record().id();
             $scope.args.recordId = $scope.recordId;
             $scope.args.cnId = itemSvc.copy.call_number().id();
@@ -969,12 +979,14 @@ function($scope , $q , $location , $routeParams , $timeout , $window , egCore ,
 
     $scope.addCopyAlerts = function(copy_id) {
         egCirc.add_copy_alerts([copy_id]).then(function() {
-            // update grid items?
+            // force a refresh
+            loadCopy($scope.copy.barcode()).then(loadTabData);
         });
     }
     $scope.manageCopyAlerts = function(copy_id) {
         egCirc.manage_copy_alerts([copy_id]).then(function() {
-            // update grid items?
+            // force a refresh
+            loadCopy($scope.copy.barcode()).then(loadTabData);
         });
     }
 
index 1a3f822..fb48ea0 100644 (file)
@@ -683,11 +683,15 @@ function($uibModal , $interpolate , egCore) {
                                 copy_alerts.push( a );
                             });
                             if (copy_alerts.length > 0) {
-                                egCore.pcrud.apply(copy_alerts);
+                                egCore.pcrud.apply(copy_alerts).finally(function() {
+                                    if (args.ok) args.ok();
+                                    $uibModalInstance.close()
+                                });
                             }
+                        } else {
+                            if (args.ok) args.ok();
+                            $uibModalInstance.close()
                         }
-                        if (args.ok) args.ok();
-                        $uibModalInstance.close()
                     }
                     $scope.cancel = function() {
                         if (args.cancel) args.cancel();
@@ -804,10 +808,14 @@ function($uibModal , $interpolate , egCore) {
                             }
                         });
                         if (acks.length > 0) {
-                            egCore.pcrud.apply(acks);
+                            egCore.pcrud.apply(acks).finally(function() {
+                                if (args.ok) args.ok($scope.params.the_next_status);
+                                $uibModalInstance.close()
+                            });
+                        } else {
+                            if (args.ok) args.ok($scope.params.the_next_status);
+                            $uibModalInstance.close()
                         }
-                        if (args.ok) args.ok($scope.params.the_next_status);
-                        $uibModalInstance.close()
                     }
                     $scope.cancel = function() {
                         if (args.cancel) args.cancel();
@@ -870,8 +878,9 @@ function($uibModal , $interpolate , egCore) {
                     });
 
                     $scope.ok = function() {
-                        egCore.pcrud.apply($scope.copy_alert_list);
-                        $uibModalInstance.close()
+                        egCore.pcrud.apply($scope.copy_alert_list).finally(function() {
+                            $uibModalInstance.close();
+                        });
                     }
                     $scope.cancel = function() {
                         if (args.cancel) args.cancel();