webstaff: Link MFHD action
authorJason Etheridge <jason@esilibrary.com>
Fri, 12 May 2017 14:29:11 +0000 (10:29 -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_link_mfhd.tt2 [new file with mode: 0644]
Open-ILS/src/templates/staff/serials/t_subscription_manager.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/subscription_manager.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index e95f8a8..63e7f3a 100644 (file)
@@ -17,6 +17,8 @@
 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') %]";
+    s.SERIALS_DISTRIBUTION_SUCCESS_LINK_MFHD = "[% l('Distribution linked to MFHD') %]";
+    s.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD = "[% l('Failed to link distribution to MFHD') %]";
 }]);
 </script>
 [% END %]
diff --git a/Open-ILS/src/templates/staff/serials/t_link_mfhd.tt2 b/Open-ILS/src/templates/staff/serials/t_link_mfhd.tt2
new file mode 100644 (file)
index 0000000..0b423fd
--- /dev/null
@@ -0,0 +1,35 @@
+<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 class="modal-title">[% l('Link MFHD') %]</h4>
+    </div>
+    <div class="modal-body">
+        <div ng-repeat="legacy in legacies">
+            <div uib-tooltip="[% l('Record ID [_1]', '{{legacy.mvr.doc_id}}') %]" tooltip-placement="left">
+                <a target="_blank" href="/eg/staff/cat/catalog/record/{{legacy.mvr.doc_id}}">{{legacy.mvr.title}}</a>
+            </div>
+            <div>
+                {{legacy.mvr.physical_description}}
+            </div>
+            <div ng-repeat="svr in legacy.svrs" uib-tooltip="{{svr|json}}" tooltip-placement="left">
+                <input type="radio" name="which_mfhd" ng-model="args.which_mfhd" ng-value="svr.sre_id" id="{{svr.sre_id}}">
+                <label for="{{svr.sre_id}}">
+                    {{svr.location}}
+                </label>
+            </div>
+        </div>
+    <div class="modal-footer">
+        <div class="pull-left">
+            <label>[% l('Summary Display') %]</label>
+            <select ng-model="args.summary_method">
+                <option value="add_to_sre" selected>[% l('Both') %]</option>
+                <option value="merge_with_sre">[% l('Merge') %]</option>
+                <option value="use_sre_only">[% l('MFHD Only') %]</option>
+                <option value="use_sdist_only">[% l('None') %]</option>
+            </select>
+        </div>
+        <input type="submit" class="btn btn-primary" value="[% l('OK') %]" ng-disabled="!args.which_mfhd"/>
+        <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+    </div>
+</form>
index 1c15c0a..d0f2c28 100644 (file)
@@ -73,7 +73,7 @@
       label="[% l('Apply Binding Template') %]"></eg-grid-action>
     <eg-grid-action handler="additional_routing" disabled="need_one_selected"
       label="[% l('Additional Routing') %]"></eg-grid-action>
-    <eg-grid-action handler="link_mfhd"
+    <eg-grid-action handler="link_mfhd" disabled="need_one_selected"
       label="[% l('Link MFHD') %]"></eg-grid-action>
     <eg-grid-action handler="edit_offsets"
       label="[% l('Edit Offsets') %]"></eg-grid-action>
index da2a9c5..b7f8868 100644 (file)
@@ -208,7 +208,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
             var some_success = false;
             var seen = {};
             angular.forEach(rows, function(row) { 
-                console.log(row);
+                //console.log(row);
                 if (!seen[row.id]) {
                     seen[row.id] = 1;
                     promises.push(
@@ -245,11 +245,138 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
             });
         });
     }
+    $scope.link_mfhd = function(rows) {
+        if (!rows) { return; }
+        var row = rows[0];
+        if (!row['sdist.id']) { return; }
+        $uibModal.open({
+            templateUrl: './serials/t_link_mfhd',
+            controller: 'LinkMFHDCtrl',
+            resolve : {
+                row : function() {
+                    return rows[0];
+                },
+                bibId : function() {
+                    return $scope.bibId;
+                }
+            },
+            windowClass: 'app-modal-window',
+            backdrop: 'static',
+            keyboard: false
+        }).result.then(function(args) {
+            console.log('modal done', args);
+            egCore.pcrud.search('sdist', {
+                    id: rows[0]['sdist.id']
+                }, {}, { atomic : true }
+            ).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);
+                    ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD);
+                }
+                var sdist = resp[0];
+                sdist.ischanged(true);
+                sdist.summary_method( args.summary_method );
+                sdist.record_entry( args.which_mfhd );
+                egCore.pcrud.apply(sdist).then(
+                    function(resp) { // maybe success
+                        console.log('apply',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);
+                            ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD);
+                        } else {
+                            console.log('success',resp);
+                            ngToast.success(egCore.strings.SERIALS_DISTRIBUTION_SUCCESS_LINK_MFHD);
+                            reload();
+                        }
+                    },
+                    function(resp) {
+                        console.log('failure',resp);
+                        ngToast.danger(egCore.strings.SERIALS_DISTRIBUTION_FAIL_LINK_MFHD);
+                    }
+                );
+            });
+        });
+    }
 
 }]
     }
 })
 
