webstaff: implement creating scap from a pattern template
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 May 2017 21:59:02 +0000 (17:59 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 May 2017 21:59:02 +0000 (17:59 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/t_prediction_manager.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/prediction_manager.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index 5a95ff1..68e47d9 100644 (file)
@@ -6,6 +6,9 @@
   <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="importScapFromSpt()">[% l('Create from Template') %]</button>
+    <select ng-model="active_pattern_template.id" ng-options="spt as spt.name for spt in pattern_templates track by spt.id"> 
+    </select>
   </div>
   <div class="row" ng-if="new_prediction">
     <ng-form name="new_prediction.predform" class="form-inline">
               <option value="supplement">[% l('Supplement') %]</option>
               <option value="index">[% l('Index') %]</option>
           </select>
-          <button class="btn btn-default" ng-click="openPatternEditorDialog(new_prediction)">[% l('Create Pattern') %]</button>
+          <button class="btn btn-default" ng-if="new_prediction.pattern_code === null"
+                  ng-click="openPatternEditorDialog(new_prediction)">[% l('Create Pattern') %]</button>
+          <button class="btn btn-default" ng-if="new_prediction.pattern_code !== null"
+                  ng-click="openPatternEditorDialog(new_prediction)">[% l('Edit Pattern') %]</button>
         </div>
       <div>
           <button type="submit" class="btn btn-default" ng-click="cancelNewScap()">[% l('Cancel') %]</button>
index a8567a2..d0ed636 100644 (file)
@@ -22,6 +22,13 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
     function reload(ssubId) {
         var ssub = egSerialsCoreSvc.get_ssub(ssubId);
         $scope.predictions = egCore.idl.toTypedHash(ssub.scaps());
+        egSerialsCoreSvc.fetch_spt().then(function() {
+            $scope.pattern_templates = egCore.idl.toTypedHash(egSerialsCoreSvc.sptList);
+            $scope.active_pattern_template = { id : null };
+            if ($scope.pattern_templates.length > 0) {
+                $scope.active_pattern_template.id = $scope.pattern_templates[0].id;
+            }
+        });
     }
 
     $scope.$watch('ssubId', function(newVal, oldVal) {
@@ -74,10 +81,25 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         $scope.new_prediction.active = true;
         $scope.new_prediction.create_date = new Date();
         $scope.new_prediction.subscription = $scope.ssubId;
+        $scope.new_prediction.pattern_code = null;
     }
 
     $scope.importScapFromBibRecord = function() {
     }
+    
+    $scope.importScapFromSpt = function() {
+        $scope.new_prediction = egCore.idl.toTypedHash(new egCore.idl.scap());
+        $scope.new_prediction.type = 'basic';
+        $scope.new_prediction.active = true;
+        $scope.new_prediction.create_date = new Date();
+        $scope.new_prediction.subscription = $scope.ssubId;
+        for (var i = 0; i < $scope.pattern_templates.length; i++) {
+            if ($scope.pattern_templates[i].id == $scope.active_pattern_template.id) {
+                $scope.new_prediction.pattern_code = $scope.pattern_templates[i].pattern_code;
+                break;
+            }
+        }
+    }
 
     $scope.openPatternEditorDialog = function(pred) {
         $uibModal.open({
index 35a1643..3394585 100644 (file)
@@ -6,7 +6,8 @@ function(egCore , orderByFilter , $q) {
         bibId : null,
         subId : null,
         subTree : [],
-        subList : []
+        subList : [],
+        sptList : []
     };
 
     // fetch subscription, distributions, streams, captions,
@@ -162,5 +163,17 @@ function(egCore , orderByFilter , $q) {
         }
     }
 
+    service.fetch_spt = function() {
+        return egCore.net.request(
+            'open-ils.serial',
+            'open-ils.serial.pattern_template.retrieve.at.atomic',
+            egCore.auth.token(),
+            egCore.auth.user().ws_ou()
+        ).then(function(list) {
+            service.sptList.length = 0;
+            angular.extend(service.sptList, list);
+        });
+    }
+
     return service;
 }]);