webstaff: Clone Subscription action
authorJason Etheridge <jason@esilibrary.com>
Thu, 11 May 2017 03:23:59 +0000 (23:23 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:44 +0000 (12:06 -0400)
under Manage Subscriptions

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/src/templates/staff/serials/index.tt2
Open-ILS/src/templates/staff/serials/t_clone_subscription.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js

index e37504d..e95f8a8 100644 (file)
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/prediction_manager.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/serials/directives/prediction_wizard.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/cat/services/record.js"></script>
-
+<script>
+angular.module('egCoreMod').run(['egStrings', function(s) {
+    s.SERIALS_SUBSCRIPTION_SUCCESS_CLONE = "[% l('Cloned serial subscription') %]";
+    s.SERIALS_SUBSCRIPTION_FAIL_CLONE = "[% l('Failed to clone serial subscription') %]";
+}]);
+</script>
 [% END %]
 
 <div ng-view></div>
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 (file)
index 0000000..038a57f
--- /dev/null
@@ -0,0 +1,57 @@
+<form ng-submit="ok(args)" role="form">
+    <div class="modal-header">
+        <button type="button" class="close" ng-click="cancel()" 
+        aria-hidden="true">&times;</button>
+        <h4 ng-show="subs.length==1" class="modal-title">[% l('Clone Subscription') %]</h4>
+        <h4 ng-show="subs.length>1" class="modal-title">[% l('Clone Subscriptions') %]</h4>
+    </div>
+    <div class="modal-body">
+        <p>[% l('This feature will clone the selected subscriptions and all of their subscription notes, distributions, distribution notes, captions and patterns, streams, and routing list users.') %]</p>
+        <p>[% l('Holdings-related objects, like issuances, items, units, and summaries will not be cloned.') %]</p>
+        <p ng-show="subs.length == 1">[% l('To which bibliographic record should the new subscription be attached?') %]</p>
+        <p ng-show="subs.length > 1">[% l('To which bibliographic record should the new subscriptions be attached?') %]</p>
+        <div class="row">
+            <div class="col-md-1">
+                <input type="radio" name="which_radio_button" id="same_bib"
+                    ng-model="args.which_radio_button" value="same_bib">
+                </input>
+            </div>
+            <div class="col-md-11">
+                <label ng-if="subs.length==1" for="same_bib">
+                    [% l('Same record as the selected subscription') %]
+                </label>
+                <label ng-if="subs.length>1" for="same_bib">
+                    [% l('Same record as the selected subscriptions') %]
+                </label>
+            </div>
+        </div>
+        <div class="row">
+            <div class="col-md-1">
+                <input type="radio" name="which_radio_button"
+                    ng-model="args.which_radio_button" value="different_bib">
+                </input>
+            </div>
+            <div class="col-md-3">
+                <label for="different_bib">
+                    [% l('Record specified by this Bid ID:') %]
+                </label>
+            </div>
+            <div class="col-md-8">
+                <input type="number" class="form-control" min="1"
+                    ng-click="args.which_radio_button='different_bib'"
+                    ng-model-options="{ debounce: 1000 }"
+                    id="different_bib" ng-model="args.bib_id"/>
+                <div ng-show="args.bib_id">{{mvr.title}}</div>
+                <div class="alert alert-warning" ng-show="bibNotFound">
+                    [% l('Not Found') %]
+                </div>
+            </div>
+        </div>
+    </div>
+    <div class="modal-footer">
+        <input
+            ng-disabled="!args.which_radio_button||(args.which_radio_button=='different_bib'&&(!args.bib_id||bibNotFound))"
+            type="submit" class="btn btn-primary" value="[% l('OK') %]"/>
+        <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+    </div>
+</form>
index 0af6533..da2a9c5 100644 (file)
@@ -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 ) {