[% WRAPPER base.tt2 %]
<script type="text/javascript" src='[% ctx.media_prefix %]/js/ui/kcls/cat/authority/list.js'> </script>
+
<style type="text/css">
.authEntry { clear: both; }
.authEntry > *:first-child { float: left; width: 20%; }
- .authEntry > .text { float: left; width: 46%; }
+ .authEntry > .text { float: left; width: 48%; }
.authEntry > .authority-control-set { float: right; width: 16%; ; font-style: italic; }
+ .authEntry > .bibrecord { visibility: hidden }
.authority-control-set .acs-name { font-weight: bold; }
.authority-control-set .acs-id { }
</style>
use OpenILS::Utils::Fieldmapper;
use OpenILS::Const qw/:const/;
use OpenILS::Event;
+use Try::Tiny;
+use MARC::Record;
+use MARC::File::XML ( BinaryEncoding => 'UTF-8' );
my $U = 'OpenILS::Application::AppUtils';
my $MARC_NAMESPACE = 'http://www.loc.gov/MARC21/slim';
}
__PACKAGE__->register_method(
+ method => 'titled_linked_bibs',
+ api_name => 'open-ils.cat.authority.records.titled_linked_bibs',
+ signature => q/
+ Returns titles of all bib records linked to each authority record in the input list
+ @param records Array of authority records to return counts
+ @return A list of hashes containing the authority record ID ("id") and linked bib count ("bibs")
+ /
+);
+
+sub titled_linked_bibs {
+ my( $self, $conn, $records ) = @_;
+
+ # Returns array_ref auth_id, bib_id, display_text_for_bib
+ my $response = $U->storagereq(
+ 'open-ils.storage.authority.get_linked_bibs', $records);
+
+ # This is a hash of hashes {auth_id => {bib_id => display_text_for_bib}}
+ my %linked_bibs;
+
+ foreach my $bib (@{$response}){
+
+ # add to auth's array if it's already there
+ if ($linked_bibs{${$bib}[0]}){
+
+ my %oldAuth = $linked_bibs{${$bib}[0]};
+
+ $oldAuth{${$bib}[1]} = ${$bib}[2];
+ }
+
+ # otherwise, make a new auth object
+ else{
+
+ my %newAuth = (${$bib}[1] => ${$bib}[2]);
+ $linked_bibs{${$bib}[0]} = \%newAuth;
+ }
+ }
+
+ return \%linked_bibs;
+}
+
+
+
+__PACKAGE__->register_method(
"method" => "retrieve_acs",
"api_name" => "open-ils.cat.authority.control_set.retrieve",
"api_level" => 1,
return $list;
}
+## Grabs all bibs (title by author in a string) with ids of bibs and
+# authorities using a list of authority ID's
+
+__PACKAGE__->register_method(
+ api_name => 'open-ils.storage.authority.get_linked_bibs',
+ method => 'get_linked_bibs',
+ api_level => 1,
+ stream => 1,
+);
+
+sub get_linked_bibs {
+
+ my $self = shift;
+ my $client = shift;
+ my $auth_ids_ref = shift;
+
+ my @holder_array = ();
+ my $id_string = '';
+ my $length = scalar @{ $auth_ids_ref };
+
+ if ($length > 0){
+
+ foreach my $id (@{ $auth_ids_ref }){
+
+ $id_string .= $id . ',';
+ }
+
+ # Remove last comma
+ chop($id_string);
+
+ # Build SQL statement
+ my $select = <<" SQL";
+ SELECT abl.authority AS auth_id, bre.id AS bre_id, bre.marc AS marc FROM biblio.record_entry bre
+ JOIN authority.bib_linking abl ON (bre.id = abl.bib)
+ WHERE abl.authority in ($id_string);
+ SQL
+
+ @holder_array = @{ authority::full_rec->db_Main->selectall_arrayref( $select ) };
+
+ foreach my $row (@holder_array){
+
+ ${$row}[2] = get_display_string(${$row}[2]);
+ }
+ }
+
+ return \@holder_array;
+}
+
+sub get_display_string {
+
+ my $marc_xml = shift;
+
+ # Grab and cleanup title
+ my $title = get_marc_value($marc_xml, 245, 'a');
+
+ my @split_array = split(/\//, $title);
+ $title = $split_array[0];
+ $title =~ s/\[(.*?)]//g;
+ $title =~ s/ ://g;
+
+ # Grab and cleanup author
+ my $author = get_marc_value($marc_xml, 100, 'a');
+
+ # DVD's should grab editor
+ if ($author eq "Not Found" || $author eq ""){
+
+ $author = get_marc_value($marc_xml, 700, 'a');
+ }
+
+ my $return_string = $title . " by " . $author;
+
+ if ($author eq "Not Found"){
+
+ $return_string = $title;
+ }
+
+ return $return_string;
+}
+
+sub get_marc_value {
+
+ my $xml = shift;
+ my $value = shift;
+ my $code = shift;
+ my $return_value = "Not Found";
+
+ if($xml =~ m/<datafield tag="$value"(.*?)datafield>/) {
+
+ my $datafield = $1;
+
+ if ($code && $datafield =~ m/<subfield code="$code">(.*?)</){
+
+ $return_value = $1;
+ }
+
+ elsif($datafield =~ m/<subfield code="a">(.*?)</) {
+
+ $return_value = $1;
+ }
+ }
+
+ if ($return_value eq "Not Found" || $return_value eq ""){
+
+ Try::Tiny::try {
+
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm 5;
+ $return_value = get_marc_value_use_marc($xml, $value, $code);
+ alarm 0;
+ }
+
+ Try::Tiny::catch {
+
+ $log->debug("get_marc_value timed out!");
+ };
+ }
+
+ return $return_value;
+}
+
+sub get_marc_value_use_marc {
+
+ my $xml = shift;
+ my $value = shift;
+ my $code = shift;
+ my $return_value;
+
+ if($xml =~ m/"<record(.*?)record>"/) {
+
+ $xml = "<record" . $1 . "record>";
+
+ my $r = MARC::Record->new_from_xml($xml);
+
+ if ($value == 100){
+
+ $return_value = $r->author();
+ }
+
+ if ($value == 245){
+
+ $return_value = $r->title_proper();
+ }
+
+ else{
+
+ if ($code){
+
+ $return_value = $r->subfield("$value",$code);
+ }
+ else{
+
+ $return_value = $r->subfield("$value","a");
+ }
+ }
+ }
+
+ return $return_value;
+}
+
1;
dojo.require('openils.widget.OrgUnitFilteringSelect');
dojo.require("openils.widget.PCrudAutocompleteBox");
dojo.require("MARC.FixedFields");
+
dojo.requireLocalization("openils.authority", "authority");
var auth_strings = dojo.i18n.getLocalization("openils.authority", "authority");
dojo.place(
'<div class="authEntry" id="auth' + auth.id + '">' +
'<div class="text" id="authLabel' + auth.id + '">' +
- '<span class="text">' + auth.text + '</span></div><div class="authority-control-set"><span>ID: ' +
+ '<span class="text" onclick="toggleBibsForAuthority('+
+ auth.id + ');">' + auth.text + '</span></div><div class="authority-control-set"><span>ID: ' +
auth.id + '</span></div>' +
'<div class="authority-control-set">Control Set: <span class="acs-name">' +
fetch_control_set(auth.thesaurus).name() +
auth_mb.placeAt(dojo.create("div", null, "auth" + auth.id, "first"), "first");
auth_menu.startup();
});
-
- showBibCount(idArr);
+
+ getAssociatedBibs(idArr);
}
function viewMARC(recId) {
}
}
-function showBibCount(authIds) {
- /* Decorate the list with # of bibs linked to each authority record */
- var ses = new OpenSRF.ClientSession('open-ils.cat');
- var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
- var linkedIds = [];
+function getAssociatedBibs(authIds) {
+
+ var ses = new OpenSRF.ClientSession('open-ils.cat');
+ var req = ses.request('open-ils.cat.authority.records.titled_linked_bibs', authIds);
+
req.oncomplete = function(r) {
+
var msg = r.recv().content();
- dojo.forEach(msg, function(auth) {
- linkedIds.push(auth.authority);
- dojo.place('<span class="bibcount">' + auth.bibs + '</span> ', 'authLabel' + auth.authority, 'first');
- }
- );
-
- /* Assign counts of 0 for every non-linked authority */
- dojo.forEach(authIds, function (id) {
- var found = false;
- dojo.forEach(linkedIds, function (lid) {
- if (id == lid) {
- found = true;
- }
- });
- if (!found) {
- dojo.place('<span class="bibcount">0</span> ', 'authLabel' + id, 'first');
- }
- });
+
+ for (var i in authIds){
+
+ if (authIds[i] in msg){
+
+ var count = 0;
+
+ for (var bib in msg[authIds[i]]){
+
+ count ++;
+
+ dojo.place('<div class="bibrecord forAuth' +
+ authIds[i] + '"><a href="/eg/opac/record/' + authIds[i] + '" target="_blank"> - ' + msg[authIds[i]][bib] +
+ '</a></div> ',
+ 'auth' + authIds[i],
+ 'last');
+ }
+
+ dojo.place('<span class="bibcount" id="bibcount' + authIds[i] +
+ '" onclick="toggleBibsForAuthority('+
+ authIds[i] + ');">► ' + count +
+ '</span>',
+ 'authLabel' + authIds[i], 'first');
+ }
+
+ else{
+
+ dojo.place('<span class="bibcount">0</span> ', 'authLabel' + authIds[i], 'first');
+ dojo.place('<div class="bibrecord"><span>-</span></div> ', 'auth' + authIds[i], 'last');
+ }
+ }
}
req.send();
}
+function toggleBibsForAuthority(authId){
+
+ var bibs = document.getElementsByClassName("forAuth" + authId);
+ var show = true;
+
+ for (var i in bibs){
+
+ if (bibs[i] != undefined && bibs[i].style != undefined){
+
+ if (bibs[i].style.visibility == "" || bibs[i].style.visibility == "hidden"){
+
+ bibs[i].style.visibility = "visible";
+ show = true;
+ }
+
+ else{
+
+ bibs[i].style.visibility = "hidden";
+ show = false;
+ }
+ }
+ }
+
+ var textToChange = document.getElementById("bibcount" + authId).innerHTML;
+
+ if (show){
+
+ var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9660));
+ }
+
+ else{
+
+ var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9658));
+ }
+
+ document.getElementById("bibcount" + authId).innerHTML = changedText;
+}
+
function loadMarcEditor(pcrud, rec) {
/* Prevent the spawned MARC editor from making its title bar inaccessible */