if (!list.length) return $q.reject();
- var donor_unit_ids = {};
- angular.forEach(list, function (item) {
- if (item.unit()) donor_unit_ids[item.unit().id()] = 1;
- if (do_barcode) item.unit(-1);
- if (bind) item.unit(-2);
- });
-
- var method; var success_label;
- if (mode == 'receive') {
- method = 'open-ils.serial.receive_items';
- success_label = 'received';
- } else { // bind mode
- method = 'open-ils.serial.bind_items';
- success_label = 'bound';
- }
-
// deal with locations and circ mods for *NEW* units
var copy_locations = {};
var circ_mods = {};
controller:
['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
- $scope.receive_date = new Date();
$scope.barcode_items = do_barcode;
$scope.force_bind = bind;
$scope.bind = bind;
$scope.acn_list = [];
$scope.acpl_list = [];
- var acpl_hash = {};
- var acn_hash = {};
-
- $scope.bind_or_none = function (index) {
- return !$scope.barcode_items || ($scope.bind && index > 0);
- }
-
- $scope.focus_next_barcode = function (index) {
- index++;
- $('#item_barcode_'+index).focus().select();
- }
-
- $scope.$watch('auto_barcodes', function (n) {
- var bc = '@@AUTO';
- if (!n) bc = '';
-
- angular.forEach($scope.items, function (i) {
- var _barcode = i._barcode;
- i._barcode = bc || i._old_barcode;
- i._old_barcode = _barcode;
- });
- });
-
- $scope.apply_template_overrides = function (e) {
- if ($scope.selected_call_number) {
- angular.forEach($scope.items, function (i) {
- i._call_number = $scope.selected_call_number;
- });
- }
- if ($scope.selected_circ_mod) {
- angular.forEach($scope.items, function (i) {
- i._circ_mod = $scope.selected_circ_mod;
- });
- }
- if ($scope.selected_copy_location) {
- angular.forEach($scope.items, function (i) {
- i._copy_location = $scope.selected_copy_location;
- });
- }
- }
-
var pile_o_promises = [$q.when()];
// let's gather what we need...
angular.forEach(list, function (i) {
- if (i.stream().distribution()[mode + '_call_number']())
- i._call_number = i.stream().distribution()[mode + '_call_number']().label();
+ if (i.unit()) {
+ i._barcode = i.unit().barcode();
+ pile_o_promises.push(
+ egCore.pcrud.retrieve(
+ 'acn', i.unit().call_number()
+ ).then(function(cn){ i._call_number = cn.label() })
+ );
+ } else {
+ if (i.stream().distribution()[mode + '_call_number']()) {
+ i._call_number = i.stream().distribution()[mode + '_call_number']().label();
+ } else {
+ pile_o_promises.push(
+ egSerialsCoreSvc.fetchLastCallnumber(
+ i.stream().distribution().holding_lib().id()
+ ).then(function(cn){ i._call_number = cn.label() })
+ );
+ }
+ }
if (i.stream().distribution()[mode + '_unit_template']()) {
i._copy_location = i.stream().distribution()[mode + '_unit_template']().location();
console.log('receive data collected');
});
+ $scope.bind_or_none = function (index) {
+ return !$scope.barcode_items || ($scope.bind && index > 0);
+ }
+
+ $scope.focus_next_barcode = function (index) {
+ index++;
+ $('#item_barcode_'+index).focus().select();
+ }
+
+ $scope.apply_template_overrides = function (e) {
+ if ($scope.selected_call_number) {
+ angular.forEach($scope.items, function (i) {
+ i._call_number = $scope.selected_call_number;
+ });
+ }
+ if ($scope.selected_circ_mod) {
+ angular.forEach($scope.items, function (i) {
+ i._circ_mod = $scope.selected_circ_mod;
+ });
+ }
+ if ($scope.selected_copy_location) {
+ angular.forEach($scope.items, function (i) {
+ i._copy_location = $scope.selected_copy_location;
+ });
+ }
+ }
+
+ $scope.$watch('barcode_items', function (n,o) {
+ if (n === undefined || n == o) return;
+ do_barcode = n;
+ });
+
+ $scope.$watch('bind', function (n,o) {
+ if (n === undefined || n == o) return;
+ bind = n;
+ });
+
+ $scope.$watch('auto_barcodes', function (n,o) {
+ if (n === undefined || n == o) return;
+
+ var bc = '@@AUTO';
+ if (!n) bc = '';
+
+ angular.forEach($scope.items, function (i) {
+ var _barcode = i._barcode;
+ i._barcode = bc || i._old_barcode;
+ i._old_barcode = _barcode;
+ });
+ });
+
$scope.ok = function(items) { $uibModalInstance.close(items) }
$scope.cancel = function () { $uibModalInstance.dismiss() }
}]
current_promise.then(function (items) {
+ var donor_unit_ids = {};
angular.forEach(items, function(i, index) {
+ if (item.unit()) donor_unit_ids[item.unit().id()] = 1;
+ if (do_barcode) item.unit(-1);
+ if (bind) item.unit(-2);
copy_locations[i.id()] = i._copy_location;
circ_mods[i.id()] = i._circ_mod;
call_numbers[i.id()] = i._call_number || 'DEFAULT';
if (bind && index > 0) barcodes[i.id()] = items[0]._barcode;
});
+ var method;
+ if (mode == 'receive') {
+ method = 'open-ils.serial.receive_items';
+ } else { // bind mode
+ method = 'open-ils.serial.bind_items';
+ }
+
return egCore.net.request(
'open-ils.serial', method,
egCore.auth.token(), items, barcodes, call_numbers, donor_unit_ids,