From: Galen Charlton Date: Thu, 25 May 2017 17:48:56 +0000 (-0400) Subject: webstaff: move add_issuances() to core service X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c25423187748b07f3159041f79cd16c6620c5094;p=working%2FEvergreen.git webstaff: move add_issuances() to core service Signed-off-by: Galen Charlton Conflicts: Open-ILS/web/js/ui/default/staff/serials/services/core.js --- diff --git a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js index d9bea4c9f1..5a3238be38 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js +++ b/Open-ILS/web/js/ui/default/staff/serials/directives/view-items-grid.js @@ -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); }); } diff --git a/Open-ILS/web/js/ui/default/staff/serials/services/core.js b/Open-ILS/web/js/ui/default/staff/serials/services/core.js index 0a02ffe628..be44b93796 100644 --- a/Open-ILS/web/js/ui/default/staff/serials/services/core.js +++ b/Open-ILS/web/js/ui/default/staff/serials/services/core.js @@ -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; }]);