webstaff: implement saving pattern as a template
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 9 May 2017 20:34:48 +0000 (16:34 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 9 May 2017 20:34:48 +0000 (16:34 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/serials/t_prediction_wizard.tt2
Open-ILS/web/js/ui/default/staff/serials/directives/prediction_wizard.js

index 976dd0a..4d369cc 100644 (file)
         </div>
       </div>
       <div class="row">
-        <div class="col-md-2">
-          <label for="pattern_name">[% l('Share this pattern as a template?') %]</label>
-          <input id="pattern_name" type="text" ng-model="pattern_name">
+        <div class="col-md-8">
+          <label for="pattern_name">[% l('Enter a name to share this pattern as a template') %]</label>
+          <input id="pattern_name" type="text" ng-model="share.pattern_name">
+          <label for="share_depth">[% l('Share with') %]</label>
+          <eg-share-depth-selector ng-model="share.depth"></eg-share-depth-selector>
         </div>
       </div>
       <div class="row">
index 5cefee2..1ec9c05 100644 (file)
@@ -501,10 +501,30 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider) {
     } else {
         $scope.pattern = new PredictionPattern();
     }
+
+    // possible sharing
+    $scope.share = {
+        pattern_name : null,
+        depth        : 0
+    };
+
     $scope.handle_save = function() {
         $scope.patternCode = JSON.stringify($scope.pattern.compile());
-        if (angular.isFunction($scope.onSave)) {
-            $scope.onSave($scope.patternCode);
+        if ($scope.share.pattern_name !== null) {
+            var spt = new egCore.idl.spt();
+            spt.name($scope.share.pattern_name);
+            spt.pattern_code($scope.patternCode);
+            spt.share_depth($scope.share.depth);
+            spt.owning_lib(egCore.auth.user().ws_ou());
+            egCore.pcrud.create(spt).then(function() {
+                if (angular.isFunction($scope.onSave)) {
+                    $scope.onSave($scope.patternCode);
+                }
+            });
+        } else {
+            if (angular.isFunction($scope.onSave)) {
+                $scope.onSave($scope.patternCode);
+            }
         }
     }