first template and supporting code, printing queued bib records
authorJason Etheridge <jason@esilibrary.com>
Wed, 11 May 2011 05:39:32 +0000 (01:39 -0400)
committerJason Etheridge <jason@esilibrary.com>
Wed, 11 May 2011 05:39:32 +0000 (01:39 -0400)
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Vandelay.pm
Open-ILS/src/sql/Pg/upgrade/renumber_me.sql [new file with mode: 0644]
Open-ILS/web/js/ui/default/vandelay/vandelay.js

index 4251519..6442531 100644 (file)
@@ -148,6 +148,31 @@ my $_TT_helpers = {
         }
         return;
     },
+
+    get_queued_bib_attr => sub {
+        my $name = shift or return;     # the first arg is always the name
+        my ($attr) = @_;
+        # use Data::Dumper; $logger->warn("get_queued_bib_attr: " . Dumper($attr));
+        ($name and @$attr) or return;
+
+        my $query = {
+            select => {'vqbrad' => ['id']},
+            from => 'vqbrad',
+            where => {code => $name}
+        };
+
+        my $def_ids = new_editor()->json_query($query);
+        @$def_ids or return;
+
+        my $length;
+        $name =~ s/^(\D+)_(\d+)$/$1/ and $length = $2;
+        foreach (@$attr) {
+            $_->field eq @{$def_ids}[0]->{id} or next;
+            next if $length and $length != length($_->attr_value);
+            return $_->attr_value;
+        }
+        return;
+    },
 };
 
 
