From: Jason Etheridge Date: Thu, 11 May 2017 03:23:59 +0000 (-0400) Subject: webstaff: Clone Subscription action X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4e74d3d4c4109a2ed29da3e3806f21f8dc84a003;p=working%2FEvergreen.git webstaff: Clone Subscription action under Manage Subscriptions Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/templates/staff/serials/index.tt2 b/Open-ILS/src/templates/staff/serials/index.tt2 index e37504dff5..e95f8a8a81 100644 --- a/Open-ILS/src/templates/staff/serials/index.tt2 +++ b/Open-ILS/src/templates/staff/serials/index.tt2 @@ -13,7 +13,12 @@ - + [% END %]
diff --git a/Open-ILS/src/templates/staff/serials/t_clone_subscription.tt2 b/Open-ILS/src/templates/staff/serials/t_clone_subscription.tt2 new file mode 100644 index 0000000000..038a57f543 --- /dev/null +++ b/Open-ILS/src/templates/staff/serials/t_clone_subscription.tt2 @@ -0,0 +1,57 @@ +
+ + + +
diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js b/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js index 0af65337df..da2a9c576d 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js @@ -10,9 +10,9 @@ angular.module('egSerialsAppDep') templateUrl: './serials/t_subscription_manager', controller: ['$scope','$q','egSerialsCoreSvc','egCore','egGridDataProvider', - '$uibModal', + '$uibModal','ngToast', function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , - $uibModal) { + $uibModal , ngToast ) { egSerialsCoreSvc.fetch($scope.bibId).then(function() { $scope.subscriptions = egCore.idl.toTypedHash(egSerialsCoreSvc.subTree); $scope.distStreamGridDataProvider.refresh(); @@ -188,10 +188,116 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , }); } } + $scope.clone_subscription = function(rows) { + if (!rows) { return; } + var row = rows[0]; + $uibModal.open({ + templateUrl: './serials/t_clone_subscription', + controller: 'CloneCtrl', + resolve : { + subs : function() { + return rows; + } + }, + windowClass: 'app-modal-window', + backdrop: 'static', + keyboard: false + }).result.then(function(args) { + var promises = []; + var some_failure = false; + var some_success = false; + var seen = {}; + angular.forEach(rows, function(row) { + console.log(row); + if (!seen[row.id]) { + seen[row.id] = 1; + promises.push( + egCore.net.request( + 'open-ils.serial', + 'open-ils.serial.subscription.clone', + egCore.auth.token(), + row.id, + args.bib_id + ).then( + function(resp) { + var evt = egCore.evt.parse(resp); + if (evt) { // any way to just throw or return this to the error handler? + console.log('failure',resp); + some_failure = true; + ngToast.danger(egCore.strings.SERIALS_SUBSCRIPTION_FAIL_CLONE); + } else { + console.log('success',resp); + some_success = true; + ngToast.success(egCore.strings.SERIALS_SUBSCRIPTION_SUCCESS_CLONE); + } + }, + function(resp) { + console.log('failure',resp); + some_failure = true; + ngToast.danger(egCore.strings.SERIALS_SUBSCRIPTION_FAIL_CLONE); + } + ) + ); + } + }); + $q.all(promises).then(function() { + reload(); + }); + }); + } + }] } }) +.controller('CloneCtrl', + ['$scope','$uibModalInstance','egCore','subs', +function($scope , $uibModalInstance , egCore , subs ) { + $scope.args = {}; + $scope.ok = function(count) { $uibModalInstance.close($scope.args) } + $scope.cancel = function () { $uibModalInstance.dismiss() } + $scope.subs = subs; + $scope.find_bib = function () { + + $scope.bibNotFound = null; + $scope.mvr = null; + if (!$scope.args.bib_id) return; + + return egCore.net.request( + 'open-ils.search', + 'open-ils.search.biblio.record.mods_slim.retrieve.authoritative', + $scope.args.bib_id + ).then( + function(resp) { // maybe success + + if (evt = egCore.evt.parse(resp)) { + $scope.bibNotFound = $scope.args.bib_id; + console.error(evt.toString()); + return; + } + + if (!resp) { + $scope.bibNotFound = $scope.args.bib_id; + return; + } + + $scope.mvr = egCore.idl.toHash(resp); + console.log($scope.mvr); + }, + function(resp) { // outright failure + console.error(resp); + $scope.bibNotFound = $scope.args.bib_id; + return; + } + ); + } + $scope.$watch("args.bib_id", function(newVal, oldVal) { + if (newVal && newVal != oldVal) { + $scope.find_bib(); + } + }); +}]) + .controller('RoutingCtrl', ['$scope','$uibModalInstance','egCore','rowInfo','routes', function($scope , $uibModalInstance , egCore , rowInfo , routes ) {