webstaff: implement import patterns from bibliographic/mfhd records
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 25 May 2017 22:45:01 +0000 (18:45 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:51 +0000 (12:06 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/t_prediction_manager.tt2
Open-ILS/src/templates/staff/serials/t_select_pattern_dialog.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index 343f636..24c9c41 100644 (file)
@@ -5,7 +5,7 @@
 <div>
   <div class="pad-vert">
     <button class="btn btn-warning" ng-click="startNewScap()">[% l('Add New') %]</button>
-    <button class="btn btn-warning" ng-click="importScapFromBibRecord()">[% l('Import from Bibliographic and/or MFHD Records') %]</button>
+    <button class="btn btn-warning" ng-click="importScapFromBibRecord()" ng-disabled="!has_pattern_to_import">[% l('Import from Bibliographic and/or MFHD Records') %]</button>
     <button class="btn btn-warning" ng-click="importScapFromSpt()">[% l('Create from Template') %]</button>
     <select ng-model="active_pattern_template.id" ng-options="spt.id as spt.name for spt in pattern_templates | orderBy:'name'"> 
     </select>
diff --git a/Open-ILS/src/templates/staff/serials/t_select_pattern_dialog.tt2 b/Open-ILS/src/templates/staff/serials/t_select_pattern_dialog.tt2
new file mode 100644 (file)
index 0000000..1f900d7
--- /dev/null
@@ -0,0 +1,32 @@
+<form ng-submit="ok()" role="form">
+<div class="modal-header">
+    <button type="button" class="close" ng-click="cancel()" 
+        aria-hidden="true">&times;</button>
+    <h4 class="modal-title">[% l('Select Patterns to Import') %]</h4>
+</div>
+
+<div class="modal-body">
+  <div ng-repeat="pot in potentials" class="row">
+    <div>
+      <div class="col-md-1">
+        <input type="checkbox" ng-model="pot.selected">
+      </div>
+      <div class="col-md-11">
+        <span ng-if="pot._classname == 'bre'">[% l('Bibliographic record [_1]', '{{pot.id}}') %]</span>
+        <span ng-if="pot._classname == 'sre'">[% l('MFHD record [_1]', '{{pot.id}}') %]</span>
+      </div>
+    </div>
+    <div>
+      <div class="col-md-1"></div>
+      <div class="col-md-11">
+        <pre>{{pot.desc}}</pre>
+      </div>
+    </div>
+  </div>
+</div>
+
+<div class="modal-footer">
+  <input type="submit" class="btn btn-primary" value="[% l('Import') %]"></input>
+  <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+</div>
+</form>
index 7cace14..eb58853 100644 (file)
@@ -15,8 +15,14 @@ angular.module('egSerialsAppDep')
 function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
          $uibModal , $timeout , $location) {
 
+    $scope.has_pattern_to_import = false;
     egSerialsCoreSvc.fetch($scope.bibId).then(function() {
         reload($scope.ssubId);
+        egSerialsCoreSvc.fetch_patterns_from_bibs_mfhds($scope.bibId).then(function() {
+            if (egSerialsCoreSvc.potentialPatternList.length > 0) {
+                $scope.has_pattern_to_import = true;
+            }
+        });
     });
 
     function reload(ssubId) {
@@ -85,6 +91,37 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
     }
 
     $scope.importScapFromBibRecord = function() {
+        $uibModal.open({
+            templateUrl: './serials/t_select_pattern_dialog',
+            size: 'md',
+            backdrop: 'static',
+            controller:
+                ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
+                $scope.focusMe = true;
+                $scope.potentials = egSerialsCoreSvc.potentialPatternList.slice();
+                $scope.ok = function(patternCode) { $uibModalInstance.close($scope.potentials) }
+                $scope.cancel = function () { $uibModalInstance.dismiss() }
+            }]
+        }).result.then(function (potentials) {
+            var marc = [];
+            angular.forEach(potentials, function(pot) {
+                if (pot.selected) {
+                    marc.push(pot.marc);
+                }
+            });
+            if (marc.length == 0) return;
+            egCore.net.request(
+                'open-ils.serial',
+                'open-ils.serial.caption_and_pattern.create_from_records',
+                egCore.auth.token(),
+                $scope.ssubId,
+                marc
+            ).then(function() {
+                egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+                    reload($scope.ssubId);
+                });
+            });
+        });
     }
     
     $scope.importScapFromSpt = function() {
index be44b93..7ec21ba 100644 (file)
@@ -10,6 +10,7 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         subList : [],
         sptList : [],
         mfhdList : [],
+        potentialPatternList : [],
         flatMfhdList : [],
         itemMap : {},
         itemTree : [],
@@ -121,6 +122,32 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         });
     }
 
+    service.fetch_patterns_from_bibs_mfhds = function(bibId) {
+        return egCore.net.request(
+            'open-ils.serial',
+            'open-ils.serial.caption_and_pattern.find_legacy_by_bib_record.atomic',
+            egCore.auth.token(),
+            bibId
+        ).then(function(list) {
+            service.potentialPatternList = egCore.idl.toTypedHash(list);
+            angular.forEach(service.potentialPatternList, function(pot) {
+                var rec = new MARC21.Record({ marcxml : pot.marc });
+                var pattern_fields = rec.fields.filter(function(f) {
+                    return (f.tag == '853' || f.tag == '854' || f.tag == '855');
+                });
+                pot.desc = '';
+                if (pattern_fields.length > 0) {
+                    // just take the first one
+                    var fld = pattern_fields[0];
+                    pot.desc = fld.tag + ' ' + fld.ind1 + fld.ind2 +
+                               fld.subfields.map(function(sf) { 
+                                 return '$' + sf[0] + sf[1]
+                               }).join('');
+                }
+            });
+        })
+    }
+
     // fetch subscription, distributions, streams, captions,
     // and notes associated with the indicated bib
     service.fetch = function(bibId, contextOrg) {