sub _find_or_create_call_number {
my ($e, $lib, $cn_string, $record) = @_;
- # FIXME: should suffix and prefix come into play here?
- my $existing = $e->search_asset_call_number({
- "owning_lib" => $lib,
- "label" => $cn_string,
- "record" => $record,
- "deleted" => "f"
- }) or return $e->die_event;
+ my ($prefix,$suffix) = ('','');
+ if (ref($cn_string)) {
+ ($prefix,$cn_string,$suffix) = @$cn_string;
+ }
+
+ my $existing = $e->search_asset_call_number([{
+ owning_lib => $lib,
+ label => $cn_string,
+ record => $record,
+ deleted => "f",
+ '+acnp' => { label => $prefix },
+ '+acns' => { label => $suffix },
+
+ },{
+ join => { acnp => {}, acns => {} }
+ }]) or return $e->die_event;
if (@$existing) {
return $existing->[0]->id;
return $e->die_event unless
$e->allowed("CREATE_VOLUME", $lib);
+ $prefix = -1 if (!$prefix);
+ $suffix = -1 if (!$suffix);
+
+ if ($prefix ne '-1') {
+ my $acnp = $e->search_asset_call_number_prefix({
+ owning_lib => $lib,
+ label => $prefix,
+ })->[0];
+
+ if (!$acnp) {
+ $acnp = new Fieldmapper::asset::call_number_prefix;
+ $acnp->label($prefix);
+ $acnp->owning_lib($lib);
+ $e->create_asset_call_number_prefix($acnp) or return $e->die_event;
+ $prefix = $e->data->id;
+ }
+ }
+
+ if ($suffix ne '-1') {
+ my $acns = $e->search_asset_call_number_suffix({
+ owning_lib => $lib,
+ label => $suffix,
+ })->[0];
+
+ if (!$acns) {
+ $acns = new Fieldmapper::asset::call_number_suffix;
+ $acns->label($suffix);
+ $acns->owning_lib($lib);
+ $e->create_asset_call_number_suffix($acns) or return $e->die_event;
+ $suffix = $e->data->id;
+ }
+ }
+
my $acn = new Fieldmapper::asset::call_number;
$acn->creator($e->requestor->id);
$acn->record($record);
$acn->label($cn_string);
$acn->owning_lib($lib);
+ $acn->prefix($prefix);
+ $acn->suffix($suffix);
$e->create_asset_call_number($acn) or return $e->die_event;
return $e->data->id;
<select
class="form-control"
ng-model="selected_call_number"
- ng-options="l.label as l.label for l in acn_list | orderBy:'label_sortkey'">
+ ng-options="l as fullCNLabel(l) for l in acn_list | orderBy:'label_sortkey'">
<option value="">[% l('Default') %]</option>
</select>
</div>
</select>
</div>
<div class="col-md-1">
- <input ng-disabled="!item._receive || bind_or_none($index)" class="form-control"
+ <input ng-disabled="!item._receive || bind_or_none($index)" class="form-control" placeholder="[% l('Prefix') %]"
+ ng-model="item._cn_prefix" type="text"/>
+ <input ng-disabled="!item._receive || bind_or_none($index)" class="form-control" placeholder="[% l('Label') %]"
ng-required="item._receive && !bind_or_none($index)" ng-model="item._call_number" type="text"/>
+ <input ng-disabled="!item._receive || bind_or_none($index)" class="form-control" placeholder="[% l('Suffix') %]"
+ ng-model="item._cn_suffix" type="text"/><br/>
</div>
<div class="col-md-1">
<select
record : service.bibId,
owning_lib : contextOrg,
deleted : 'f'
- }, { order_by : [{class:'acn',field:'create_date',direction:'desc'}], limit : 1 },
- { atomic : true }
+ }, { flesh : 1,
+ flesh_fields : {acn : ['prefix','suffix']},
+ order_by : [{class:'acn',field:'create_date',direction:'desc'}],
+ limit : 1
+ }, { atomic : true }
).then(function(list) {
return $q.when(list[0]);
});
$('#item_barcode_'+index).focus().select();
}
+ $scope.fullCNLabel = function (cn) {
+ var label = [cn.prefix.label,cn.label,cn.suffix.label].join(' ');
+ return label;
+ }
+
$scope.apply_template_overrides = function (e) {
if ($scope.selected_call_number) {
angular.forEach($scope.items, function (i) {
- i._call_number = $scope.selected_call_number;
+ i._call_number = $scope.selected_call_number.label;
+ i._cn_prefix = $scope.selected_call_number.prefix.label;
+ i._cn_suffix = $scope.selected_call_number.suffix.label;
});
}
if ($scope.selected_circ_mod) {
i._barcode = i.unit().barcode();
pile_o_promises.push(
egCore.pcrud.retrieve(
- 'acn', i.unit().call_number()
- ).then(function(cn){ if (cn.deleted() == 'f') i._call_number = cn.label() })
+ 'acn', i.unit().call_number(),
+ {flesh : 1, flesh_fields : {acn : ['prefix','suffix']}}
+ ).then(function(cn){
+ if (cn.deleted() == 'f') {
+ i._call_number = cn.label();
+ i._cn_prefix = cn.prefix().label();
+ i._cn_suffix = cn.suffix().label();
+ }
+ })
);
} else {
if (i.stream().distribution()[mode + '_call_number']() &&
pile_o_promises.push(
service.fetchLastCallnumber(
i.stream().distribution().holding_lib().id()
- ).then(function(cn){ if (cn) i._call_number = cn.label() })
+ ).then(function(cn){
+ if (cn) {
+ i._call_number = cn.label();
+ i._cn_prefix = cn.prefix().label();
+ i._cn_suffix = cn.suffix().label();
+ }
+ })
);
}
}
pile_o_promises.push(egCore.pcrud.search(
'acn',
{deleted : 'f', record : bibId, owning_lib : egCore.org.fullPath(egCore.auth.user().ws_ou(), true)},
- {},{ atomic : true }
+ {flesh : 1, flesh_fields : {acn : ['prefix','suffix']}},{ atomic : true }
).then(function (list) {
$scope.acn_list = list.map(function(i){return egCore.idl.toHash(i)});
return $q.when();
if (bind) i.unit(-2);
copy_locations[i.id()] = i._copy_location;
circ_mods[i.id()] = i._circ_mod;
- call_numbers[i.id()] = i._call_number || 'DEFAULT';
+ call_numbers[i.id()] = [i._cn_prefix, i._call_number, i._cn_suffix] || 'DEFAULT';
barcodes[i.id()] = i._barcode || '@@AUTO';
if (bind && index > 0) barcodes[i.id()] = items[0]._barcode;
});