egHolds.retarget(hold_ids).then(refresh_page);
}
+
+ // udpate the in-grid hold with the clear-shelf cached response info.
+ function handle_clear_cache_resp(resp) {
+ console.debug('clear shelf said: ' + js2JSON(resp));
+ if (!angular.isArray(resp)) resp = [resp];
+ angular.forEach(resp, function(info) {
+ if (info.action) {
+ var grid_item = holds.filter(function(item) {
+ return item.hold.id() == info.hold_details.id
+ })[0];
+
+ // there will be no grid item if the hold is off-page
+ if (grid_item) {
+ grid_item.post_clear =
+ egCore.strings['CLEAR_SHELF_ACTION_' + info.action];
+ }
+ }
+ });
+ }
+
$scope.clear_holds = function() {
clearing = true;
- $scope.clear_progress = { max : 0, value : 0 };
+ $scope.clear_progress = {max : 0, value : 0};
// we want to see all processed holds, so (effectively) remove
// the grid limit.
egCore.auth.token(), $scope.pickup_ou.id()
// request responses from the clear shelf cache
- ).then(function(resp) {
- console.debug('clear holds cache key is ' + resp.cache_key);
- return egCore.net.request(
- 'open-ils.circ',
- 'open-ils.circ.hold.clear_shelf.get_cache',
- egCore.auth.token(), resp.cache_key
- )
-
- // with each clear-shelf response, update the progress meter,
- // hide it when done.
- }).then(
- function() {
+ ).then(
+
+ // clear shelf done; fetch the cached results.
+ function(resp) {
clearing = false;
- },
+ console.debug('clear holds cache key is ' + resp.cache_key);
+ egCore.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.hold.clear_shelf.get_cache',
+ egCore.auth.token(), resp.cache_key
+ ).then(null, null, handle_clear_cache_resp);
+ },
+
null,
+
+ // handle streamed clear_shelf progress updates
function(resp) {
- console.debug('clear shelf said: ' + js2JSON(resp));
- if (!angular.isArray(resp)) resp = [resp];
- angular.forEach(resp, function(info) {
- if (info.maximum)
- $scope.clear_progress.max = info.maximum;
- if (info.progress)
- $scope.clear_progress.value = info.progress;
-
- if (info.action) {
- var grid_item = holds.filter(function(item) {
- return item.hold.id() == info.hold_details.id
- })[0];
-
- // there will be no grid item if the hold is off-page
- if (grid_item) {
- grid_item.post_clear =
- egCore.strings['CLEAR_SHELF_ACTION_' + info.action];
- }
- }
- });
+ if (resp.maximum)
+ $scope.clear_progress.max = resp.maximum;
+ if (resp.progress)
+ $scope.clear_progress.value = resp.progress;
}
+
);
}