// create a new acp object with default values
// (both hard-coded and coming from OU settings)
- service.generateNewCopy = function(callNumber, owningLib, isFastAdd, isNew) {
+ service.generateNewCopy =
+ function(callNumber, owningLib, isFastAdd, isNew, delayCopyStatus) {
+
var cp = new egCore.idl.acp();
cp.id( --service.new_cp_id );
if (isNew) {
cp.mint_condition('t');
cp.empty_barcode = true;
- var status_setting = isFastAdd ?
+ if (delayCopyStatus) { return cp; }
+
+ service.applyDefaultStatus([cp], isFastAdd);
+
+ return cp;
+ }
+
+ // Apply the default copy status to a batch of copies
+ service.applyDefaultStatus = function(copies, isFastAdd) {
+
+ var setting = isFastAdd ?
'cat.default_copy_status_fast' :
'cat.default_copy_status_normal';
- egCore.org.settings(
- [status_setting],
- owningLib
- ).then(function(set) {
- var default_ccs = parseInt(set[status_setting]);
- if (isNaN(default_ccs))
- default_ccs = (isFastAdd ? 0 : 5); // 0 is Available, 5 is In Process
- cp.status(default_ccs);
+
+ var orgs = {};
+ copies.forEach(function(copy) { orgs[copy.circ_lib()] = 1; });
+
+ var promise = $q.when();
+
+ // Fetch needed org settings; serialized
+ // Note in practice this is always one org unit since
+ // batches of copies are added to a single volume at a time.
+ Object.keys(orgs).forEach(function(org) {
+ promise = promise.then(function() {
+ return egCore.org.settings(setting, org)
+ .then(function(sets) {
+ var stat = sets[setting] || (isFastAdd ? 0 : 5);
+ orgs[org] = stat;
+ });
+ })
});
- return cp;
+ // All needed org settings retrieved.
+ // Appply values to matching copies
+ promise.then(function() {
+ Object.keys(orgs).forEach(function(org) {
+
+ var someCopies = copies.filter(function(copy) {
+ return copy.circ_lib() == org});
+
+ someCopies.forEach(function(copy) { copy.status(orgs[org]); });
+ });
+ });
+
+ return promise;
}
return service;
}
$scope.changeCPCount = function () {
+ var newCopies = [];
while ($scope.copy_count > $scope.copies.length) {
var cp = itemSvc.generateNewCopy(
$scope.callNumber,
$scope.callNumber.owning_lib(),
$scope.fast_add,
- true
+ true, true
);
$scope.copies.push( cp );
$scope.allcopies.push( cp );
-
+ newCopies.push(cp);
}
+ itemSvc.applyDefaultStatus(newCopies, $scope.fast_add);
+
if ($scope.copy_count >= $scope.orig_copy_count) {
var how_many = $scope.copies.length - $scope.copy_count;
if (how_many > 0) {
$scope.$watch('cn_count', function (n) {
var o = Object.keys($scope.struct).length;
if (n > o) { // adding
+ var newCopies = [];
for (var i = o; o < n; o++) {
var cn = new egCore.idl.acn();
cn.id( --itemSvc.new_cn_id );
cn,
$scope.owning_lib.id(),
$scope.fast_add,
- true
+ true, true
);
+ newCopies.push(cp);
$scope.struct[cn.id()] = [cp];
$scope.allcopies.push(cp);
if (!$scope.defaults.classification) {
});
}
}
+
+ itemSvc.applyDefaultStatus(newCopies, $scope.fast_add);
+
} else if (n < o && n >= $scope.orig_cn_count) { // removing
var how_many = o - n;
var list = Object
return y.id() == x;
});
- return s[0].name();
+ return s[0] ? s[0].name() : '';
}
$scope.locationName = function (x) {