webstaff: move add_issuances() to core service
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 25 May 2017 17:48:56 +0000 (13:48 -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>
Conflicts:
Open-ILS/web/js/ui/default/staff/serials/services/core.js

Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js
Open-ILS/web/js/ui/default/staff/serials/services/core.js

index d9bea4c..5a3238b 100644 (file)
@@ -283,54 +283,8 @@ function($scope , $q , egSerialsCoreSvc , egCore , egGridDataProvider , orderByF
     }
 
     $scope.add_issuances = function () {
-        var lastItem = egSerialsCoreSvc.itemList[egSerialsCoreSvc.itemList.length - 1];
-
-        if (lastItem) lastItem = egCore.idl.fromHash('siss', lastItem.issuance);
-
-        return egSerialsCoreSvc.new_holding_code({
-            title : egCore.strings.SERIALS_ISSUANCE_PREDICT,
-            request_count : true,
-            prev_iss : lastItem
-        }).then(function(hc) {
-
-            var base_iss;
-            if (!lastItem) {
-                base_iss = new egCore.idl.siss();
-                base_iss.creator( egCore.auth.user().id() );
-                base_iss.editor( egCore.auth.user().id() );
-                base_iss.date_published( hc.date.toISOString() );
-                base_iss.subscription( $scope.ssubId );
-                base_iss.caption_and_pattern( hc.scap );
-                base_iss.holding_code( JSON.stringify(hc.holding_code) );
-                base_iss.holding_type( hc.type );
-            }
-
-            // if we're predicting without a preexisting holding, reduce the count
-            if (!lastItem) hc.count--;
-
-            return egCore.net.request(
-                'open-ils.serial',
-                'open-ils.serial.make_predictions',
-                egCore.auth.token(),
-                { ssub_id : $scope.ssubId,
-                  include_base_issuance : lastItem ? 0 : 1,
-                  num_to_predict : hc.count,
-                  base_issuance : base_iss || lastItem
-                }
-            ).then(
-                function(resp) {
-                    var evt = egCore.evt.parse(resp);
-                    if (evt) {
-                        ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
-                    } else {
-                        ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
-                        return reload($scope.ssubId,_paging_filter);
-                    }
-                },
-                function(resp) {
-                    ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
-                }
-            );
+        egSerialsCoreSvc.add_issuances($scope.ssubId).then(function() {
+            return reload($scope.ssubId,_paging_filter);
         });
     }
 
index 0a02ffe..be44b93 100644 (file)
@@ -938,6 +938,57 @@ function(egCore , orderByFilter , $q , $filter , $uibModal , ngToast , egConfirm
         return deferred.resolve();
     }
 
+    service.add_issuances = function (mySsubId) {
+        var lastItem = service.itemList[service.itemList.length - 1];
+
+        if (lastItem) lastItem = egCore.idl.fromHash('siss', lastItem.issuance);
+
+        return service.new_holding_code({
+            title : egCore.strings.SERIALS_ISSUANCE_PREDICT,
+            request_count : true,
+            prev_iss : lastItem
+        }).then(function(hc) {
+
+            var base_iss;
+            if (!lastItem) {
+                base_iss = new egCore.idl.siss();
+                base_iss.creator( egCore.auth.user().id() );
+                base_iss.editor( egCore.auth.user().id() );
+                base_iss.date_published( hc.date.toISOString() );
+                base_iss.subscription( mySsubId );
+                base_iss.caption_and_pattern( hc.scap );
+                base_iss.holding_code( JSON.stringify(hc.holding_code) );
+                base_iss.holding_type( hc.type );
+            }
+
+            // if we're predicting without a preexisting holding, reduce the count
+            if (!lastItem) hc.count--;
+
+            return egCore.net.request(
+                'open-ils.serial',
+                'open-ils.serial.make_predictions',
+                egCore.auth.token(),
+                { ssub_id : mySsubId,
+                  include_base_issuance : lastItem ? 0 : 1,
+                  num_to_predict : hc.count,
+                  base_issuance : base_iss || lastItem
+                }
+            ).then(
+                function(resp) {
+                    var evt = egCore.evt.parse(resp);
+                    if (evt) {
+                        ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                    } else {
+                        ngToast.success(egCore.strings.SERIALS_ISSUANCE_SUCCESS_SAVE);
+                    }
+                },
+                function(resp) {
+                    ngToast.danger(egCore.strings.SERIALS_ISSUANCE_FAIL_SAVE);
+                }
+            );
+        });
+    }
+
     return service;
 }]);