index 7412491..8d3b92d 100644 (file)
@@ -517,15 +517,18 @@ sub retrieve_queued_records {
 
     my $retrieve = ($type eq 'bib') ? 
         'retrieve_vandelay_queued_bib_record' : 'retrieve_vandelay_queued_authority_record';
+    my $search = ($type eq 'bib') ? 
+        'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record';
 
     if ($self->api_name =~ /export/) {
+        my $rec_list = $e->$search({id => [map { $_->{id} } @$record_ids]});
         if ($self->api_name =~ /print/) {
 
             $e->rollback;
             return $U->fire_object_event(
                 undef,
                 'vandelay.queued_'.$type.'_record.print',
-                [map {$_->{id}} @$record_ids],
+                $rec_list,
                 $e->requestor->ws_ou
             );
 
@@ -535,7 +538,7 @@ sub retrieve_queued_records {
             return $U->fire_object_event(
                 undef,
                 'vandelay.queued_'.$type.'_record.csv',
-                [map {$_->{id}} @$record_ids],
+                $rec_list,
                 $e->requestor->ws_ou
             );
 
@@ -543,10 +546,10 @@ sub retrieve_queued_records {
 
             $conn->respond_complete(1);
 
-            for my $rec_id (@$record_ids) {
+            for my $rec (@$rec_list) {
                 $U->create_events_for_hook(
                     'vandelay.queued_'.$type.'_record.email',
-                    $rec_id->{id},
+                    $rec,
                     $e->requestor->home_ou,
                     undef,
                     undef,
@@ -665,13 +668,14 @@ sub retrieve_queue_import_items {
         if $$options{with_import_error};
 
     my $items = $e->json_query($query);
+    my $item_list = $e->search_vandelay_import_item({id => [map { $_->{id} } @$items]});
     if ($self->api_name =~ /export/) {
         if ($self->api_name =~ /print/) {
 
             return $U->fire_object_event(
                 undef,
                 'vandelay.import_items.print',
-                [map {$_->{id}} @$items],
+                $item_list,
                 $e->requestor->ws_ou
             );
 
@@ -680,7 +684,7 @@ sub retrieve_queue_import_items {
             return $U->fire_object_event(
                 undef,
                 'vandelay.import_items.csv',
-                [map {$_->{id}} @$items],
+                $item_list,
                 $e->requestor->ws_ou
             );
 
@@ -688,10 +692,10 @@ sub retrieve_queue_import_items {
 
             $conn->respond_complete(1);
 
-            for my $item (@$items) {
+            for my $item (@$item_list) {
                 $U->create_events_for_hook(
                     'vandelay.import_items.email',
-                    $item->{id},
+                    $item,
                     $e->requestor->home_ou,
                     undef,
                     undef,
@@ -701,8 +705,8 @@ sub retrieve_queue_import_items {
 
         }
     } else {
-        for my $item (@$items) {
-            $conn->respond($e->retrieve_vandelay_import_item($item->{id}));
+        for my $item (@$item_list) {
+            $conn->respond($item);
         }
     }
 
diff --git a/Open-ILS/src/sql/Pg/upgrade/renumber_me.sql b/Open-ILS/src/sql/Pg/upgrade/renumber_me.sql
new file mode 100644 (file)
index 0000000..42e8aec
--- /dev/null
@@ -0,0 +1,165 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('test'); -- phasefx
+
+INSERT INTO action_trigger.hook (key,core_type,description,passive) VALUES (
+        'vandelay.queued_bib_record.print',
+        'vqbr', 
+        oils_i18n_gettext(
+            'vandelay.queued_bib_record.print',
+            'Print output has been requested for records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.queued_bib_record.csv',
+        'vqbr', 
+        oils_i18n_gettext(
+            'vandelay.queued_bib_record.csv',
+            'CSV output has been requested for records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.queued_bib_record.email',
+        'vqbr', 
+        oils_i18n_gettext(
+            'vandelay.queued_bib_record.email',
+            'An email has been requested for records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.queued_auth_record.print',
+        'vqar', 
+        oils_i18n_gettext(
+            'vandelay.queued_auth_record.print',
+            'Print output has been requested for records in an Importer Authority Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.queued_auth_record.csv',
+        'vqar', 
+        oils_i18n_gettext(
+            'vandelay.queued_auth_record.csv',
+            'CSV output has been requested for records in an Importer Authority Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.queued_auth_record.email',
+        'vqar', 
+        oils_i18n_gettext(
+            'vandelay.queued_auth_record.email',
+            'An email has been requested for records in an Importer Authority Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.import_items.print',
+        'vii', 
+        oils_i18n_gettext(
+            'vandelay.import_items.print',
+            'Print output has been requested for Import Items from records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.import_items.csv',
+        'vii', 
+        oils_i18n_gettext(
+            'vandelay.import_items.csv',
+            'CSV output has been requested for Import Items from records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+    ,(
+        'vandelay.import_items.email',
+        'vii', 
+        oils_i18n_gettext(
+            'vandelay.import_items.email',
+            'An email has been requested for Import Items from records in an Importer Bib Queue.',
+            'ath',
+            'description'
+        ), 
+        FALSE
+    )
+;
+
+INSERT INTO action_trigger.event_definition (
+        id,
+        active,
+        owner,
+        name,
+        hook,
+        validator,
+        reactor,
+        group_field,
+        granularity,
+        template
+    ) VALUES (
+        38,
+        TRUE,
+        1,
+        'Print Output for Queued Bib Records',
+        'vandelay.queued_bib_record.print',
+        'NOOP_True',
+        'ProcessTemplate',
+        'usr',
+        'print-on-demand',
+$$
+[%- USE date -%]
+<pre>
+Queue ID: [% target.0.queue.id %]
+Queue Name: [% target.0.queue.name %]
+Queue Type: [% target.0.queue.queue_type %]
+Complete? [% target.0.queue.complete %]
+
+    [% FOR vqbr IN target %]
+=-=-=
+ Title of work    | [% helpers.get_queued_bib_attr('title',vqbr.attributes) %]
+ Author of work   | [% helpers.get_queued_bib_attr('author',vqbr.attributes) %]
+ Language of work | [% helpers.get_queued_bib_attr('language',vqbr.attributes) %]
+ Pagination       | [% helpers.get_queued_bib_attr('pagination',vqbr.attributes) %]
+ ISBN             | [% helpers.get_queued_bib_attr('isbn',vqbr.attributes) %]
+ ISSN             | [% helpers.get_queued_bib_attr('issn',vqbr.attributes) %]
+ Price            | [% helpers.get_queued_bib_attr('price',vqbr.attributes) %]
+ Accession Number | [% helpers.get_queued_bib_attr('rec_identifier',vqbr.attributes) %]
+ TCN Value        | [% helpers.get_queued_bib_attr('eg_tcn',vqbr.attributes) %]
+ TCN Source       | [% helpers.get_queued_bib_attr('eg_tcn_source',vqbr.attributes) %]
+ Internal ID      | [% helpers.get_queued_bib_attr('eg_identifier',vqbr.attributes) %]
+ Publisher        | [% helpers.get_queued_bib_attr('publisher',vqbr.attributes) %]
+ Publication Date | [% helpers.get_queued_bib_attr('pubdate',vqbr.attributes) %]
+ Edition          | [% helpers.get_queued_bib_attr('edition',vqbr.attributes) %]
+ Item Barcode     | [% helpers.get_queued_bib_attr('item_barcode',vqbr.attributes) %]
+
+    [% END %]
+</pre>
+$$
+    )
+;
+
+INSERT INTO action_trigger.environment ( event_def, path) VALUES (
+    38, 'attributes')
+    ,( 38, 'queue')
+;
+
+COMMIT;
+-- DELETE FROM action_trigger.event WHERE event_def IN (38); DELETE FROM action_trigger.environment WHERE event_def IN (38); DELETE FROM action_trigger.event_definition WHERE id IN (38); DELETE FROM action_trigger.hook WHERE key IN ('vandelay.queued_bib_record.print','vandelay.queued_bib_record.csv','vandelay.queued_bib_record.email','vandelay.queued_auth_record.print','vandelay.queued_auth_record.csv','vandelay.queued_auth_record.email','vandelay.import_items.print','vandelay.import_items.csv','vandelay.import_items.email'); DELETE FROM config.upgrade_log WHERE version = 'test';
index bc9a153..9565869 100644 (file)
@@ -422,11 +422,15 @@ function vlExportInit() {
 }
 
 function exportHandler(type, response) {
-    var content = openils.Util.readResponse(response);
-    if(type == 'print') {
-        // TODO print the content
+    try {
+        var content = openils.Util.readResponse(response)[0].template_output().data();
+        switch(type) {
+            case 'print': openils.Util.printHtmlString(content); break;
+            default: alert('response = ' + response + ' content:\n' + content);
+        }
+    } catch(E) {
+        alert('Error exporting data: ' + E);
     }
-    alert('response = ' + response);
 }
 
 function retrieveQueuedRecords(type, queueId, onload, doExport) {
@@ -465,7 +469,7 @@ function retrieveQueuedRecords(type, queueId, onload, doExport) {
         {   async: true,
             params: params,
             oncomplete: function(r){
-                if(doExport) return onload();
+                if(doExport) return onload(r);
                 var recs = r.recv().content();
                 if(e = openils.Event.parse(recs[0]))
                     return alert(e);