+.controller('LinkMFHDCtrl',
+       ['$scope','$q','$uibModalInstance','egCore','row','bibId',
+function($scope , $q , $uibModalInstance , egCore , row , bibId ) {
+    console.log('row',row);
+    console.log('bibId',bibId);
+    $scope.args = {
+        summary_method: row['sdist.summary_method'] || 'add_to_sre',
+    };
+    if (row['sdist.record_entry']) {
+        $scope.args.which_mfhd = row['sdist.record_entry'].id;
+    }
+    $scope.ok = function(count) { $uibModalInstance.close($scope.args) }
+    $scope.cancel = function () { $uibModalInstance.dismiss() }
+    $scope.legacies = {};
+    egCore.pcrud.search('sre', {
+            record: bibId, owning_lib : row['owning_lib.id'], active: 't', deleted: 'f'
+        }, {}, { atomic : true }
+    ).then(
+        function(resp) { // maybe success
+            var evt; if (evt = egCore.evt.parse(resp)) { console.error(evt.toString()); return; }
+            if (!resp) { return; }
+
+            var promises = [];
+            var seen = {};
+
+            angular.forEach(resp, function(sre) {
+                console.log('sre',sre);
+                if (!seen[sre.record()]) {
+                    seen[sre.record()] = 1;
+                    $scope.legacies[sre.record()] = { mvr: null, svrs: [] };
+                    promises.push(
+                        egCore.net.request(
+                            'open-ils.search',
+                            'open-ils.search.biblio.record.mods_slim.retrieve.authoritative',
+                            sre.record()
+                        ).then(function(resp2) {
+                            var evt; if (evt = egCore.evt.parse(resp2)) { console.error(evt.toString()); return; }
+                            if (!resp2) { return; }
+                            $scope.legacies[sre.record()].mvr = egCore.idl.toHash(resp2);
+                        })
+                    );
+                    promises.push(
+                        egCore.net.request(
+                            'open-ils.search',
+                            'open-ils.search.serial.record.bib.retrieve',
+                            sre.record(),
+                            row['owning_lib.id']
+                        ).then(function(resp2) {
+                            angular.forEach(resp2,function(r) {
+                                if (r.sre_id() > 0) {
+                                    console.log('svr',egCore.idl.toHash(r));
+                                    $scope.legacies[sre.record()].svrs.push( egCore.idl.toHash(r) );
+                                }
+                            });
+                        })
+                    );
+                }
+                if (typeof $scope.legacies[sre.record()].sres == 'undefined') {
+                    $scope.legacies[sre.record()].sres = {};
+                }
+                $scope.legacies[sre.record()].sres[sre.id()] = egCore.idl.toHash(sre);
+            });
+
+            $q.all(promises).then(function(){
+                console.log('done',$scope.legacies);
+            });
+        },
+        function(resp) { // outright failure
+            console.error('failure',resp);
+        }
+    )
+}])
+
 .controller('CloneCtrl',
        ['$scope','$uibModalInstance','egCore','subs',
 function($scope , $uibModalInstance , egCore , subs ) {
@@ -282,7 +409,7 @@ function($scope , $uibModalInstance , egCore , subs ) {
                 }
 
                 $scope.mvr = egCore.idl.toHash(resp);
-                console.log($scope.mvr);
+                //console.log($scope.mvr);
             },
             function(resp) { // outright failure
                 console.error(resp);
index 2f69e04..35a1643 100644 (file)
@@ -46,6 +46,7 @@ function(egCore , orderByFilter , $q) {
             var _ssub = {
                 'id'                   : ssubHash.id,
                 'owning_lib.name'      : ssubHash.owning_lib.name,
+                'owning_lib.id'        : ssubHash.owning_lib.id,
                 'start_date'           : ssubHash.start_date,
                 'end_date'             : ssubHash.end_date,
                 'expected_date_offset' : ssubHash.expected_date_offset
@@ -61,6 +62,7 @@ function(egCore , orderByFilter , $q) {
                 angular.forEach([
                     'id',
                     'summary_method',
+                    'record_entry',
                     'label',
                     'display_grouping',
                     'unit_label_prefix',