webstaff: fix creating PredictionPattern from null pattern code
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 5 May 2017 21:33:35 +0000 (17:33 -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/web/js/ui/default/staff/serials/directives/prediction_wizard.js

index 5ac7909..9d267c1 100644 (file)
@@ -27,12 +27,13 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
         this.use_chron = false;
         this.use_alt_chron = false;
         this.use_calendar_changes = false;
+        this.calendar_change = [];
         this.compress_expand = '3';
         this.caption_evaluation = '0';        
         this.enum_levels = [];
         this.alt_enum_levels = [];
         this.chron_levels = [];
-        this.alt_chron_levels = [];
+        this.alt_chron_levels = [{ caption : null, display_caption: false }];
         this.frequency_type = 'preset';
         this.use_regularity = false;
         this.regularity = [];
@@ -164,7 +165,6 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
                 }
                 if (sf == 'x') {
                     this.use_calendar_change = true;
-                    this.calendar_change = [];
                     value.split(',').forEach(function(chg) {
                         var calendar_change = {
                             type   : null,
@@ -241,6 +241,7 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
                 }
             }
         }
+
         if (self.frequency) {
             if (self.frequency.match(/^\d+$/)) {
                 self.frequency_type = 'numeric';
@@ -472,10 +473,27 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
                 return lvl.caption;
             }).join(', ');
         }
+
+        if (!patternCode) {
+            // starting from scratch, ensure there's
+            // enough so that the input wizard can be used
+            this.use_enum = true;
+            this.use_chron = true;
+            this.link = 0;
+            self.add_enum_level();
+            self.add_alt_enum_level();
+            self.add_chron_level();
+            self.add_calendar_change();
+            self.add_regularity();
+        }
     }
     // TODO chron only
 
-    $scope.pattern = new PredictionPattern(JSON.parse($scope.patternCode));
+    if ($scope.patternCode) {
+        $scope.pattern = new PredictionPattern(JSON.parse($scope.patternCode));
+    } else {
+        $scope.pattern = new PredictionPattern();
+    }
     $scope.handle_save = function() {
         $scope.patternCode = JSON.stringify($scope.pattern.compile());
         if (angular.isFunction($scope.onSave)) {