webstaff: implement adding a new prediction
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 5 May 2017 21:34:11 +0000 (17:34 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 30 May 2017 16:06:41 +0000 (12:06 -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

index 2872034..cecf908 100644 (file)
@@ -3,6 +3,37 @@
 </div>
 
 <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>
+  </div>
+  <div ng-if="new_prediction">
+    <ng-form name="new_prediction.predform" class="form-inline">
+      <div class="col-md-1"><label>[% l('ID') %] {{new_prediction.id}}</label></div>
+      <div class="col-md-1">
+        <label class="checkbox-inline">
+          <input type="checkbox" ng-model="new_prediction.active">[% l('Active') %]
+        </label>
+      </div>
+      <div class="col-md-2">
+        <label>[% l('Start Date') %]</label>
+          {{new_prediction.create_date | date:"shortDate"}}
+      </div>
+      <div class="col-md-3">
+          <label>[% l('Type') %]</label>
+          <select ng-model="new_prediction.type">
+              <option value="basic">[% l('Basic') %]</option>
+              <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>
+        </div>
+      <div>
+          <button type="submit" class="btn btn-primary" ng-disabled="!new_prediction.predform.$dirty" ng-click="createScap(new_prediction)">[% l('Create') %]</button>
+      </div>
+    </form>
+  </div>
+  <h3>[% l('Existing Prediction Patterns') %]</h3>
   <div class="row" ng-repeat="pred in predictions | orderBy: 'id' as filtered track by pred.id">
     <ng-form name="pred.predform" class="form-inline">
     <div class="col-md-1"><label>[% l('ID') %] {{pred.id}}</label></div>
index 7be34ea..02f735e 100644 (file)
@@ -28,6 +28,18 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         if (newVal && newVal != oldVal) reload(newVal);
     });
 
+    $scope.createScap = function(pred) {
+        var scap = egCore.idl.fromTypedHash(pred);
+        egCore.pcrud.create(scap).then(function() {
+            // completely reset the model in order to reset the
+            // forms; causes a blink, alas
+            $scope.predictions = [];
+            $scope.new_prediction = null;
+            egSerialsCoreSvc.fetch($scope.bibId).then(function() {
+                reload($scope.ssubId);
+            });
+        });
+    }
     $scope.updateScap = function(pred) {
         var scap = egCore.idl.fromTypedHash(pred);
         egCore.pcrud.update(scap).then(function() {
@@ -40,6 +52,18 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider ,
         });
     }
 
+    $scope.startNewScap = 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;
+        $scope.new_pred = {};
+    }
+
+    $scope.importScapFromBibRecord = function() {
+    }
+
     $scope.openPatternEditorDialog = function(pred) {
         $uibModal.open({
             templateUrl: './serials/t_pattern_editor_dialog',