Backport biblio source enhancements from trunk:
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 2 Sep 2010 03:06:33 +0000 (03:06 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 2 Sep 2010 03:06:33 +0000 (03:06 +0000)
  * Make biblio source selection in Vandelay set the source for imported
    bib records.

  * Place a biblio source editor widget on the MARC Editor when invoked
    with a biblio record that already exists in the database ("rtype": "bre"
    with a specific ID).

git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_2_0@17435 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm
Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm
Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/js/ui/default/vandelay/vandelay.js
Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Open-ILS/xul/staff_client/server/cat/marcedit.js
Open-ILS/xul/staff_client/server/cat/marcedit.xul
Open-ILS/xul/staff_client/server/cat/z3950.js

index 4769f09..4d928a8 100644 (file)
@@ -89,6 +89,9 @@ sub biblio_record_xml_import {
                return $evt if $evt;
        }
 
+       # Silence warnings when _find_tcn_info() fails
+       $tcn ||= '';
+       $tcn_source ||= '';
        $logger->info("user ".$e->requestor->id.
                " creating new biblio entry with tcn=$tcn and tcn_source $tcn_source");
 
index f39cb5f..da3dca6 100644 (file)
@@ -44,6 +44,7 @@ my %record_types = (
         x => 'holdings',
         y => 'holdings',
         z => 'auth',
+      ' ' => 'bib',
 );
 
 sub initialize {}
@@ -624,6 +625,13 @@ sub import_record_list_impl {
     my $update_queue_func = 'update_vandelay_bib_queue';
     my $rec_class = 'vqbr';
 
+    my %bib_sources;
+    my $editor = new_editor();
+    my $sources = $editor->search_config_bib_source({id => {'!=' => undef}});
+    foreach my $src (@$sources) {
+        $bib_sources{$src->id} = $src->source;
+    }
+
     if($type eq 'auth') {
         $overlay_func =~ s/bib/auth/o;
         $auto_overlay_func = s/bib/auth/o;
@@ -737,8 +745,7 @@ sub import_record_list_impl {
                 # No overlay / merge occurred.  Do a traditional record import by creating a new record
             
                 if($type eq 'bib') {
-                    $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc); #$rec->bib_source
-
+                    $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc, $bib_sources{$rec->bib_source});
                 } else {
 
                     $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source);
index 00ae185..52e672c 100644 (file)
@@ -2308,7 +2308,7 @@ function AcqLiTable() {
         }
         var self = this;
         win.xulG = {
-            record : {marc : li.marc()},
+            record : {marc : li.marc(), "rtype": "bre"},
             save : {
                 label: 'Save Record', // XXX I18N
                 func: function(xmlString) {
index 61d0485..d5828ed 100644 (file)
@@ -1055,6 +1055,13 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
 
+    var type;
+    if (currentType == 'bib') {
+        type = 'bre';
+    } else {
+        type = 'are';
+    }
+
     function onsave(r) {
         // after the record is saved, reload the HTML display
         var stat = r.recv().content();
@@ -1066,7 +1073,7 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) {
     }
 
     win.xulG = {
-        record : {marc : rec.marc()},
+        record : {marc : rec.marc(), "rtype": type},
         save : {
             label: dojo.byId('vl-marc-edit-save-label').innerHTML,
             func: function(xmlString) {
index e07584b..45b3404 100644 (file)
@@ -121,7 +121,7 @@ function set_marc_edit() {
     var a =    xulG.url_prefix( urls.XUL_MARC_EDIT );
     var b =    {};
     var c =    {
-            'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
+            'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid, "id": docid, "rtype": "bre" },
             'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
                 try {
                     var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */
index 90435c9..1beb0c1 100644 (file)
@@ -140,11 +140,30 @@ function my_init() {
             var cgi = new CGI();
             var _rid = cgi.param('record');
             if (_rid) {
+                window.xulG.record.id = _rid;
                 window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid;
             }
         }
+
         // End faking part...
 
+        /* Check for an explicitly passed record type
+         * This is not the same as the fixed-field record type; we can't trust
+         * the fixed fields when making modifications to the attributes for a
+         * given record (in particular, config.bib_source only applies for bib
+         * records, but an auth or MFHD record with the same ID and bad fixed
+         * fields could trample the config.bib_source value for the
+         * corresponding bib record if we're not careful.
+         *
+         * are = authority record
+         * sre = serial record (MFHD)
+         * bre = bibliographic record
+         */
+        if (!window.xulG.record.rtype) {
+            var cgi = new CGI();
+            window.xulG.record.rtype = cgi.param('rtype') || false;
+        }
+
         document.getElementById('save-button').setAttribute('label', window.xulG.save.label);
         document.getElementById('save-button').setAttribute('oncommand',
             'if ($("xul-editor").hidden) swap_editors(); ' +
@@ -288,6 +307,19 @@ function my_init() {
         }
         document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked;
 
+        // Only show bib sources for bib records that already exist in the database
+        if (xulG.record.rtype == 'bre' && xulG.record.id) {
+            dojo.require('openils.PermaCrud');
+            var authtoken = ses();
+            // Retrieve the current record attributes
+            var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id);
+
+            // Remember the current bib source of the record
+            xulG.record.bre = bib;
+
+            buildBibSourceList(authtoken, xulG.record.id);
+        }
+
     } catch(E) {
         alert('FIXME, MARC Editor, my_init: ' + E);
     }
@@ -1865,11 +1897,19 @@ function getAuthorityContextMenu (target, sf) {
         var fields = xml.datafield;
         for (var j in fields) {
 
+            /* Restrict options to Heading Information fields (1xx)
+             * and See Also From fields (5xx) rather than displaying
+             * every field in the authority record */
+            var tag = fields[j].@tag;
+            if (tag.substr(0,1) != 1 && tag.substr(0,1) != 5) {
+                continue;
+            }
+
             var row = createRow(
                 {},
-                createLabel( { value : fields[j].@tag } ),
-                createLabel( { value : fields[j].@ind1 } ),
-                createLabel( { value : fields[j].@ind2 } )
+                createLabel( { "value" : tag } ),
+                createLabel( { "value" : fields[j].@ind1 } ),
+                createLabel( { "value" : fields[j].@ind2 } )
             );
 
             var sf_box = createHbox();
@@ -1878,10 +1918,10 @@ function getAuthorityContextMenu (target, sf) {
             for (var k in subfields) {
                 sf_box.appendChild(
                     createCheckbox(
-                        { label    : '\u2021' + subfields[k].@code + ' ' + subfields[k],
-                          subfield : subfields[k].@code,
-                          tag      : subfields[k].parent().@tag,
-                          value    : subfields[k]
+                        { "label"    : '\u2021' + subfields[k].@code + ' ' + subfields[k],
+                          "subfield" : subfields[k].@code,
+                          "tag"      : subfields[k].parent().@tag,
+                          "value"    : subfields[k]
                         }
                     )
                 );
@@ -2295,3 +2335,65 @@ function searchAuthority (term, tag, sf, limit) {
 
 }
 
+function buildBibSourceList (authtoken, recId) {
+    /* TODO: Work out how to set the bib source of the bre that does not yet
+     * exist - this is specifically in the case of Z39.50 imports. Right now
+     * we just avoid populating and showing the config.bib_source list
+     */
+       if (!recId) {
+               return false;
+       }
+
+    var bib = xulG.record.bre;
+
+    dojo.require('openils.PermaCrud');
+
+    // cbsList = the XUL menulist that contains the available bib sources 
+    var cbsList = dojo.byId('bib-source-list');
+
+    // bibSources = an array containing all of the bib source objects
+    var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs');
+
+    // A tad ugly, but gives us the index of the bib source ID in cbsList
+    var x = 0;
+    var cbsListArr = [];
+    dojo.forEach(bibSources, function (item) {
+        cbsList.appendItem(item.source(), item.id());
+        cbsListArr[item.id()] = x;
+        x++;
+    });
+
+    // Show the current value of the bib source for this record
+    cbsList.selectedIndex = cbsListArr[bib.source()];
+
+    // Display the bib source selection widget
+    dojo.byId('bib-source-list-caption').hidden = false;
+    dojo.byId('bib-source-list').hidden = false;
+    dojo.byId('bib-source-list-button').disabled = true;
+    dojo.byId('bib-source-list-button').hidden = false;
+}
+
+// Fired when the "Update Source" button is clicked
+// Updates the value of the bib source for the current record
+function updateBibSource() {
+    var authtoken = ses();
+    var cbs = dojo.byId('bib-source-list').selectedItem.value;
+    var recId = xulG.record.id;
+    var pcrud = new openils.PermaCrud({"authtoken": authtoken});
+    var bib = pcrud.retrieve('bre', recId);
+    if (bib.source() != cbs) {
+        bib.source(cbs);
+        bib.ischanged = true;
+        pcrud.update(bib);
+    }
+}
+
+function onBibSourceSelect() {
+    var cbs = dojo.byId('bib-source-list').selectedItem.value;
+    var bib = xulG.record.bre;
+    if (bib.source() != cbs) {
+        dojo.byId('bib-source-list-button').disabled = false;   
+    } else {
+        dojo.byId('bib-source-list-button').disabled = true;   
+    }
+}
index 1c91a6c..83d8a5e 100644 (file)
                 </grid>
             </vbox>
         </groupbox>
+
+            <vbox>
+                <caption id="bib-source-list-caption" hidden="true">&staff.cat.marcedit.source.caption;</caption>
+                <menulist id="bib-source-list" rows="3" hidden="true" onselect='onBibSourceSelect();'><menupopup id='bib-source-list-popup'></menupopup></menulist>
+                <button id="bib-source-list-button" label="&staff.cat.marcedit.source.submit.label;" disabled="true" oncommand="updateBibSource();" hidden="true"/>
+            </vbox>
         </hbox>
 
         <grid id="recGrid" flex="1">
index b1ac1b0..3c7e3ed 100644 (file)
@@ -709,7 +709,7 @@ cat.z3950.prototype = {
             xulG.url_prefix(urls.XUL_MARC_EDIT), 
             { 'tab_name' : 'MARC Editor' }, 
             { 
-                'record' : { 'marc' : my_marcxml },
+                'record' : { 'marc' : my_marcxml, "rtype": "bre" },
                 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
                     try {
                         JSAN.use('cat.util'); return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);