From 37a68bfd9f6ae2950a6051fdc282cd4027a84b03 Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 1 Sep 2010 22:57:49 +0000 Subject: [PATCH] Serials: checkbox for batch receive interface to en/disable receiving w units git-svn-id: svn://svn.open-ils.org/ILS/trunk@17431 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../src/perlmods/OpenILS/Application/Serial.pm | 68 +++++++++++--------- .../staff_client/server/serial/batch_receive.js | 73 ++++++++++++++++++---- .../server/serial/batch_receive_overlay.xul | 19 +++--- 3 files changed, 110 insertions(+), 50 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/OpenILS/Application/Serial.pm index 4b644076f..5a41d7a2d 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Serial.pm @@ -877,6 +877,35 @@ sub unitize_items { return {'num_items_received' => scalar @$items, 'new_unit_id' => $new_unit_id}; } +sub _find_or_create_call_number { + my ($e, $lib, $cn_string, $record) = @_; + + my $existing = $e->search_asset_call_number({ + "owning_lib" => $lib, + "label" => $cn_string, + "record" => $record, + "deleted" => "f" + }) or return $e->die_event; + + if (@$existing) { + return $existing->[0]->id; + } else { + return $e->die_event unless + $e->allowed("CREATE_VOLUME", $lib); + + my $acn = new Fieldmapper::asset::call_number; + + $acn->creator($e->requestor->id); + $acn->editor($e->requestor->id); + $acn->record($record); + $acn->label($cn_string); + $acn->owning_lib($lib); + + $e->create_asset_call_number($acn) or return $e->die_event; + return $e->data->id; + } +} + __PACKAGE__->register_method( "method" => "receive_items_one_unit_per", "api_name" => "open-ils.serial.receive_items.one_unit_per", @@ -959,36 +988,19 @@ sub receive_items_one_unit_per { } } + # Treat call number specially: the provided value from the + # user will really be a string. if ($user_unit->call_number) { - # call_number passed in will actually be a string representing - # a call_number label, not an actual acn object or even an ID. - # Therefore we must lookup the call_number requested, or - # create a new one if it does not exist for the given lib. - - my $existing = $e->search_asset_call_number({ - "owning_lib" => $sdist->holding_lib->id, - "label" => $user_unit->call_number, - "record" => $record, - "deleted" => "f" - }) or return $e->die_event; - - if (@$existing) { - $user_unit->call_number($existing->[0]->id); - } else { - return $e->die_event unless - $e->allowed("CREATE_VOLUME", $sdist->holding_lib->id); - - my $acn = new Fieldmapper::asset::call_number; - - $acn->creator($user_id); - $acn->editor($user_id); - $acn->record($record); - $acn->label($user_unit->call_number); - $acn->owning_lib($sdist->holding_lib->id); - - $e->create_asset_call_number($acn) or return $e->die_event; + my $real_cn = _find_or_create_call_number( + $e, $sdist->holding_lib->id, + $user_unit->call_number, $record + ); - $user_unit->call_number($e->data->id); + if ($U->event_code($real_cn)) { + $e->rollback; + return $real_cn; + } else { + $user_unit->call_number($real_cn); } } diff --git a/Open-ILS/xul/staff_client/server/serial/batch_receive.js b/Open-ILS/xul/staff_client/server/serial/batch_receive.js index a0bb48609..3e7ffd3a1 100644 --- a/Open-ILS/xul/staff_client/server/serial/batch_receive.js +++ b/Open-ILS/xul/staff_client/server/serial/batch_receive.js @@ -45,6 +45,19 @@ function show(e) { openils.Util.removeCSSClass(e, "hideme"); } +function hide_table_cell(e) { + if (typeof(e) == "string") e = dojo.byId(e); + + e.style.display = "none"; + e.style.visibility = "hidden"; +} + +function show_table_cell(e) { + if (typeof(e) == "string") e = dojo.byId(e); + e.style.display = "table-cell"; + e.style.visibility = "visible"; +} + function busy(on) { if (typeof(busy._window) == "undefined") busy._window = dojo.query("window")[0]; @@ -383,11 +396,18 @@ function BatchReceiver() { dojo.query("textbox,menulist", row).forEach( function(element) { element.disabled = disabled; } ); + this._row_disabled(row, disabled); }; - this._row_disabled = function(row) { + this._row_disabled = function(row, disabled) { if (typeof(row) == "string") row = this.rows[row]; - return !dojo.query("checkbox", row)[0].checked; + + var checkbox = dojo.query("checkbox", row)[0]; + + if (typeof(disabled) != "undefined") + checkbox.checked = !disabled; + + return !checkbox.checked; }; this._row_field_value = function(row, field, value) { @@ -460,11 +480,6 @@ function BatchReceiver() { }; this._call_number_confirm_for_lib = function(lib, value) { - /* XXX Right now, this method will ask the user if they're serious if - * they apply an _existing_ (somewhere) call number to an item - * going to a library where that call number _doesn't_ exist,but it - * won't say anything if the user enters a brand new call number. - * This may not be ideal, and can be reworked later. */ if (!this._has_confirmed_cn_for) this._has_confirmed_cn_for = {}; @@ -678,11 +693,11 @@ function BatchReceiver() { show("form_holder"); list.forEach(function(o) {self.add_entry_row(o);}); - if (list.length > 1) { - self.build_batch_entry_row(); - show("batch_receive_entry"); - } + self.build_batch_entry_row(); + dojo.byId("batch_receive_with_units").doCommand(); + + show("batch_receive_entry"); busy(false); } else { alert(S("item_lookup.none")); @@ -695,9 +710,38 @@ function BatchReceiver() { ); }; + this.toggle_receive_with_units = function(ev) { + var head_row = dojo.byId("batch_receive_entry_thead"); + var batch_row = dojo.byId("entry_batch_row"); + + var fields = [ + "barcode", "call_number", "price", "location", "circ_modifier" + ]; + + var table_cell_func = ev.target.checked ? + show_table_cell : hide_table_cell; + fields.forEach( + function(key) { + if (batch_row) table_cell_func(node_by_name(key, batch_row)); + if (head_row) table_cell_func(node_by_name(key, head_row)); + + for (var id in self.rows) { + table_cell_func(node_by_name(key, self.rows[id])); + } + } + ); + + if (!ev.target.checked) { + /* XXX As of the time of this writing, a blank barcode field will + * avoid unit creation */ + this._set_all_enabled_rows("barcode", ""); + } + }; + this.toggle_all_receive = function(checked) { - for (var id in this.rows) + for (var id in this.rows) { this._disable_row(id, !checked); + } }; this.build_batch_entry_row = function() { @@ -839,7 +883,10 @@ function BatchReceiver() { alert(S("missing_cn")); return; } else if (!confirmed_missing_units) { - if (confirm(S("missing_units"))) { + if ( + (!dojo.byId("batch_receive_with_units").checked) || + confirm(S("missing_units")) + ) { confirmed_missing_units = true; } else { return; diff --git a/Open-ILS/xul/staff_client/server/serial/batch_receive_overlay.xul b/Open-ILS/xul/staff_client/server/serial/batch_receive_overlay.xul index 46b158a8b..fe77020a1 100644 --- a/Open-ILS/xul/staff_client/server/serial/batch_receive_overlay.xul +++ b/Open-ILS/xul/staff_client/server/serial/batch_receive_overlay.xul @@ -83,28 +83,28 @@ - + &staff.serial.batch_receive.org_unit; - + &staff.serial.batch_receive.barcode; - + &staff.serial.batch_receive.circ_modifier; - + &staff.serial.batch_receive.call_number; &staff.serial.batch_receive.note; - + &staff.serial.batch_receive.location; - + &staff.serial.batch_receive.price; @@ -159,12 +159,13 @@