More polish for MFHD record display
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 26 May 2009 06:17:49 +0000 (06:17 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 26 May 2009 06:17:49 +0000 (06:17 +0000)
  * Add an owning_lib to SRE and SVR so that holdings are scoped to the search location
  * Add owning_lib as a context for deleting, merging, and updating MFHD records
  * Make the comma spacing regex global so that all current issues will be separated by a comma followed by a space
  * Use the MFHD id to invoke the MARC editor directly

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

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/OpenILS/Application/Search/Serial.pm
Open-ILS/src/perlmods/OpenILS/Utils/MFHDParser.pm
Open-ILS/src/sql/Pg/210.schema.serials.sql
Open-ILS/web/opac/skin/default/js/rdetail.js

index ad8f2b2..bd6012c 100644 (file)
@@ -2274,6 +2274,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        </class>
        <class id="svr" controller="open-ils.cstore" oils_obj:fieldmapper="serial::virtual_record" oils_persist:virtual="true" reporter:label="Serial Virtual Record">
                <fields>
+                       <field name="id" oils_persist:virtual="true" />
+                       <field name="owning_lib" oils_persist:virtual="true" />
                        <field name="holdings" oils_persist:virtual="true" />
                        <field name="current_holdings" oils_persist:virtual="true" />
                        <field name="supplements" oils_persist:virtual="true" />
@@ -2298,18 +2300,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="last_xact_id" />
                        <field name="marc" />
                        <field name="source" />
+                       <field reporter:label="Owning Org Unit" name="owning_lib" reporter:datatype="org_unit"/>
                </fields>
                <links>
                        <link field="record" reltype="has_a" key="id" map="" class="bre"/>
                        <link field="editor" reltype="has_a" key="id" map="" class="au"/>
                        <link field="creator" reltype="has_a" key="id" map="" class="au"/>
+                       <link field="owning_lib" reltype="has_a" key="id" map="" class="aou"/>
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="CREATE_MFHD_RECORD" global_required="true"/>
+                               <create permission="CREATE_MFHD_RECORD" context_field="owning_lib"/>
                                <retrieve/>
-                               <update permission="UPDATE_MFHD_RECORD" global_required="true"/>
-                               <delete permission="DELETE_MFHD_RECORD" global_required="true"/>
+                               <update permission="UPDATE_MFHD_RECORD" context_field="owning_lib"/>
+                               <delete permission="DELETE_MFHD_RECORD" context_field="owning_lib"/>
                        </actions>
                </permacrud>
        </class>
index b7188e2..6031659 100644 (file)
@@ -50,7 +50,7 @@ sub mfhd_to_hash {
                        "open-ils.cstore.direct.serial.record_entry.retrieve", $id )->gather(1);
 
        my $u = OpenILS::Utils::MFHDParser->new();
-       my $mfhd_hash = $u->generate_svr( $request->marc );
+       my $mfhd_hash = $u->generate_svr( $request->id, $request->marc, $request->owning_lib );
 
        $session->disconnect();
        return $mfhd_hash;
@@ -81,7 +81,7 @@ sub bib_to_mfhd_hash {
        # XXX perhaps this? --miker
 #      my $e = OpenILS::Utils::CStoreEditor->new();
 #      my $mfhd = $e->search_serial_record_entry({ record => $bib });
-#      return $u->generate_svr( $mfhd->[0]->marc ) if (ref $mfhd);
+#      return $u->generate_svr( $mfhd->[0] ) if (ref $mfhd);
 #      return undef;
 
        my @mfhd = $U->cstorereq( "open-ils.cstore.json_query.atomic", {
@@ -134,4 +134,30 @@ __PACKAGE__->register_method(
        note            => "Given a bibliographic record ID, return MFHD holdings"
 );
 
+sub bib_to_mfhd {
+       my ($self, $client, $bib) = @_;
+       
+       my $mfhd;
+
+       my $e = OpenILS::Utils::CStoreEditor->new();
+       my $serials = $e->search_serial_record_entry({ record => $bib });
+       if (!ref $serials) {
+               return undef;
+       }
+
+       my $u = OpenILS::Utils::MFHDParser->new();
+       foreach (@$serials) {
+               push(@$mfhd, $u->generate_svr($_->id, $_->marc, $_->owning_lib));
+       }
+
+       return $mfhd;
+}
+
+__PACKAGE__->register_method(
+       method  => "bib_to_mfhd",
+       api_name        => "open-ils.search.serial.record.bib.retrieve",
+       argc            => 1, 
+       note            => "Given a bibliographic record ID, return MFHD holdings"
+);
+
 1;
index ee2403d..6611d0e 100644 (file)
@@ -149,6 +149,8 @@ Initialize the serial virtual record (svr) instance
 =cut
 sub init_holdings_virtual_record {
        my $record = Fieldmapper::serial::virtual_record->new;
+       $record->id();
+       $record->owning_lib();
        $record->holdings([]);
        $record->current_holdings([]);
        $record->supplements([]);
@@ -171,7 +173,7 @@ Given an MFHD record, return a populated svr instance
 
 =cut
 sub generate_svr {
-       my ($self, $mfhd) = @_;
+       my ($self, $id, $mfhd, $owning_lib) = @_;
 
        if (!$mfhd) {
                return undef;
@@ -180,6 +182,8 @@ sub generate_svr {
        my $record = init_holdings_virtual_record();
        my $holdings = $self->mfhd_to_hash($mfhd);
 
+       $record->id($id);
+       $record->owning_lib($owning_lib);
        $record->holdings($holdings->{holdings});
        $record->current_holdings($holdings->{current_holdings});
        $record->supplements($holdings->{supplements});
index 43e8c56..a8a98d7 100644 (file)
@@ -9,6 +9,7 @@ CREATE SCHEMA serial;
 CREATE TABLE serial.record_entry (
        id              BIGSERIAL       PRIMARY KEY,
        record          BIGINT          REFERENCES biblio.record_entry (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
+       owning_lib      INT             NOT NULL DEFAULT 1 REFERENCES actor.org_unit (id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
        creator         INT             NOT NULL DEFAULT 1,
        editor          INT             NOT NULL DEFAULT 1,
        source          INT,
@@ -21,6 +22,7 @@ CREATE TABLE serial.record_entry (
 );
 CREATE INDEX serial_record_entry_creator_idx ON serial.record_entry ( creator );
 CREATE INDEX serial_record_entry_editor_idx ON serial.record_entry ( editor );
+CREATE INDEX serial_record_entry_owning_lib_idx ON serial.record_entry ( owning_lib, deleted );
 
 CREATE TABLE serial.full_rec (
        id              BIGSERIAL       PRIMARY KEY,
index 42d73b8..835ec7f 100644 (file)
@@ -204,7 +204,7 @@ function OpenMarcEditWindow(pcrud, rec) {
 
 function loadMarcEditor(recId) {
        var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
-       var recs = pcrud.search("sre", {"record": recId});
+       var recs = pcrud.search("sre", {"id": recId, "deleted": false});
        OpenMarcEditWindow(pcrud, recs[0]);
 }
 
@@ -217,10 +217,12 @@ function _holdingsDraw(h) {
        if (!holdings) { return null; }
 
        dojo.forEach(holdings, _holdingsDrawMFHD);
-
 }
 
 function _holdingsDrawMFHD(holdings, entryNum) {
+       if (!orgIsMine(findOrgUnit(holdings.owning_lib()), findOrgUnit(getLocation()))) {
+               return null;
+       }
        var hh = holdings.holdings();
        var hch = holdings.current_holdings();
        var hs = holdings.supplements();
@@ -252,13 +254,12 @@ function _holdingsDrawMFHD(holdings, entryNum) {
        if (isXUL()) {
                dojo.require('openils.Event');
                dojo.require('openils.PermaCrud');
-               dojo.place("<span> - </span><a class='classic_link' href='javascript:loadMarcEditor(" + getRid() + ")'> Edit</a>", "mfhdHoldingsCaption", "last");
+               dojo.place("<span> - </span><a class='classic_link' href='javascript:loadMarcEditor(" + holdings.id() + ")'> Edit</a>", "mfhdHoldingsCaption", "last");
        }
 }
 
 function _holdingsDrawMFHDEntry(entryNum, entryName, entry) {
-       var commaRegex = /,/;
-       var flatEntry = entry.toString().replace(commaRegex, ', ');
+       var flatEntry = entry.toString().replace(/,/g, ', ');
        dojo.place("<tr><td> </td><td nowrap='nowrap' class='rdetail_desc'>" + entryName + "</td><td class='rdetail_item'>" + flatEntry + "</td></tr>", "rdetail_holdings_tbody_" + entryNum, "last");
 }