From 027a7d0983b6ff376b3d87120710d63b9339e225 Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 6 Oct 2010 21:01:42 +0000 Subject: [PATCH] New way to printing shelf-expired holds This just takes the newest template for printing hold pull lists and grafts this new functionality onto it. It should perhaps be adjusted to also be able to print things on the holds shelf that /aren't/ shelf-expired. For now you get to this under Admin -> For Developers -> Local Administration This also corrects a bug because of which a "print pull list (alternate strategy)" button appeared where it shouldn't. This also removes the booking links from Admin -> For Developers -> Local Administration, as there are regular staff client menu entries for those now. git-svn-id: svn://svn.open-ils.org/ILS/trunk@18215 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Circ/Holds.pm | 82 ++++++++++++- ...lt_pull_list.html => alt_holds_print.html} | 115 ++++++++++++++++-- Open-ILS/web/opac/locale/en-US/lang.dtd | 9 +- .../xul/staff_client/server/admin/index.xhtml | 25 +--- .../xul/staff_client/server/patron/holds.js | 7 +- .../server/patron/holds_overlay.xul | 2 +- 6 files changed, 199 insertions(+), 41 deletions(-) rename Open-ILS/web/opac/extras/circ/{alt_pull_list.html => alt_holds_print.html} (55%) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm index 924d653c14..ebdaf5332a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm @@ -1749,8 +1749,8 @@ sub fetch_captured_holds { my( $self, $conn, $auth, $org ) = @_; my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; - return $e->event unless $e->allowed('VIEW_HOLD'); # XXX rely on editor perm + return $e->die_event unless $e->checkauth; + return $e->die_event unless $e->allowed('VIEW_HOLD'); # XXX rely on editor perm $org ||= $e->requestor->ws_ou; @@ -1802,6 +1802,84 @@ sub fetch_captured_holds { return undef; } +__PACKAGE__->register_method( + method => "print_expired_holds_stream", + api_name => "open-ils.circ.captured_holds.expired.print.stream", + stream => 1 +); + +sub print_expired_holds_stream { + my ($self, $client, $auth, $params) = @_; + + # No need to check specific permissions: we're going to call another method + # that will do that. + my $e = new_editor("authtoken" => $auth); + return $e->die_event unless $e->checkauth; + + delete($$params{org_id}) unless (int($$params{org_id})); + delete($$params{limit}) unless (int($$params{limit})); + delete($$params{offset}) unless (int($$params{offset})); + delete($$params{chunk_size}) unless (int($$params{chunk_size})); + delete($$params{chunk_size}) if ($$params{chunk_size} && $$params{chunk_size} > 50); # keep the size reasonable + $$params{chunk_size} ||= 10; + + $$params{org_id} = (defined $$params{org_id}) ? $$params{org_id}: $e->requestor->ws_ou; + + my @hold_ids = $self->method_lookup( + "open-ils.circ.captured_holds.id_list.expired_on_shelf.retrieve" + )->run($auth, $params->{"org_id"}); + + if (!@hold_ids) { + $e->disconnect; + return; + } elsif (defined $U->event_code($hold_ids[0])) { + $e->disconnect; + return $hold_ids[0]; + } + + $logger->info("about to stream back up to " . scalar(@hold_ids) . " expired holds"); + + while (@hold_ids) { + my @hid_chunk = splice @hold_ids, 0, $params->{"chunk_size"}; + + my $result_chunk = $e->json_query({ + "select" => { + "acp" => ["barcode"], + "au" => [qw/ + first_given_name second_given_name family_name alias + /], + "acn" => ["label"], + "bre" => ["marc"], + "acpl" => ["name"] + }, + "from" => { + "ahr" => { + "acp" => { + "field" => "id", "fkey" => "current_copy", + "join" => { + "acn" => { + "field" => "id", "fkey" => "call_number", + "join" => { + "bre" => { + "field" => "id", "fkey" => "record" + } + } + }, + "acpl" => {"field" => "id", "fkey" => "location"} + } + }, + "au" => {"field" => "id", "fkey" => "usr"} + } + }, + "where" => {"+ahr" => {"id" => \@hid_chunk}} + }) or return $e->die_event; + $client->respond($result_chunk); + } + + $e->disconnect; + undef; +} + __PACKAGE__->register_method( method => "check_title_hold_batch", api_name => "open-ils.circ.title_hold.is_possible.batch", diff --git a/Open-ILS/web/opac/extras/circ/alt_pull_list.html b/Open-ILS/web/opac/extras/circ/alt_holds_print.html similarity index 55% rename from Open-ILS/web/opac/extras/circ/alt_pull_list.html rename to Open-ILS/web/opac/extras/circ/alt_holds_print.html index 966ee4053d..370aa98ee0 100644 --- a/Open-ILS/web/opac/extras/circ/alt_pull_list.html +++ b/Open-ILS/web/opac/extras/circ/alt_holds_print.html @@ -50,13 +50,11 @@ dojo.require("openils.BibTemplate"); dojo.require("openils.widget.ProgressDialog"); - function my_init() { - var cgi = new CGI(); - var ses = (typeof ses == "function" ? ses() : 0) || - cgi.param("ses") || dojo.cookie("ses"); - var user = new openils.User({"authtoken": ses}); - + function do_pull_list(user, cgi) { progress_dialog.show(true); + + var any = false; + fieldmapper.standardRequest( ['open-ils.circ','open-ils.circ.hold_pull_list.print.stream'], { async : true, @@ -70,6 +68,7 @@ } ], onresponse : function (r) { + any = true; dojo.forEach( openils.Util.readResponse(r), function (hold_fm) { // hashify the hold @@ -101,17 +100,115 @@ dojo.place(tr, "target"); }); }, - oncomplete : function () { - progress_dialog.hide(); window.print() } + oncomplete : function () { + progress_dialog.hide(); + if (any) + window.print(); + else + alert(dojo.byId("no_results").innerHTML); + } } ); } + + function do_shelf_expired_holds(user, cgi) { + progress_dialog.show(true); + + var any = false; + fieldmapper.standardRequest( + ["open-ils.circ", + "open-ils.circ.captured_holds.expired.print.stream"], { + "async": true, + "params": [ + user.authtoken, { + "org_id": cgi.param("o"), + "limit": cgi.param("limit"), + "offset": cgi.param("offset"), + "chunk_size": cgi.param("chunk_size"), + "sort": sort_order + } + ], + "onresponse": function(r) { + dojo.forEach( + openils.Util.readResponse(r), + function(hold_fields) { + any = true; + /* munge this object to make it look like + the template expects */ + var hold = { + "usr": {}, + "current_copy": { + "barcode": hold_fields.barcode, + "call_number": { + "label": hold_fields.label, + "record": {"marc": hold_fields.marc} + }, + "location": {"name": hold_fields.name} + } + }; + if (hold_fields.alias) { + hold.usr.display_name = hold_fields.alias; + } else { + hold.usr.display_name = [ + (hold_fields.family_name ? hold_fields.family_name : ""), + (hold_fields.first_given_name ? hold_fields.first_given_name : ""), + (hold_fields.second_given_name ? hold_fields.second_given_name : "") + ].join(" "); + } + ["first_given_name","second_given_name","family_name","alias"].forEach(function(k) {hold.usr[k] = hold_fields[k]; }); + + // clone the template's html + var tr = dojo.clone( + dojo.query("tr", dojo.byId('template'))[0] + ); + dojo.query("td:not([type])", tr).forEach( + function(td) { + td.innerHTML = + dojo.string.substitute(td.innerHTML, hold); + } + ); + + new openils.BibTemplate({ + "root": tr, + "xml": dojox.xml.parser.parse(hold.current_copy.call_number.record.marc), + "delay": false + }); + + dojo.place(tr, "target"); + } + ); + }, + "oncomplete": function() { + progress_dialog.hide(); + if (any) + window.print(); + else + alert(dojo.byId("no_results").innerHTML); + } + } + ); + } + + function my_init() { + var cgi = new CGI(); + var ses = (typeof ses == "function" ? ses() : 0) || + cgi.param("ses") || dojo.cookie("ses"); + var user = new openils.User({"authtoken": ses}); + + if (cgi.param("do") == "shelf_expired_holds") { + do_shelf_expired_holds(user, cgi); + } else { + dojo.query("[only='shelf_expired_holds']").forEach(dojo.destroy); + do_pull_list(user, cgi); + } + } dojo.addOnLoad(my_init);
+
No results
@@ -122,6 +219,7 @@ + @@ -131,6 +229,7 @@ +
Shelving Location Call Number BarcodePatron
${current_copy.location.name} ${current_copy.call_number.label} ${current_copy.barcode}${usr.display_name}
diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 8b2b60645f..d507abbf25 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -1904,6 +1904,7 @@ + @@ -1915,14 +1916,6 @@ - - - - - - - - diff --git a/Open-ILS/xul/staff_client/server/admin/index.xhtml b/Open-ILS/xul/staff_client/server/admin/index.xhtml index aa01bc578b..60a3327ef3 100644 --- a/Open-ILS/xul/staff_client/server/admin/index.xhtml +++ b/Open-ILS/xul/staff_client/server/admin/index.xhtml @@ -24,10 +24,7 @@ function getBuildId() { return location.href.match(/\/xul\/(.+?)\/server\//)[1]; } function my_init() { - try { - dojo.require("dojo.cookie"); - window.xulG.auth = {"session": {"key": dojo.cookie("ses")}}; - } catch(E) { /* XXX ignorable except for booking links */ } + ; }