webstaff: add subscription ID to serials routes
authorGalen Charlton <gmc@equinoxinitiative.org>
Mon, 24 Apr 2017 21:52:56 +0000 (17:52 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 24 Apr 2017 21:52:56 +0000 (17:52 -0400)
Teach the serials app to recognize the subscription ID if supplied
in the path. The subscription ID is validated against the bib record;
if it doesn't belong to the bib, the path is rewritten to
drop it.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/serials/app.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index e65ae41..7cd7a34 100644 (file)
@@ -26,11 +26,29 @@ angular.module('egSerialsApp')
         controller: 'ManageCtrl',
         resolve : resolver
     });
+
+    $routeProvider.when('/serials/:bib_id/:active_tab/:subscription_id', {
+        templateUrl: './serials/t_manage',
+        controller: 'ManageCtrl',
+        resolve : resolver
+    });
 })
 
 .controller('ManageCtrl',
-       ['$scope','$routeParams','$location',
-function($scope , $routeParams , $location) {
+       ['$scope','$routeParams','$location','egSerialsCoreSvc',
+function($scope , $routeParams , $location , egSerialsCoreSvc) {
     $scope.bib_id = $routeParams.bib_id;
     $scope.active_tab = $routeParams.active_tab ?  $routeParams.active_tab : 'manage-subscriptions';
+    $scope.ssub_id = null;
+    if ($routeParams.subscription_id) {
+        egSerialsCoreSvc.verify_subscription_id($scope.bib_id, $routeParams.subscription_id)
+        .then(function(verified) {
+            if (verified) {
+                $scope.ssub_id = $routeParams.subscription_id;
+            } else {
+                // subscription ID is no good, so drop it from the URL
+                $location.path('/serials/' + $scope.bib_id + '/' + $scope.active_tab);
+            }
+        });
+    }
 }])
index e40a08c..d138df4 100644 (file)
@@ -1,7 +1,7 @@
 angular.module('egSerialsMod', ['egCoreMod'])
 .factory('egSerialsCoreSvc',
-       ['egCore','orderByFilter',
-function(egCore , orderByFilter) {
+       ['egCore','orderByFilter','$q',
+function(egCore , orderByFilter , $q) {
     var service = {
         bibId : null,
         subId : null,
@@ -134,5 +134,23 @@ function(egCore , orderByFilter) {
         });
     }
 
+    // verify that a subscription ID and bib ID are actually
+    // associated with each other
+    service.verify_subscription_id = function(bibId, ssubId) {
+        var deferred = $q.defer();
+        egCore.pcrud.search('ssub', {
+                record_entry : bibId,
+                id           : ssubId
+        }, {}, { atomic : true, idlist : true }
+        ).then(function(list) {
+            if (list.length == 1) {
+                deferred.resolve(true);
+            } else {
+                deferred.resolve(false);
+            }
+        });
+        return deferred.promise;
+    }
+
     return service;
 }]);