From ee433d2245480572f40f87ea69aebbe440b238b6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 29 Oct 2014 17:09:25 -0400 Subject: [PATCH] All Holdings Maintenance Code Smashed Together (2014.03.20) Cross-port: 115c74a Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm Open-ILS/xul/staff_client/server/cat/copy_browser.js Conflicts: Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm Open-ILS/xul/staff_client/chrome/content/main/constants.js --- .../HoldingsMaintenance/holdings_maintenance.SQL | 93 + .../holdings_maintenance_rollback.SQL | 3 + .../src/perlmods/lib/OpenILS/Application/Cat.pm | 74 + .../lib/OpenILS/Application/Search/Biblio.pm | 21 +- .../OpenILS/Application/Storage/Publisher/asset.pm | 123 +- .../src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm | 10 + .../staff_client/chrome/content/main/constants.js | 2 + .../xul/staff_client/chrome/content/util/list.js | 380 +- .../xul/staff_client/server/cat/copy_browser.js | 5510 +++++++++++++------- .../xul/staff_client/server/cat/copy_editor.js | 1 + Open-ILS/xul/staff_client/server/cat/util.js | 75 +- Open-ILS/xul/staff_client/server/circ/util.js | 2 +- Open-ILS/xul/staff_client/server/skin/cat.css | 23 + 13 files changed, 4252 insertions(+), 2065 deletions(-) create mode 100644 KCLS/sql/HoldingsMaintenance/holdings_maintenance.SQL create mode 100644 KCLS/sql/HoldingsMaintenance/holdings_maintenance_rollback.SQL diff --git a/KCLS/sql/HoldingsMaintenance/holdings_maintenance.SQL b/KCLS/sql/HoldingsMaintenance/holdings_maintenance.SQL new file mode 100644 index 0000000000..5968ac5d08 --- /dev/null +++ b/KCLS/sql/HoldingsMaintenance/holdings_maintenance.SQL @@ -0,0 +1,93 @@ +DROP FUNCTION IF EXISTS asset.get_holdings_maintenance_page(bigint); + +DROP TYPE IF EXISTS holdings_maintenance; + +CREATE TYPE holdings_maintenance AS (acn_create_date timestamp with time zone, acn_creator bigint, acn_deleted boolean, acn_edit_date timestamp with time zone, acn_editor bigint, +acn_id bigint, label text, acn_owning_lib integer, acn_record bigint, label_sortkey text, label_class bigint, prefix integer, suffix integer, age_protect integer, alert_message text, barcode text, call_numer bigint, +circ_as_type text, circ_lib integer, circ_modifier text, circulate boolean, copy_number integer, +create_date timestamp with time zone, active_date timestamp with time zone, creator bigint, deleted boolean, dummy_isbn text, +deposit boolean, deposit_amount numeric(6,2), dummy_author text, dummy_title text, edit_date timestamp with time zone, +editor bigint, fine_level integer, holdable boolean, id bigint, load_duration integer, location integer, +opac_visible boolean, price numeric(8,2), ref boolean, status integer, status_changed_time timestamp with time zone, +mint_condition boolean, floating boolean, cost numeric(8,2), checkin_lib integer, checkin_staff integer, +checkin_time timestamp with time zone, circ_circ_lib integer, circ_staff integer, desk_renewal boolean, due_date timestamp with time zone, +duration interval, duration_rule text, fine_interval interval, circ_id bigint, max_fine numeric(6,2), +max_fine_rule text, opac_renewal boolean, phone_renewal boolean, recurring_fine numeric(6,2), +recurring_fine_rule text, renewal_remaining integer, grace_period interval, stop_fines text, stop_fines_time timestamp with time zone, +target_copy bigint, usr integer, xact_finish timestamp with time zone, xact_start timestamp with time zone, create_time timestamp with time zone, workstation integer, +checkin_workstation integer, checkin_scan_time timestamp with time zone, parent_circ bigint, unrecovered boolean, copy_location integer); + +CREATE OR REPLACE FUNCTION asset.get_holdings_maintenance_page(tcn_value bigint) +RETURNS SETOF holdings_maintenance AS +$BODY$ + +DECLARE + r holdings_maintenance; + +BEGIN + +FOR r IN + +SELECT acn.create_date, acn.creator, acn.deleted, acn.edit_date, acn.editor, acn.id, acn.label, acn.owning_lib, acn.record, acn.label_sortkey, acn.label_class, acn.prefix, acn.suffix, acp.age_protect, acp.alert_message, acp.barcode, acp.call_number, acp.circ_as_type, acp.circ_lib, acp.circ_modifier, acp.circulate, acp.copy_number, acp.create_date, acp.active_date, acp.creator, acp.deleted, acp.dummy_isbn, acp.deposit, acp.deposit_amount, acp.dummy_author, acp.dummy_title, acp.edit_date, acp.editor, acp.fine_level, acp.holdable, acp.id, acp.loan_duration, acp.LOCATION, acp.opac_visible, acp.price, acp.REF, acp.STATUS, acp.status_changed_time, acp.mint_condition, acp.floating, acp.COST, circ.checkin_lib, circ.checkin_staff, circ.checkin_time, circ.circ_lib, circ.circ_staff, circ.desk_renewal, circ.due_date, circ.duration, circ.duration_rule, circ.fine_interval, circ.id, circ.max_fine, circ.max_fine_rule, circ.opac_renewal, circ.phone_renewal, circ.recurring_fine, circ.recurring_fine_rule, circ.renewal_remaining, circ.grace_period, circ.stop_fines, circ.stop_fines_time, circ.target_copy, circ.usr, circ.xact_finish, circ.xact_start, circ.create_time, circ.workstation, circ.checkin_workstation, circ.checkin_scan_time, circ.parent_circ, circ.unrecovered, circ.copy_location + + FROM asset.COPY AS acp + + JOIN asset.call_number acn ON (acp.call_number = acn.id) + JOIN actor.org_unit aou ON (acn.owning_lib = aou.id) + JOIN action.circulation circ ON (acp.id = circ.target_copy) + + + WHERE acn.record = tcn_value + AND circ.xact_start = ( + SELECT c.xact + FROM ( + SELECT target_copy, max(xact_start) AS xact + FROM action.circulation + WHERE target_copy = acp.id + GROUP BY target_copy) AS c) + AND aou.parent_ou = '1' + AND acn.deleted = 'f' + AND acn.LABEL <> '##URI##' + AND acp.deleted = 'f' + +UNION ALL + +SELECT acn.create_date, acn.creator, acn.deleted, acn.edit_date, acn.editor, acn.id, acn.label, acn.owning_lib, acn.record, acn.label_sortkey, acn.label_class, acn.prefix, acn.suffix, acp.age_protect, acp.alert_message, acp.barcode, acp.call_number, acp.circ_as_type, acp.circ_lib, acp.circ_modifier, acp.circulate, acp.copy_number, acp.create_date, acp.active_date, acp.creator, acp.deleted, acp.dummy_isbn, acp.deposit, acp.deposit_amount, acp.dummy_author, acp.dummy_title, acp.edit_date, acp.editor, acp.fine_level, acp.holdable, acp.id, acp.loan_duration, acp.LOCATION, acp.opac_visible, acp.price, acp.REF, acp.STATUS, acp.status_changed_time, acp.mint_condition, acp.floating, acp.COST, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null + + FROM asset.COPY AS acp + + JOIN asset.call_number acn ON (acp.call_number = acn.id) + JOIN actor.org_unit aou ON (acn.owning_lib = aou.id) + + + WHERE acn.record = tcn_value + AND acp.id NOT IN (SELECT circ.target_copy + FROM action.circulation circ + WHERE circ.target_copy = acp.id) + AND aou.parent_ou = '1' + AND acn.deleted = 'f' + AND acn.LABEL <> '##URI##' + AND acp.deleted = 'f' + +UNION ALL + +SELECT acn.create_date, acn.creator, acn.deleted, acn.edit_date, acn.editor, acn.id, acn.label, acn.owning_lib, acn.record, acn.label_sortkey, acn.label_class, acn.prefix, acn.suffix, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null + + FROM asset.call_number AS acn + LEFT OUTER JOIN asset.copy AS acp + ON acn.id = acp.call_number + WHERE acn.record = tcn_value + AND acp.id IS NULL + + + + +LOOP +RETURN NEXT r; +END LOOP; + +RETURN; + +END; +$BODY$ +LANGUAGE 'plpgsql' IMMUTABLE diff --git a/KCLS/sql/HoldingsMaintenance/holdings_maintenance_rollback.SQL b/KCLS/sql/HoldingsMaintenance/holdings_maintenance_rollback.SQL new file mode 100644 index 0000000000..419ccf8b8e --- /dev/null +++ b/KCLS/sql/HoldingsMaintenance/holdings_maintenance_rollback.SQL @@ -0,0 +1,3 @@ +DROP FUNCTION IF EXISTS asset.get_holdings_maintenance_page(bigint); + +DROP TYPE IF EXISTS holdings_maintenance; \ No newline at end of file diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 3fcd255e45..389a3e3638 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -22,6 +22,7 @@ use OpenILS::Perm; use OpenSRF::Utils::SettingsClient; use OpenSRF::Utils::Logger qw($logger); use OpenSRF::AppSession; +use OpenSRF::Utils::Cache; my $U = "OpenILS::Application::AppUtils"; my $conf; @@ -662,6 +663,8 @@ sub retrieve_copies { my( $self, $client, $user_session, $docid, @org_ids ) = @_; if(ref($org_ids[0])) { @org_ids = @{$org_ids[0]}; } + + $logger->debug("retrieve_copies $org_ids[0] id $docid"); $docid = "$docid"; @@ -686,6 +689,9 @@ sub retrieve_copies { for my $orgid (@org_ids) { my $vols = _build_volume_list($e, { record => $docid, owning_lib => $orgid, deleted => 'f', label => { '<>' => '##URI##' } } ); + + $logger->debug("retrieve_copies vols @$vols"); + push( @all_vols, @$vols ); } @@ -738,7 +744,12 @@ sub _build_volume_list { } ]); + $copies = [ sort { $a->barcode cmp $b->barcode } @$copies ]; + for my $c (@$copies) { + + $logger->debug("copy: ".Dumper($c)); + if( $c->status == OILS_COPY_STATUS_CHECKED_OUT ) { $c->circulations( $e->search_action_circulation( @@ -754,9 +765,20 @@ sub _build_volume_list { } } + + $volume->copies($copies); + + for my $item (@$volume) { + + $logger->debug("volume 2: ".Dumper($item)); + } + #$logger->debug("copies: ".Dumper($volume->copies)); + + push( @volumes, $volume ); } + #$session->disconnect(); return \@volumes; @@ -1687,7 +1709,59 @@ sub acn_sms_msg { ); } +__PACKAGE__->register_method( + api_name => 'open-ils.cat.asset.map_asset_by_call_number', + method => 'asset_by_call_number', + stream => 1 +); + +sub asset_by_call_number { + + my( $self, $client, $user_session, $docid, $current_index, $max_index ) = @_; + + my $cache = OpenSRF::Utils::Cache->new('global'); + my $returned; + if ($current_index && $max_index){ + + $current_index --; + my $key = 'maintenance_data'.($max_index - $current_index); + $returned = $cache->get_cache($key); + push(@{$returned},$current_index); + $cache->delete_cache($key); + $client->respond($returned); + } + + else{ + + my $meth = $self->method_lookup("open-ils.storage.asset.map_asset_by_call_number"); + + my ($key_pair_ref) = $meth->run($user_session, $docid); + + $logger->debug("cat key_pair: ".Dumper($key_pair_ref)); + + my $key_string = ${$key_pair_ref}[0];#'maintenance_data'; + my $index = ${$key_pair_ref}[1]; + + $logger->debug("cat key: ".$key_string.$index); + + # start at 0 + $returned = $cache->get_cache($key_string.'0'); + + # This is so we know how many batches there will be + # and which batch number we are on + push(@{$returned},$index + 1); + + $cache->delete_cache($key_string.'0'); # remove the cache + + $logger->debug("cat response: ".Dumper($returned)); + $logger->debug("cat response: ".${$returned}[(scalar @{$returned} - 1)]); + + $client->respond($returned); + } + + return undef; +} __PACKAGE__->register_method( method => "fixed_field_values_by_rec_type", diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index b1dbdbad0b..e5eab8f64c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2402,11 +2402,20 @@ sub fetch_cn { return $cn; } +sub fetch_copies_by_cn { + my( $self, $client, $id ) = @_; + + my $e = new_editor(); + my( $cn, $evt ) = $apputils->fetch_copies_by_call_number( $id ); + return $evt if $evt; + return $cn; +} + __PACKAGE__->register_method( - method => "fetch_fleshed_cn", - api_name => "open-ils.search.callnumber.fleshed.retrieve", + method => "fetch_copies_by_cn", + api_name => "open-ils.search.copies.retrieve.by_cn", authoritative => 1, - notes => "retrieves a callnumber based on ID, fleshing prefix, suffix, and label_class", + notes => "retrieves all copies for a given cn", ); sub fetch_fleshed_cn { @@ -2418,6 +2427,12 @@ sub fetch_fleshed_cn { return $cn; } +__PACKAGE__->register_method( + method => "fetch_fleshed_cn", + api_name => "open-ils.search.callnumber.fleshed.retrieve", + authoritative => 1, + notes => "retrieves a callnumber based on ID, fleshing prefix, suffix, and label_class", +); __PACKAGE__->register_method( method => "fetch_copy_by_cn", diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/asset.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/asset.pm index f5e3279a3b..34128b2a1a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/asset.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/asset.pm @@ -1,12 +1,11 @@ package OpenILS::Application::Storage::Publisher::asset; use base qw/OpenILS::Application::Storage/; -#use OpenILS::Application::Storage::CDBI::asset; -#use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils::Logger qw/:level/; use OpenSRF::EX qw/:try/; use OpenSRF::Utils::JSON; - -# +use Data::Dumper; +use Storable 'dclone'; +use OpenSRF::Utils::Cache; my $log = 'OpenSRF::Utils::Logger'; @@ -877,4 +876,120 @@ __PACKAGE__->register_method( api_level => 1, ); + +__PACKAGE__->register_method( + api_name => 'open-ils.storage.asset.map_asset_by_call_number', + method => 'map_asset_by_call_number' + +); + +sub map_asset_by_call_number { + + my( $self, $client, $user_session, $docid ) = @_; + + # Build SQL statement + my $select = <<" SQL"; + + SELECT * FROM asset.get_holdings_maintenance_page($docid); + SQL + + # Load and execute statement + my $sth = asset::stat_cat->db_Main->prepare_cached($select); + + $sth->execute(); + + # Catch DB response + my @holder_array = @{ $sth->fetchall_arrayref }; + + return format_asset_map(\@holder_array); +} + +# Takes an array of strings from get_holdings_maintenance_page and +# fieldmaps it +sub format_asset_map{ + + my $result = shift; + + $log->debug("result_array: ".Dumper($result)); + + my @copy_list = @{ $result }; + + my @finalized_copy_list; + + foreach my $copy (@copy_list){ + + my @copy_items = @{ $copy }; + my @finalized_copy; + + foreach my $item (@copy_items){ + + #2011-08-10T14:16:12-0700 + if ($item =~ m/"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.*"/){ + + # Replace the T with a space + $item =~ s/ /T/g; + + # Clobber all the quotes + $item =~ s/"//g; + + # Clobber the milliseconds + $item =~ s/\.[0-9]+//g; + + # Add minutes to the time zone + $item = $item.'00'; + } + + # Clobber bookend quotes if they're there + if ($item =~ m/^"(.*)"$/){ + + $item = $1; + } + + push(@finalized_copy, $item); + } + + push(@finalized_copy_list, \@finalized_copy); + } + + $log->debug("asset holdings: ".Dumper(\@finalized_copy_list)); + my $key = 'maintenance_data'; + + #100 copies at a time appears to be optimal + #These times are for TCN 467795 (4085 copies) + #250-1:22 50-1:29 500-1:28 100-1:16 + my $copies_at_a_time = 100; + my $end = $copies_at_a_time; + my $start = 0; + my $index = 0; + my @response; + my $cache = OpenSRF::Utils::Cache->new('global'); + + while ($end < scalar @finalized_copy_list){ + + @response = @finalized_copy_list[$start..$end]; + $cache->put_cache($key.$index, \@response); + + $end += $copies_at_a_time; + $start += $copies_at_a_time; + $index++; + } + + @response = @finalized_copy_list[$start .. $#finalized_copy_list]; + + $log->debug("asset response: ".Dumper(\@response)); + + $cache->put_cache($key.$index, \@response); + + my @key_pair; + + push(@key_pair, $key); + push(@key_pair, $index); + + $log->debug("asset key_pair: ".Dumper(\@key_pair)); + + return \@key_pair; +} + + + 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm index 749f9b99ab..7c7569780d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/Fieldmapper.pm @@ -413,6 +413,16 @@ sub real_fields { return @f; } +sub all_fields { + my $self = shift; + my $class_name = $self->class_name; + my $fields = $$fieldmap{$class_name}{fields}; + + my @f = sort {$$fields{$a}{position} <=> $$fields{$b}{position}} keys %$fields; + + return @f; +} + sub has_field { my $self = shift; my $field = shift; diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index b7412821ae..3d8a78d443 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -101,6 +101,7 @@ var api = { //'FM_ACP_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed.retrieve' }, 'FM_ACP_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed2.retrieve', 'secure' : false }, //'FM_ACP_RETRIEVE_VIA_BARCODE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.find_by_barcode' }, + 'FM_ACP_BATCH_RETRIEVE_VIA_ACN_LIST' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.copies.retrieve.by_cn', 'secure' : false }, 'FM_ACP_RETRIEVE_VIA_BARCODE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed2.find_by_barcode', 'secure' : false }, 'FM_ACP_RETRIEVE_VIA_BARCODE.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed2.find_by_barcode.authoritative', 'secure' : false }, 'FM_ACP_FLESHED_BATCH_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.asset.copy.fleshed.batch.retrieve', 'secure' : false }, @@ -374,6 +375,7 @@ var api = { 'USER_ORG_UNIT_OPT_IN_CHECK' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.org_unit_opt_in.check' }, 'USER_ORG_UNIT_OPT_IN_CREATE' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.user.org_unit_opt_in.create' }, 'GET_BARCODES' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.get_barcodes' }, + 'MAP_ASSET' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.map_asset_by_call_number' }, 'ADJUST_BILLS_TO_ZERO' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.money.billable_xact.adjust_to_zero' }, 'PATRON_MESSAGE_LIST' : { 'app' : 'open-ils.actor', 'method' : 'open-ils.actor.patron_message_list' } } diff --git a/Open-ILS/xul/staff_client/chrome/content/util/list.js b/Open-ILS/xul/staff_client/chrome/content/util/list.js index f9a962fac3..41f9a6d22c 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/list.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/list.js @@ -135,14 +135,14 @@ util.list.prototype = { treecol, 'click', function(ev) { - setTimeout( - function() { - var toggle = ev.target.getAttribute('toggleAll') || 'on'; - if (toggle == 'off') toggle = 'on'; else toggle = 'off'; - ev.target.setAttribute('toggleAll',toggle); - obj._toggle_checkbox_column(ev.target,toggle); - }, 0 - ); + //setTimeout( + //function() { + var toggle = ev.target.getAttribute('toggleAll') || 'on'; + if (toggle == 'off') toggle = 'on'; else toggle = 'off'; + ev.target.setAttribute('toggleAll',toggle); + obj._toggle_checkbox_column(ev.target,toggle); + //}, 0 + //); }, false ); @@ -265,11 +265,13 @@ util.list.prototype = { ); if (r) { - setTimeout( do_it, 0 ); + //setTimeout( + do_it;//, 0 ); } } else { - setTimeout( do_it, 0 ); + //setTimeout( + do_it;//, 0 ); } }, @@ -322,15 +324,6 @@ util.list.prototype = { false ); } - - /* - obj.event_listeners.add( - this.node, - 'mousemove', - function(ev) { obj.detect_visible(); }, - false - ); - */ obj.event_listeners.add( this.node, 'keypress', @@ -351,17 +344,6 @@ util.list.prototype = { ); /* FIXME -- find events on scrollbar to trigger this */ obj.detect_visible_polling(); - /* - var scrollbar = document.getAnonymousNodes( document.getAnonymousNodes(this.node)[1] )[1]; - var slider = document.getAnonymousNodes( scrollbar )[2]; - alert('scrollbar = ' + scrollbar.nodeName + ' grippy = ' + slider.nodeName); - scrollbar.addEventListener('click',function(){alert('sb click');},false); - scrollbar.addEventListener('command',function(){alert('sb command');},false); - scrollbar.addEventListener('scroll',function(){alert('sb scroll');},false); - slider.addEventListener('click',function(){alert('slider click');},false); - slider.addEventListener('command',function(){alert('slider command');},false); - slider.addEventListener('scroll',function(){alert('slider scroll');},false); - */ obj.event_listeners.add(this.node, 'scroll',function(){ obj.auto_retrieve(); },false); this.restores_columns(params); @@ -516,7 +498,8 @@ util.list.prototype = { this.error.sdump('D_LIST','Clearing list ' + this.node.getAttribute('id') + '\n'); this.row_count.total = 0; this.row_count.fleshed = 0; - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + //setTimeout( function() { + obj.exec_on_all_fleshed();// }, 0 ); }, '_clear_tree' : function(params) { @@ -557,7 +540,8 @@ util.list.prototype = { } this.row_count.total++; if (this.row_count.fleshed == this.row_count.total) { - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + + obj.exec_on_all_fleshed(); } rparams.treeitem_node.setAttribute('unique_row_counter',obj.unique_row_counter); rparams.unique_row_counter = obj.unique_row_counter++; @@ -606,38 +590,55 @@ util.list.prototype = { var treeitem = document.createElement('treeitem'); treeitem.setAttribute('retrieve_id',params.retrieve_id); + if (typeof params.to_bottom != 'undefined') { + treechildren_node.appendChild( treeitem ); + if (typeof params.no_auto_select == 'undefined') { + if (!obj.auto_select_pending) { + obj.auto_select_pending = true; - setTimeout(function() { - dump('auto-selecting\n'); - var idx = Number(obj.node.view.rowCount)-1; - try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } - try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } - obj.auto_select_pending = false; - try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } - }, 1000); + + dump('auto-selecting\n'); + var idx = Number(obj.node.view.rowCount)-1; + try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } + try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } + obj.auto_select_pending = false; + try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } } } } else { - if (treechildren_node.firstChild) { - treechildren_node.insertBefore( treeitem, treechildren_node.firstChild ); - } else { - treechildren_node.appendChild( treeitem ); - } - if (typeof params.no_auto_select == 'undefined') { - if (!obj.auto_select_pending) { - obj.auto_select_pending = true; - setTimeout(function() { - try { obj.node.view.selection.select(0); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } - try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } + + if (!params.add_before || params.add_before == null) { + + if (treechildren_node.firstChild) { + + treechildren_node.insertBefore( treeitem, treechildren_node.firstChild ); + + } else { + treechildren_node.appendChild( treeitem ); + } + if (typeof params.no_auto_select == 'undefined') { + if (!obj.auto_select_pending) { + + obj.auto_select_pending = true; + try { obj.node.view.selection.select(0); } + catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } + try { if (typeof params.on_select == 'function') params.on_select(); } + catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } obj.auto_select_pending = false; - try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } - }, 1000); + try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(0).firstChild); } + catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } + } } } + + else{ + + treechildren_node.insertBefore( treeitem, params.add_before ); + } } var treerow = document.createElement('treerow'); treeitem.appendChild( treerow ); @@ -647,8 +648,6 @@ util.list.prototype = { s += ('tree = ' + this.node + ' treechildren = ' + treechildren_node + '\n'); s += ('treeitem = ' + treeitem + ' treerow = ' + treerow + '\n'); - obj.put_retrieving_label(treerow); - if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') { obj.event_listeners.add( treerow, @@ -659,14 +658,14 @@ util.list.prototype = { treerow.setAttribute('retrieved','true'); - //dump('fleshing = ' + params.retrieve_id + '\n'); - function inc_fleshed() { if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */ treerow.setAttribute('fleshed','true'); obj.row_count.fleshed++; if (obj.row_count.fleshed >= obj.row_count.total) { - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + + obj.exec_on_all_fleshed(); + } } @@ -684,7 +683,7 @@ util.list.prototype = { util.widgets.dispatch('select',obj.node); } } catch(E) { - // Let's not alert on this for now. Getting contentView has no properties in record buckets under certain conditions + dump('fixme2: ' + E + '\n'); } } @@ -695,11 +694,11 @@ util.list.prototype = { } else if (typeof obj.retrieve_row == 'function') { - obj.retrieve_row( params ); + obj.retrieve_row( params ); } else { - - inc_fleshed(); + + inc_fleshed(); } obj.refresh_ordinals(); }, @@ -707,11 +706,8 @@ util.list.prototype = { ); if (typeof params.flesh_immediately != 'undefined') { if (params.flesh_immediately) { - setTimeout( - function() { - util.widgets.dispatch('flesh',treerow); - }, 0 - ); + + util.widgets.dispatch('flesh',treerow); } } } else { @@ -719,48 +715,48 @@ util.list.prototype = { treerow, 'flesh', function() { - //dump('fleshing anon\n'); + if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */ obj._map_row_to_treecell(params,treerow); treerow.setAttribute('retrieved','true'); treerow.setAttribute('fleshed','true'); obj.row_count.fleshed++; if (obj.row_count.fleshed >= obj.row_count.total) { - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + + obj.exec_on_all_fleshed(); } obj.refresh_ordinals(); }, false ); + if (typeof params.flesh_immediately != 'undefined') { + if (params.flesh_immediately) { - setTimeout( - function() { - util.widgets.dispatch('flesh',treerow); - }, 0 - ); + + util.widgets.dispatch('flesh',treerow); } } } this.error.sdump('D_LIST',s); - try { + try { - if (obj.trim_list && obj.row_count.total >= obj.trim_list) { - // Remove oldest row - //if (typeof params.to_bottom != 'undefined') - if (typeof params.to_top == 'undefined') { - if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); } - treechildren_node.removeChild( treechildren_node.firstChild ); - } else { - if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); } - treechildren_node.removeChild( treechildren_node.lastChild ); - } + if (obj.trim_list && obj.row_count.total >= obj.trim_list) { + + if (typeof params.to_top == 'undefined') { + if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.firstChild.getAttribute('unique_row_counter') ); } + treechildren_node.removeChild( treechildren_node.firstChild ); + } else { + if (typeof params.on_delete == 'function') { params.on_delete( treechildren_node.lastChild.getAttribute('unique_row_counter') ); } + treechildren_node.removeChild( treechildren_node.lastChild ); } - } catch(E) { } + } catch(E) { + } - setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 ); + obj.auto_retrieve(); + obj.refresh_ordinals(); params.treeitem_node = treeitem; return params; @@ -782,14 +778,14 @@ util.list.prototype = { if (typeof params.no_auto_select == 'undefined') { if (!obj.auto_select_pending) { obj.auto_select_pending = true; - setTimeout(function() { - dump('auto-selecting\n'); - var idx = Number(obj.node.view.rowCount)-1; - try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } - try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } - obj.auto_select_pending = false; - try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } - }, 1000); + //setTimeout(function() { + dump('auto-selecting\n'); + var idx = Number(obj.node.view.rowCount)-1; + try { obj.node.view.selection.select(idx); } catch(E) { obj.error.sdump('D_WARN','tree auto select: ' + E + '\n'); } + try { if (typeof params.on_select == 'function') params.on_select(); } catch(E) { obj.error.sdump('D_WARN','tree auto select, on_select: ' + E + '\n'); } + obj.auto_select_pending = false; + try { util.widgets.dispatch('flesh',obj.node.contentView.getItemAtIndex(idx).firstChild); } catch(E) { obj.error.sdump('D_WARN','tree auto select, flesh: ' + E + '\n'); } + //}, 1000); } } } @@ -823,14 +819,13 @@ util.list.prototype = { treerow.setAttribute('retrieved','true'); - //dump('fleshing = ' + params.retrieve_id + '\n'); - function inc_fleshed() { if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */ treerow.setAttribute('fleshed','true'); obj.row_count.fleshed++; if (obj.row_count.fleshed >= obj.row_count.total) { - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + + obj.exec_on_all_fleshed(); } } @@ -859,11 +854,11 @@ util.list.prototype = { } else if (typeof obj.retrieve_row == 'function') { - obj.retrieve_row( params ); + obj.retrieve_row( params ); } else { - inc_fleshed(); + inc_fleshed(); } obj.refresh_ordinals(); }, @@ -871,11 +866,8 @@ util.list.prototype = { ); if (typeof params.flesh_immediately != 'undefined') { if (params.flesh_immediately) { - setTimeout( - function() { - util.widgets.dispatch('flesh',treerow); - }, 0 - ); + + util.widgets.dispatch('flesh',treerow); } } @@ -887,14 +879,15 @@ util.list.prototype = { treerow, 'flesh', function() { - //dump('fleshing anon\n'); + if (treerow.getAttribute('fleshed') == 'true') return; /* already fleshed */ obj._map_row_to_treecell(params,treerow); treerow.setAttribute('retrieved','true'); treerow.setAttribute('fleshed','true'); obj.row_count.fleshed++; if (obj.row_count.fleshed >= obj.row_count.total) { - setTimeout( function() { obj.exec_on_all_fleshed(); }, 0 ); + + obj.exec_on_all_fleshed(); } obj.refresh_ordinals(); }, @@ -902,31 +895,28 @@ util.list.prototype = { ); if (typeof params.flesh_immediately != 'undefined') { if (params.flesh_immediately) { - setTimeout( - function() { - util.widgets.dispatch('flesh',treerow); - }, 0 - ); + + util.widgets.dispatch('flesh',treerow); } } } - try { + try { - if (obj.trim_list && obj.row_count.total >= obj.trim_list) { - // Remove oldest row - //if (typeof params.to_bottom != 'undefined') - if (typeof params.to_top == 'undefined') { - treechildren_node.removeChild( treechildren_node.firstChild ); - } else { - treechildren_node.removeChild( treechildren_node.lastChild ); - } + if (obj.trim_list && obj.row_count.total >= obj.trim_list) { + // Remove oldest row + if (typeof params.to_top == 'undefined') { + treechildren_node.removeChild( treechildren_node.firstChild ); + } else { + treechildren_node.removeChild( treechildren_node.lastChild ); } - } catch(E) { } + } catch(E) { + } - setTimeout( function() { obj.auto_retrieve(); obj.refresh_ordinals(); }, 0 ); + obj.auto_retrieve(); + obj.refresh_ordinals(); JSAN.use('util.widgets'); util.widgets.dispatch('select',obj.node); @@ -1051,32 +1041,32 @@ util.list.prototype = { var obj = this; if (!obj.auto_retrieve_in_progress) { obj.auto_retrieve_in_progress = true; - setTimeout( - function() { - try { - //alert('auto_retrieve\n'); - var count = 0; - var startpos = obj.node.treeBoxObject.getFirstVisibleRow(); - var endpos = obj.node.treeBoxObject.getLastVisibleRow(); - if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength(); - //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n'); - for (var i = startpos; i < endpos + 4; i++) { - try { - //dump('trying index ' + i + '\n'); - var item = obj.node.contentView.getItemAtIndex(i).firstChild; - if (item && item.getAttribute('retrieved') != 'true' ) { - //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n'); - util.widgets.dispatch('flesh',item); count++; - } - } catch(E) { - //dump(i + ' : ' + E + '\n'); - } - } - obj.auto_retrieve_in_progress = false; - return count; - } catch(E) { alert(E); } - }, 1 - ); + //setTimeout( + //function() { + try { + //alert('auto_retrieve\n'); + var count = 0; + var startpos = obj.node.treeBoxObject.getFirstVisibleRow(); + var endpos = obj.node.treeBoxObject.getLastVisibleRow(); + if (startpos > endpos) endpos = obj.node.treeBoxObject.getPageLength(); + //dump('startpos = ' + startpos + ' endpos = ' + endpos + '\n'); + for (var i = startpos; i < endpos + 4; i++) { + try { + //dump('trying index ' + i + '\n'); + var item = obj.node.contentView.getItemAtIndex(i).firstChild; + if (item && item.getAttribute('retrieved') != 'true' ) { + //dump('\tgot an unfleshed item = ' + item + ' = ' + item.nodeName + '\n'); + util.widgets.dispatch('flesh',item); count++; + } + } catch(E) { + //dump(i + ' : ' + E + '\n'); + } + } + obj.auto_retrieve_in_progress = false; + return count; + } catch(E) { alert(E); } + //}, 1 + //); } }, @@ -1086,27 +1076,27 @@ util.list.prototype = { if (obj.on_all_fleshed) { if (typeof obj.on_all_fleshed == 'function') { dump('exec_on_all_fleshed == function\n'); - setTimeout( - function() { - try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); } - }, 0 - ); + //setTimeout( + //function() { + try { obj.on_all_fleshed(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',obj.on_all_fleshed); } + //}, 0 + //); } else if (typeof obj.on_all_fleshed.length != 'undefined') { dump('exec_on_all_fleshed == array\n'); - setTimeout( - function() { - try { - dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n'); - var f = obj.on_all_fleshed.pop(); - if (typeof f == 'function') { - try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',E); } - } - if (obj.on_all_fleshed.length > 0) arguments.callee(); - } catch(E) { - obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E); - } - }, 0 - ); + //setTimeout( + //function() { + try { + dump('exec_on_all_fleshed, processing on_all_fleshed array, length = ' + obj.on_all_fleshed.length + '\n'); + var f = obj.on_all_fleshed.pop(); + if (typeof f == 'function') { + try { f(); } catch(E) { obj.error.standard_unexpected_error_alert('_full_retrieve_tree callback',E); } + } + if (obj.on_all_fleshed.length > 0) arguments.callee(); + } catch(E) { + obj.error.standard_unexpected_error_alert('exec_on_all_fleshed callback error',E); + } + //}, 0 + //); } else { obj.error.standard_unexpected_error_alert('unexpected on_all_fleshed object: ', obj.on_all_fleshed); } @@ -1158,34 +1148,34 @@ util.list.prototype = { if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') { - setTimeout( - function() { - listitem.setAttribute('retrieve_id',params.retrieve_id); - //FIXME//Make async and fire when row is visible in list - var row; - - params.treeitem_node = listitem; - params.on_retrieve = function(row) { - params.row = row; - obj._map_row_to_listcell(params,listitem); - obj.node.appendChild( listitem ); - util.widgets.dispatch('select',obj.node); - } + //setTimeout( + //function() { + listitem.setAttribute('retrieve_id',params.retrieve_id); + //FIXME//Make async and fire when row is visible in list + var row; - if (typeof params.retrieve_row == 'function') { + params.treeitem_node = listitem; + params.on_retrieve = function(row) { + params.row = row; + obj._map_row_to_listcell(params,listitem); + obj.node.appendChild( listitem ); + util.widgets.dispatch('select',obj.node); + } - row = params.retrieve_row( params ); + if (typeof params.retrieve_row == 'function') { - } else { + row = params.retrieve_row( params ); - if (typeof obj.retrieve_row == 'function') { + } else { - row = obj.retrieve_row( params ); + if (typeof obj.retrieve_row == 'function') { - } - } - }, 0 - ); + row = obj.retrieve_row( params ); + + } + } + //}, 0 + //); } else { this._map_row_to_listcell(params,listitem); this.node.appendChild( listitem ); @@ -2095,15 +2085,15 @@ util.list.prototype = { var def = { 'id' : col_id, 'label' : my_field.label || my_field.name, - 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' : - ( my_field.datatype == 'money' ? 'money' : + 'sort_type' : [ 'int', 'float', 'id', 'number' ].indexOf(my_field.datatype) > -1 ? 'number' : + ( my_field.datatype == 'money' ? 'money' : ( my_field.datatype == 'timestamp' ? 'date' : 'default')), 'hidden' : my_field.virtual || my_field.datatype == 'link', 'flex' : 1 - }; + }; // my_field.datatype => bool float id int interval link money number org_unit text timestamp if (my_field.datatype == 'link') { - def.render = function(my) { + def.render = function(my) { // is the object fleshed? return my[dataobj][datafield]() && typeof my[dataobj][datafield]() == 'object' // yes, show the display field @@ -2121,7 +2111,7 @@ util.list.prototype = { ) // no, just show the raw value : my[dataobj][datafield]() - ); + ); } } else { def.render = function(my) { return my[dataobj][datafield](); } diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.js b/Open-ILS/xul/staff_client/server/cat/copy_browser.js index 327b45b70b..8e0b42daa6 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -1,2009 +1,3799 @@ dump('entering cat.copy_browser.js\n'); -// vim:noet:sw=4:ts=4: + +JSAN.use('cat.util'); +JSAN.use('util.network'); +JSAN.use('OpenILS.data'); +JSAN.use('util.file'); +JSAN.use('util.error'); +JSAN.use('util.controller'); +JSAN.use('util.functional'); +JSAN.use('circ.util'); +JSAN.use('util.window'); +JSAN.use('util.widgets'); +JSAN.use('util.list'); if (typeof cat == 'undefined') cat = {}; + cat.copy_browser = function (params) { try { - JSAN.use('util.error'); this.error = new util.error(); + this.error = new util.error(); } catch(E) { - dump('cat.copy_browser: ' + E + '\n'); + dump('cat.copy_browser: ' + E + '\n'); } } +const AVAILABLE = 0; +const MISSING = 4; +const DAMAGED = 14; + cat.copy_browser.prototype = { - 'map_tree' : {}, - 'map_acn' : {}, - 'map_acp' : {}, - 'sel_list' : [], - 'funcs' : [], + 'map_tree' : {}, + 'map_acn' : {}, + 'map_acp' : {}, + 'sel_list' : [], + 'org_ids' : [], + 'hashOfVolumes' : {}, // lib : [volume ids] + 'copy_count' : {}, + 'open_objs' : {}, + 'transferring' : false, + + 'init' : function( params ) { + + try { + + var obj = this; + + obj.docid = params.docid; + + + obj.network = new util.network(); + obj.data = new OpenILS.data(); + obj.data.init({'via':'stash'}); + + obj.full_data_reload(); + + obj.controller_init(params); + + obj.list_init(params); + + obj.source_init(); + + obj.controller.render(); + + obj.default_depth = obj.depth_menu_init(); + obj.default_lib = obj.data.hash.aou[ obj.library_menu_init() ]; + + document.getElementById('show_acns').addEventListener( + 'command', + function(ev) { + + var file = new util.file( + 'copy_browser_prefs.'+obj.data.server_unadorned); + util.widgets.save_attributes(file, { + 'lib_menu' : [ 'value' ], + 'depth_menu' : [ 'value' ], + 'show_acns' : [ 'checked' ], + 'show_acps' : [ 'checked' ], + 'hide_aous' : [ 'checked' ] }); + }, + false + ); + + document.getElementById('show_acps').addEventListener( + 'command', + function(ev) { + + var file = new util.file( + 'copy_browser_prefs.'+obj.data.server_unadorned); + util.widgets.save_attributes(file, { + 'lib_menu' : [ 'value' ], + 'depth_menu' : [ 'value' ], + 'show_acns' : [ 'checked' ], + 'show_acps' : [ 'checked' ], + 'hide_aous' : [ 'checked' ] }); + }, + false + ); + + document.getElementById('hide_aous').addEventListener( + 'command', + function(ev) { + + var file = new util.file( + 'copy_browser_prefs.'+obj.data.server_unadorned); + util.widgets.save_attributes(file, { + 'lib_menu' : [ 'value' ], + 'depth_menu' : [ 'value' ], + 'show_acns' : [ 'checked' ], + 'show_acps' : [ 'checked' ], + 'hide_aous' : [ 'checked' ] }); + }, + false + ); + + obj.show_my_libs( obj.default_lib.id() ); + obj.show_consortial_count(); + + document.getElementById('cat_copy_browser').removeChild(document.getElementById('loading_bar_box')); + } catch(E) { + this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E); + } + }, - 'init' : function( params ) { + // This clobbers all local data and reloads it all from the DB + 'full_data_reload' : function(){ - try { - var obj = this; + var obj = this; - obj.docid = params.docid; + try{ - JSAN.use('util.network'); obj.network = new util.network(); - JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'}); + obj.map_tree = {}; + obj.map_acn = {}; + obj.map_acp = {}; + obj.sel_list = []; + obj.org_ids = []; + obj.hashOfVolumes = {}; + obj.copy_count = {}; + obj.open_objs = {}; - obj.controller_init(params); + // This grabs all the relevant data in one go so we don't have + // frequent calls to the DB + var returnedArray = obj.network.simple_request('MAP_ASSET',[ ses(), obj.docid ]); - obj.list_init(params); + if (returnedArray === null){ - obj.source_init(); + throw("Database error: MAP_ASSET did not return expected results. copy_browser.js:39"); + } - obj.controller.render(); + var total_batches = returnedArray.pop(); + var listOfCopies = returnedArray; - obj.default_depth = obj.depth_menu_init(); - obj.default_lib = obj.data.hash.aou[ obj.library_menu_init() ]; - document.getElementById('show_acns').addEventListener( - 'command', - function(ev) { - JSAN.use('util.file'); - var file = new util.file( - 'copy_browser_prefs.'+obj.data.server_unadorned); - util.widgets.save_attributes(file, { - 'lib_menu' : [ 'value' ], - 'depth_menu' : [ 'value' ], - 'show_acns' : [ 'checked' ], - 'show_acps' : [ 'checked' ], - 'hide_aous' : [ 'checked' ] }); - }, - false - ); + var current_batch = total_batches; + var loading_bar_box = document.createElement('div'); + loading_bar_box.id = "loading_bar_box"; + var loading_bar = document.createElement('div'); + loading_bar.id = "loading_bar"; + loading_bar_box.appendChild(loading_bar); + document.getElementById('cat_copy_browser').appendChild(loading_bar_box); - document.getElementById('show_acps').addEventListener( - 'command', - function(ev) { - JSAN.use('util.file'); - var file = new util.file( - 'copy_browser_prefs.'+obj.data.server_unadorned); - util.widgets.save_attributes(file, { - 'lib_menu' : [ 'value' ], - 'depth_menu' : [ 'value' ], - 'show_acns' : [ 'checked' ], - 'show_acps' : [ 'checked' ], - 'hide_aous' : [ 'checked' ] }); - }, - false - ); + var percentDone = (total_batches - current_batch) / (parseFloat(total_batches)) * 100; - document.getElementById('hide_aous').addEventListener( - 'command', - function(ev) { - JSAN.use('util.file'); - var file = new util.file( - 'copy_browser_prefs.'+obj.data.server_unadorned); - util.widgets.save_attributes(file, { - 'lib_menu' : [ 'value' ], - 'depth_menu' : [ 'value' ], - 'show_acns' : [ 'checked' ], - 'show_acps' : [ 'checked' ], - 'hide_aous' : [ 'checked' ] }); - }, - false - ); + while(current_batch > 1){ - obj.show_my_libs( obj.default_lib.id() ); + returnedArray = obj.network.simple_request('MAP_ASSET',[ ses(), obj.docid, current_batch, total_batches]); + current_batch = returnedArray.pop(); + percentDone = (total_batches - current_batch) / (total_batches * 1.0) * 100; + loading_bar.style.width = percentDone + "%"; - JSAN.use('util.exec'); var exec = new util.exec(20); exec.timer(obj.funcs,100); + listOfCopies = listOfCopies.concat(returnedArray); + } - obj.show_consortial_count(); + var orgSet = {}; - } catch(E) { - this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E); - } - }, + obj.copy_count.count = 0; + obj.copy_count.available = 0; - 'controller_init' : function(params) { - var obj = this; - try { - JSAN.use('util.controller'); obj.controller = new util.controller(); - obj.controller.init( - { - control_map : { - 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ], - 'sel_clip' : [ - ['command'], - function() { obj.list.clipboard(); } - ], - 'cmd_broken' : [ - ['command'], - function() { - alert(document.getElementById('commonStrings').getString('common.unimplemented')); - } - ], - 'cmd_show_my_libs' : [ - ['command'], - function() { - obj.show_my_libs(); - } - ], - 'cmd_show_all_libs' : [ - ['command'], - function() { - obj.show_all_libs(); - } - ], - 'cmd_show_libs_with_copies' : [ - ['command'], - function() { - obj.show_libs_with_copies(); - } - ], - 'cmd_clear' : [ - ['command'], - function() { - obj.map_tree = {}; - obj.list.clear(); - } - ], - 'cmd_request_items' : [ - ['command'], - function() { - JSAN.use('cat.util'); JSAN.use('util.functional'); - - var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); - - list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); - - cat.util.request_items( list ); - } - ], - 'sel_mark_items_damaged' : [ - ['command'], - function() { - JSAN.use('cat.util'); JSAN.use('util.functional'); - - var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); - - list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); - - cat.util.mark_item_damaged( list ); - - obj.refresh_list(); - } - ], - 'sel_mark_items_missing' : [ - ['command'], - function() { - JSAN.use('cat.util'); JSAN.use('util.functional'); - - var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); - - list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); - - cat.util.mark_item_missing( list ); - - obj.refresh_list(); - } - ], - 'sel_patron' : [ - ['command'], - function() { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); + // For list of copy info in the list of copies + // Make a new object from the template and insert copy data + for (var i in listOfCopies){ + + // count copies + obj.copy_count.count ++; + + var volumeVars = listOfCopies[i].slice(0,13); + var copyVars = listOfCopies[i].slice(13,46); + var circVars = listOfCopies[i].slice(46,79); + + // This checks if the id is null + // If it is, then this is an empty volume + if (copyVars[22] != null){ + + var copy = makeCopy(copyVars); + + // Slap 6 nulls after element 20 + circVars = circVars.slice(0,20).concat( + [null,null,null,null,null], + circVars.slice(20)); + + var circ = makeCirc(circVars); + + // Count available copies + if (copy.status() == AVAILABLE){ + + obj.copy_count.available ++; + } + + // If no circ info, set circ to null + if (circ.var_id){ + + copy.var_circulations = [circ]; + } + + else{ + + copy.var_circulations = null; + } + + copy.circulations = function(){ + + return copy.var_circulations; + } + + // If the volume isn't there yet, make it + if (!obj.map_acn[ copy.call_number() ]){ + + volumeVars = [[]].concat(volumeVars.slice(0,9), + [null,null,null], + volumeVars.slice(9,13)); + + var newVolume = makeVolume(volumeVars); + obj.map_acn[ copy.call_number()] = newVolume; + } + + obj.map_acn[ copy.call_number()].copies().push(copy); + } + + // If we have an empty volume + else{ + + // This should always return true... + // Checks if the volume isn't there yet + if (!obj.map_acn[ volumeVars[5]]){ + + volumeVars = [[]].concat(volumeVars.slice(0,9), + [null,null,null], + volumeVars.slice(9,13)); + + var newVolume = makeVolume(volumeVars); + obj.map_acn[ newVolume.id()] = newVolume; + } + } + } + + // populate obj.hashOfVolumes + for (var v in obj.map_acn){ + + if (!obj.hashOfVolumes[ obj.map_acn[v].owning_lib() ]){ + + obj.hashOfVolumes[ obj.map_acn[v].owning_lib() ] = []; + + // And populate obj.org_ids while we're at it + obj.org_ids.push( obj.map_acn[v].owning_lib() ); + } + + // add the volume to the end of the list + obj.hashOfVolumes[ obj.map_acn[v].owning_lib() ].push(obj.map_acn[v].id()); + } + } + + catch(E) { + + this.error.standard_unexpected_error_alert('cat.copy_browser.init: ',E); + } + }, + + 'controller_init' : function(params) { + var obj = this; + try { + obj.controller = new util.controller(); + obj.controller.init( + { + control_map : { + 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ], + 'sel_clip' : [ + ['command'], + function() { obj.list.clipboard(); } + ], + 'cmd_broken' : [ + ['command'], + function() { + alert(document.getElementById('commonStrings').getString('common.unimplemented')); + } + ], + 'cmd_show_my_libs' : [ + ['command'], + function() { + obj.show_my_libs(); + } + ], + 'cmd_show_all_libs' : [ + ['command'], + function() { + obj.show_all_libs(); + } + ], + 'cmd_show_libs_with_copies' : [ + ['command'], + function() { + obj.show_libs_with_copies(); + } + ], + 'cmd_clear' : [ + ['command'], + function() { + obj.map_tree = {}; + obj.list.clear(); + } + ], + 'cmd_request_items' : [ + ['command'], + function() { + + var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); + + list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); + + cat.util.request_items( list ); + } + ], + 'sel_mark_items_damaged' : [ + ['command'], + function() { + + var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); + + list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); + + var copies = cat.util.mark_item_damaged( list ); + var changed_copies = []; + var lib_to_update = {}; + + for (var c in copies){ + + if (copies[c].status() == DAMAGED){ + + changed_copies.push(copies[c]); + lib_to_update[ obj.map_acn[ copies[c].call_number() ].owning_lib() ] = true; + } + } + + obj.refresh_list(changed_copies, undefined, lib_to_update); + obj.redraw_orgs(lib_to_update); + } + ], + 'sel_mark_items_missing' : [ + ['command'], + function() { + + var list = util.functional.filter_list( obj.sel_list, function (o) { return o.split(/_/)[0] == 'acp'; }); + + list = util.functional.map_list( list, function (o) { return o.split(/_/)[1]; }); + + var copies = cat.util.mark_item_missing( list ); + var changed_copies = []; + var lib_to_update = {}; + + for (var c in copies){ + + if (copies[c].status() == MISSING){ + + changed_copies.push(copies[c]); + lib_to_update[ obj.map_acn[ copies[c].call_number() ].owning_lib() ] = true; + } + } + + obj.refresh_list(changed_copies); + obj.redraw_orgs(lib_to_update); + } + ], + 'sel_patron' : [ + ['command'], + function() { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + return { 'copy_id' : o.split(/_/)[1] }; + } + ); + + circ.util.show_last_few_circs(list); + } + ], + 'sel_copy_details' : [ + ['command'], + function() { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); - list = util.functional.map_list( + circ.util.item_details_new( + util.functional.map_list( + list, function (o) { + return obj.map_acp[o.split(/_/)[1]].barcode(); + } + ) + ); + } + ], + 'cmd_create_brt' : [ + ['command'], + function() { + + /* Filter selected rows that aren"t copies. */ + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == "acp"; + } + ); + var results = cat.util.make_bookable( + util.functional.map_list( + list, function (o) { + return obj.map_acp[o.split(/_/)[1]].id(); + } + ) + ); + if (results && results["brsrc"]) { + cat.util.edit_new_brsrc(results["brsrc"]); + } + } + ], + 'cmd_book_item_now' : [ + ['command'], + function() { + + /* Filter selected rows that aren"t copies. */ + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == "acp"; + } + ); + var results = cat.util.make_bookable( + util.functional.map_list( + list, function (o) { + return obj.map_acp[o.split(/_/)[1]].id(); + } + ) + ); + if (results) { + cat.util.edit_new_bresv(results); + } + } + ], + 'cmd_add_items' : [ + ['command'], + function() { + try { + + var list = util.functional.map_list( + util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acn'; + } + ), + function (o) { + return o.split(/_/)[1]; + } + ); + if (list.length == 0) return; + + var copy_shortcut = {}; + + list = util.functional.map_list( + list, + function (o) { + var call_number = obj.map_acn[ o ]; + var ou_id = call_number.owning_lib(); + var volume_id = o; + var label = call_number.label(); + var acnc_id = typeof call_number.label_class() == 'object' + ? call_number.label_class().id() + : call_number.label_class(); + var acnp_id = typeof call_number.prefix() == 'object' + ? call_number.prefix().id() + : call_number.prefix(); + var acns_id = typeof call_number.suffix() == 'object' + ? call_number.suffix().id() + : call_number.suffix(); + if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {}; + var callnumber_composite_key = acnc_id + ':' + acnp_id + ':' + label + ':' + acns_id; + copy_shortcut[ou_id][ callnumber_composite_key ] = volume_id; + vol_id = volume_id; + + return ou_id; + } + ); + /* quick fix */ /* what was this fixing? */ + list = []; for (var i in copy_shortcut) { list.push( i ); } + + var edit = 0; + try { + edit = obj.network.request( + api.PERM_MULTI_ORG_CHECK.app, + api.PERM_MULTI_ORG_CHECK.method, + [ + ses(), + obj.data.list.au[0].id(), list, - function (o) { - return { 'copy_id' : o.split(/_/)[1] }; - } - ); - - JSAN.use('circ.util'); - circ.util.show_last_few_circs(list); - } - ], - 'sel_copy_details' : [ - ['command'], - function() { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - JSAN.use('circ.util'); - circ.util.item_details_new( - util.functional.map_list( - list, function (o) { - return obj.map_acp[o].barcode(); - } - ) - ); - } - ], - 'cmd_create_brt' : [ - ['command'], - function() { - JSAN.use("cat.util"); - JSAN.use("util.functional"); - - /* Filter selected rows that aren"t copies. */ - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == "acp"; - } - ); - var results = cat.util.make_bookable( - util.functional.map_list( - list, function (o) { - return obj.map_acp[o].id(); - } - ) - ); - if (results && results["brsrc"]) { - cat.util.edit_new_brsrc(results["brsrc"]); - } - } - ], - 'cmd_book_item_now' : [ - ['command'], - function() { - JSAN.use("cat.util"); - JSAN.use("util.functional"); - - /* Filter selected rows that aren"t copies. */ - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == "acp"; - } - ); - var results = cat.util.make_bookable( - util.functional.map_list( - list, function (o) { - return obj.map_acp[o].id(); - } - ) - ); - if (results) { - cat.util.edit_new_bresv(results); - } - } - ], - 'cmd_add_items' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - var list = util.functional.map_list( - util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acn'; - } - ), - function (o) { - return o.split(/_/)[1]; - } - ); - if (list.length == 0) return; - - var copy_shortcut = {}; - list = util.functional.map_list( - list, - function (o) { - var call_number = obj.map_acn['acn_'+o]; - var ou_id = call_number.owning_lib(); - var volume_id = o; - var label = call_number.label(); - var acnc_id = typeof call_number.label_class() == 'object' - ? call_number.label_class().id() - : call_number.label_class(); - var acnp_id = typeof call_number.prefix() == 'object' - ? call_number.prefix().id() - : call_number.prefix(); - var acns_id = typeof call_number.suffix() == 'object' - ? call_number.suffix().id() - : call_number.suffix(); - if (!copy_shortcut[ou_id]) copy_shortcut[ou_id] = {}; - var callnumber_composite_key = acnc_id + ':' + acnp_id + ':' + label + ':' + acns_id; - copy_shortcut[ou_id][ callnumber_composite_key ] = volume_id; - - return ou_id; - } - ); - /* quick fix */ /* what was this fixing? */ - list = []; for (var i in copy_shortcut) { list.push( i ); } - - var edit = 0; - try { - edit = obj.network.request( - api.PERM_MULTI_ORG_CHECK.app, - api.PERM_MULTI_ORG_CHECK.method, - [ - ses(), - obj.data.list.au[0].id(), - list, - [ 'CREATE_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); + [ 'CREATE_COPY' ] + ] + ).length == 0 ? 1 : 0; + } catch(E) { + obj.error.sdump('D_ERROR','batch permission check: ' + E); + } + + if (edit==0) return; // no read-only view for this interface + + if (!obj.can_have_copies) { + alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source)); + return; + } + + var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.title'); + + var url; + var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; + if (unified_interface) { + var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true'; + url = xulG.url_prefix( horizontal_interface ? 'XUL_VOLUME_COPY_CREATOR_HORIZONTAL' : 'XUL_VOLUME_COPY_CREATOR' ); + } else { + url = xulG.url_prefix('XUL_VOLUME_COPY_CREATOR_ORIGINAL'); + } + + var w = xulG.new_tab( + url, + { 'tab_name' : title }, + { + 'doc_id' : obj.docid, + 'ou_ids' : list, + 'copy_shortcut' : copy_shortcut, + 'onrefresh' : function() { + obj.refresh_list(obj.get_new_copies(copy_shortcut)); + } + } + ); + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.error'),E); + } + } + ], + 'cmd_add_items_to_buckets' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + return o.split(/_/)[1]; + } + ); + + + cat.util.add_copies_to_bucket( list ); + + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_items_bucket.error'),E); + } + } + ], + 'cmd_replace_barcode' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o.split(/_/)[1] ] ) ); + cloned_copy_obj.call_number( obj.map_acn[ cloned_copy_obj.call_number() ] ); + return cloned_copy_obj; + } + ); + + xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { + + var copies = cat.util.update_copies_by_id( list ); + + var volume_id_set = {}; + var volumes = []; + var libs_to_update = {}; + + for (var c in copies){ + + // If we haven't yet handled this copy's volume + if (!(copies[c].call_number() in volume_id_set)){ + + var copy = obj.map_acp[copies[c].id()]; + copy.barcode( copies[c].barcode() ); + copy.call_number( copies[c].call_number() ); + + volume_id_set[copy.call_number()] = true; + var volume = obj.network.simple_request('FM_ACN_RETRIEVE.authoritative',[ copy.call_number() ]); + libs_to_update[volume.owning_lib()] = true; + + // first, remove the copy from it's old location + var done = false; + + // And then remove the old copy from it's old location + var volume_ids = obj.hashOfVolumes[ volume.owning_lib() ]; + + for (var v in volume_ids){ + + var old_volume = obj.map_acn[ volume_ids[v] ]; + + for (var o in old_volume.copies()){ + + if (old_volume.copies()[o].id() == copy.id()){ + + libs_to_update[old_volume.owning_lib()] = true; + old_volume.copies().splice(o,1); + delete obj.map_tree[ 'acp_' + copy.id() ]; + obj.map_acn[old_volume.id()] = old_volume; + obj.map_acp[copy.id()] = copy; + done = true; + break; + } + } + + if (done){ + + break; + } } - if (edit==0) return; // no read-only view for this interface + // If we don't have this volume, add it + if (!(volume.id() in obj.map_acn)){ - if (!obj.can_have_copies) { - alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source)); - return; + volume = obj.add_copy_to_volume_in_js(volume, copy); + volumes.push(volume); } - var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.title'); + // Otherwise, transfer the copies + else{ - var url; - var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; - if (unified_interface) { - var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true'; - url = xulG.url_prefix( horizontal_interface ? 'XUL_VOLUME_COPY_CREATOR_HORIZONTAL' : 'XUL_VOLUME_COPY_CREATOR' ); - } else { - url = xulG.url_prefix('XUL_VOLUME_COPY_CREATOR_ORIGINAL'); + volume = obj.map_acn[volume.id()]; + volume = obj.add_copy_to_volume_in_js(volume, copy); + obj.map_acn[volume.id()] = volume; } + } + } - var w = xulG.new_tab( - url, - { 'tab_name' : title }, - { - 'doc_id' : obj.docid, - 'ou_ids' : list, - 'copy_shortcut' : copy_shortcut, - 'onrefresh' : function() { obj.refresh_list(); } - } - ); - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_item.error'),E); - } - } - ], - 'cmd_add_items_to_buckets' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - - JSAN.use('cat.util'); - cat.util.add_copies_to_bucket( list ); - - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_items_bucket.error'),E); - } - } - ], - 'cmd_edit_items' : [ - ['command'], - function() { - try { - var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; - if (!unified_interface) { - obj.controller.control_map['old_cmd_edit_items'][1](); - return; - } + // If volumes need to be added, add them + if (volumes.length > 0){ - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) ); - cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] ); - return cloned_copy_obj; - } - ); - - if (list.length > 0) { - xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } ); - } + obj.add_new_volumes_to_js(volumes); + } - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); - obj.refresh_list(); - } - } - ], - 'cmd_replace_barcode' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o ] ) ); - cloned_copy_obj.call_number( obj.map_acn[ 'acn_' + cloned_copy_obj.call_number() ] ); - return cloned_copy_obj; - } - ); - - xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { obj.refresh_list(); } } ); - - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); - obj.refresh_list(); - } - } - ], - - 'old_cmd_edit_items' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - - JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); - obj.refresh_list(); - - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); - } - } - ], - 'cmd_delete_items' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return JSON2js( js2JSON( obj.map_acp[ 'acp_' + o.split(/_/)[1] ] ) ); - } - ); - - var delete_msg; - if (list.length != 1) { - delete_msg = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_items.confirm.plural', [list.length]); - } else { - delete_msg = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.confirm'); - } - var r = obj.error.yns_alert( - delete_msg, - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.title'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'), - null, - document.getElementById('commonStrings').getString('common.confirm') - ); - - if (r == 0) { - var acn_hash = {}; var acn_list = []; - for (var i = 0; i < list.length; i++) { - list[i].isdeleted('1'); - var acn_id = list[i].call_number(); - if ( ! acn_hash[ acn_id ] ) { - acn_hash[ acn_id ] = obj.map_acn[ 'acn_' + acn_id ]; - acn_hash[ acn_id ].copies( [] ); - } - var temp = acn_hash[ acn_id ].copies(); - temp.push( list[i] ); - acn_hash[ acn_id ].copies( temp ); - } - for (var i in acn_hash) acn_list.push( acn_hash[i] ); - var robj = obj.network.simple_request( - 'FM_ACN_TREE_UPDATE', - [ ses(), acn_list, true ], - null, - { - 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.override'), - 'overridable_events' : [ - 1208 /* TITLE_LAST_COPY */, - 1227 /* COPY_DELETE_WARNING */, - ] - } - ); - if (robj == null) throw(robj); - if (typeof robj.ilsevent != 'undefined') { - if ( - (robj.ilsevent != 0) - && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) - && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) - && (robj.ilsevent != 5000 /* PERM_DENIED */) - ) { - throw(robj); - } - } - obj.refresh_list(); - } + // Don't try and mess with volumes, just + // update all copies and refresh the libs + obj.refresh_list(copies, undefined, libs_to_update); + }, 'doc_id' : obj.docid } ); - - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.error'),E); - obj.refresh_list(); - } - } - ], - 'cmd_print_spine_labels' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acp'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return obj.map_acp[ o ]; - } - ); - - xulG.new_tab( - xulG.url_prefix('XUL_SPINE_LABEL'), - { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') }, - { - 'barcodes' : util.functional.map_list( list, function(o){return o.barcode();}) - } - ); - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E); - } - } - ], - 'cmd_add_volumes' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'aou'; - } - ); - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - var edit = 0; - try { - edit = obj.network.request( - api.PERM_MULTI_ORG_CHECK.app, - api.PERM_MULTI_ORG_CHECK.method, - [ - ses(), - obj.data.list.au[0].id(), - list, - [ 'CREATE_VOLUME', 'CREATE_COPY' ] - ] - ).length == 0 ? 1 : 0; - } catch(E) { - obj.error.sdump('D_ERROR','batch permission check: ' + E); - } + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); + obj.refresh_list(); + } + } + ], + 'cmd_edit_items' : [ + ['command'], + function() { + try { + var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; + if (!unified_interface) { + obj.controller.control_map['old_cmd_edit_items'][1](); + return; + } + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + var orgs = obj.update_orgs_from_copy_code_list(list); + + list = util.functional.map_list( + list, + function (o) { + var cloned_copy_obj = JSON2js( js2JSON( obj.map_acp[ o.split(/_/)[1] ] ) ); + cloned_copy_obj.call_number( obj.map_acn[ cloned_copy_obj.call_number() ] ); + return cloned_copy_obj; + } + ); + + if (list.length > 0) { + + xulG.volume_item_creator( {'existing_copies':list, 'onrefresh' : function() { + + var copies = cat.util.update_copies_by_id( list ); + + // returns the leftover copies, list, and libs_to_update + var returned = obj.weed_and_transfer_copies_in_js(copies); + obj.refresh_list(returned[0], undefined, returned[1]); + + for (var c in copies){ + + orgs[obj.map_acn[ copies[c].call_number()].owning_lib()] = true; + } + + obj.redraw_orgs(orgs); + } + } ); + } + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); + obj.refresh_list(); + } + } + ], + // Called from cmd_edit_items as a backup + 'old_cmd_edit_items' : [ + ['command'], + function() { + try { - if (edit==0) { - alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error')); - return; // no read-only view for this interface - } + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); - if (!obj.can_have_copies) { - alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source)); - return; - } + var orgs = obj.update_orgs_from_copy_code_list(list); - var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.title'); + list = util.functional.map_list( + list, + function (o) { + return o.split(/_/)[1]; + } + ); - var url; - var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; - if (unified_interface) { - var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true'; - url = xulG.url_prefix( horizontal_interface ? 'XUL_VOLUME_COPY_CREATOR_HORIZONTAL' : 'XUL_VOLUME_COPY_CREATOR' ); - } else { - url = xulG.url_prefix('XUL_VOLUME_COPY_CREATOR_ORIGINAL'); - } + + var editor_return = cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } ); - var w = xulG.new_tab( - url, - { 'tab_name' : title }, - { 'doc_id' : obj.docid, 'ou_ids' : list, 'onrefresh' : function() { obj.refresh_list(); } } - ); + if (editor_return && editor_return.length > 0){ - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.error'),E); - } - } - ], - 'cmd_edit_volumes' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - var volumes = util.functional.map_list( - util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acn'; - } - ), - function (o) { - return o.split(/_/)[1]; - } - ); - volumes = util.functional.map_list( - volumes, - function (o) { - var my_acn = obj.map_acn['acn_' + o]; - return function(r){return r;}(my_acn); - } - ); - - JSAN.use('cat.util'); - if ( cat.util.batch_edit_volumes( volumes ) ) { - obj.refresh_list(); - } + var copies = cat.util.update_copies_by_id( list ); - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_volume.exception'),E); - } - } - ], - 'cmd_delete_volumes' : [ - ['command'], - function() { - try { - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acn'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return JSON2js( js2JSON( obj.map_acn[ 'acn_' + o.split(/_/)[1] ] ) ); - } - ); - - var del_prompt; - if (list.length == 1) { - del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt'); - } else { - del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]); - } + // returns the leftover copies, list, and libs_to_update + var returned = obj.weed_and_transfer_copies_in_js(copies); + obj.refresh_list(returned[0], undefined, returned[1]); - var r = obj.error.yns_alert( - del_prompt, - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'), - null, - document.getElementById('commonStrings').getString('common.confirm') - ); - - if (r == 0) { // delete vols - for (var i = 0; i < list.length; i++) { - list[i].isdeleted('1'); - } - var params = {}; - loop: while(true) { - var robj = obj.network.simple_request( - 'FM_ACN_TREE_UPDATE', - [ ses(), list, true, params ], - null, - { - 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'), - 'overridable_events' : [ - 1208 /* TITLE_LAST_COPY */, - 1227 /* COPY_DELETE_WARNING */ - ] - } - ); - if (robj == null) throw(robj); - if (typeof robj.ilsevent != 'undefined') { - if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) { - var r2 = obj.error.yns_alert( - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.confirm'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.cancel'), - null, - document.getElementById('commonStrings').getString('common.confirm') - ); - if (r2 == 0) { // delete vols and copies - params.force_delete_copies = true; - continue loop; - } - } else { - if (typeof robj.ilsevent != 'undefined') { - if ( - (robj.ilsevent != 0) - && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) - && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) - && (robj.ilsevent != 5000 /* PERM_DENIED */) - ) { - throw(robj); - } - } - } - } - break loop; - } - obj.refresh_list(); - } - } catch(E) { - obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E); - obj.refresh_list(); - } - } - ], - 'cmd_mark_library' : [ - ['command'], - function() { - try { - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'aou'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - - if (list.length == 1) { - obj.data.marked_library = { 'lib' : list[0], 'docid' : obj.docid }; - obj.data.stash('marked_library'); - alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.alert')); - } else { - obj.error.yns_alert( - document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.prompt'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_library.title'), - document.getElementById('commonStrings').getString('common.ok'), - null, - null, - document.getElementById('commonStrings').getString('common.confirm') - ); + for (var c in copies){ + + if (typeof obj.map_acn[ copies[c].call_number()] == 'object' + && obj.map_acn[ copies[c].call_number()].owning_lib() != 'object'){ + + orgs[obj.map_acn[ copies[c].call_number()].owning_lib()] = true; + } + } + + obj.redraw_orgs(orgs); + } + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.edit_items.error'),E); + } + } + ], + 'cmd_delete_items' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + return JSON2js( js2JSON( obj.map_acp[ o.split(/_/)[1] ] ) ); + } + ); + + var delete_msg; + if (list.length != 1) { + delete_msg = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_items.confirm.plural', [list.length]); + } else { + delete_msg = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.confirm'); + } + + var r = obj.error.yns_alert( + delete_msg, + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.title'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.delete'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.cancel'), + null, + document.getElementById('commonStrings').getString('common.confirm') + ); + + if (r == 0) { + + var acn_hash = {}; var acn_list = []; + + for (var i = 0; i < list.length; i++) { + + list[i].isdeleted('1'); + var acn_id = list[i].call_number(); + + if ( ! acn_hash[ acn_id ] ) { + + // Have to clone this or it will bork the data + // and the page refresh will show an empty volume + acn_hash[ acn_id ] = cloneVolume(obj.map_acn[ acn_id ]); + acn_hash[ acn_id ].copies( [] ); + } + + var temp = acn_hash[ acn_id ].copies(); + temp.push( list[i] ); + acn_hash[ acn_id ].copies( temp ); + } + + for (var i in acn_hash) acn_list.push( acn_hash[i] ); + + var robj = obj.network.simple_request( + 'FM_ACN_TREE_UPDATE', + [ ses(), acn_list, true ], + null, + { + 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.override'), + 'overridable_events' : [ + 1208 /* TITLE_LAST_COPY */, + 1227 /* COPY_DELETE_WARNING */, + ] + } + ); + + if (robj == null) throw(robj); + if (typeof robj.ilsevent != 'undefined') { + if ( + (robj.ilsevent != 0) + && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) + && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) + && (robj.ilsevent != 5000 /* PERM_DENIED */) + ) { + throw(robj); + } + } + + if (typeof robj.ilsevent == 'undefined' || robj.ilsevent == 0){ + + var copies = cat.util.update_copies_by_id( list ); + + for (var c in copies){ + + copies[c].isdeleted(1); + } + + obj.refresh_list(copies); + } + + else{ + + obj.list.node.view.selection.clearSelection(); + } + } + + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_items.error'),E); + obj.refresh_list(list); + } + } + ], + 'cmd_print_spine_labels' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acp'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + return obj.map_acp[ o.split(/_/)[1] ]; + } + ); + + xulG.new_tab( + xulG.url_prefix('XUL_SPINE_LABEL'), + { 'tab_name' : document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.tab') }, + { + 'barcodes' : util.functional.map_list( list, function(o){return o.barcode();}) + } + ); + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.print_spine.error'),E); + } + } + ], + 'cmd_add_volumes' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'aou'; + } + ); + list = util.functional.map_list( + list, + function (o) { + return o.split(/_/)[1]; + } + ); + + var edit = 0; + try { + edit = obj.network.request( + api.PERM_MULTI_ORG_CHECK.app, + api.PERM_MULTI_ORG_CHECK.method, + [ + ses(), + obj.data.list.au[0].id(), + list, + [ 'CREATE_VOLUME', 'CREATE_COPY' ] + ] + ).length == 0 ? 1 : 0; + } catch(E) { + obj.error.sdump('D_ERROR','batch permission check: ' + E); + } + + if (edit==0) { + alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.permission_error')); + return; // no read-only view for this interface + } + + if (!obj.can_have_copies) { + alert(document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.can_have_copies.false', obj.source)); + return; + } + + var title = document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.title'); + + var url; + var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true'; + if (unified_interface) { + var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true'; + url = xulG.url_prefix( horizontal_interface ? 'XUL_VOLUME_COPY_CREATOR_HORIZONTAL' : 'XUL_VOLUME_COPY_CREATOR' ); + } else { + url = xulG.url_prefix('XUL_VOLUME_COPY_CREATOR_ORIGINAL'); + } + + // This creates a new tab in which new volumes can be created + // After created, the tab will close and the holdings maintenance + // page will refresh with the new volumes in place + // obj.get_new_volumes(list) is grabbing all volumes for docid in the list of libraries provided + var w = xulG.new_tab( + url, + { 'tab_name' : title }, + { + 'doc_id' : obj.docid, + 'ou_ids' : list, + 'onrefresh' : function() { + + obj.refresh_list(undefined, obj.get_new_volumes(list)); + } + } + ); + + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.add_volume.error'),E); + } + } + ], + 'cmd_edit_volumes' : [ + ['command'], + function() { + try { + + var volumes = util.functional.map_list( + util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acn'; + } + ), + function (o) { + return o.split(/_/)[1]; + } + ); + volumes = util.functional.map_list( + volumes, + function (o) { + var my_acn = obj.map_acn[ o ]; + return function(r){return r;}(my_acn); + } + ); + + + + var copy_lists = {}; + + for (var v in volumes){ + + copy_lists[volumes[v].id()] = volumes[v].copies(); + } + + volumes = cat.util.batch_edit_volumes( volumes ); + var libs_to_update = {}; + + for (var v in volumes){ + + if (volumes[v].id() in copy_lists){ + + // Add all the old copies to the newly edited volume + volumes[v].a[0] = copy_lists[volumes[v].id()]; + } + + libs_to_update[volumes[v].owning_lib()] = true; + } + + if ( volumes ) { + + obj.refresh_list(undefined, volumes); + obj.redraw_orgs(libs_to_update); + } + + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.edit_volume.exception'),E); + } + } + ], + 'cmd_delete_volumes' : [ + ['command'], + function() { + try { + + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'acn'; + } + ); + + list = util.functional.map_list( + list, + function (o) { + return JSON2js( js2JSON( obj.map_acn[ o.split(/_/)[1] ] ) ); + } + ); + + var del_prompt; + if (list.length == 1) { + del_prompt = document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.prompt'); + } else { + del_prompt = document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.delete_volume.prompt.plural', [list.length]); + } + + var r = obj.error.yns_alert( + del_prompt, + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.delete'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.cancel'), + null, + document.getElementById('commonStrings').getString('common.confirm') + ); + + if (r == 0) { // delete vols + for (var i = 0; i < list.length; i++) { + list[i].isdeleted('1'); + } + var params = {}; + loop: while(true) { + var robj = obj.network.simple_request( + 'FM_ACN_TREE_UPDATE', + [ ses(), list, true, params ], + null, + { + 'title' : document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.override'), + 'overridable_events' : [ + 1208 /* TITLE_LAST_COPY */, + 1227 /* COPY_DELETE_WARNING */ + ] } - } catch(E) { - obj.error.standard_unexpected_error_alert('copy browser -> mark library',E); - } - } - ], - - 'cmd_mark_volume' : [ - ['command'], - function() { - try { - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acn'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - - if (list.length == 1) { - obj.data.marked_volume = list[0]; - obj.data.stash('marked_volume'); - alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.alert')); + ); + if (robj == null) throw(robj); + if (typeof robj.ilsevent != 'undefined') { + if (robj.ilsevent == 1206 /* VOLUME_NOT_EMPTY */) { + var r2 = obj.error.yns_alert( + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.title'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.confirm'), + document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.copies_remain.cancel'), + null, + document.getElementById('commonStrings').getString('common.confirm') + ); + if (r2 == 0) { // delete vols and copies + params.force_delete_copies = true; + continue loop; + } + else { + + list = []; + break; + } } else { - obj.error.yns_alert( - document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.prompt'), - document.getElementById('catStrings').getString('staff.cat.copy_browser.mark_volume.title'), - document.getElementById('commonStrings').getString('common.ok'), - null, - null, - document.getElementById('commonStrings').getString('common.confirm') - ); + if (typeof robj.ilsevent != 'undefined') { + if ( + (robj.ilsevent != 0) + && (robj.ilsevent != 1227 /* COPY_DELETE_WARNING */) + && (robj.ilsevent != 1208 /* TITLE_LAST_COPY */) + && (robj.ilsevent != 5000 /* PERM_DENIED */) + ) { + throw(robj); + } + + // This means nothing was deleted + // So don't remove anything from the page + if (robj.ilsevent == 1227 + || robj.ilsevent == 1208 + || robj.ilsevent == 5000){ + + list = []; + break loop; + } + } } - } catch(E) { - obj.error.standard_unexpected_error_alert('copy browser -> mark volume',E); + } + break loop; + } + + // This removes all copies and volumes + for (var l in list){ + + var copies = list[l].copies(); + + // mark copies as deleted + for (var c in copies){ + + copies[c].isdeleted(true); + } + + // This updates copies javascript memory + obj.refresh_copies( copies ); + } + + if (list.length > 0){ + + // removes volumes from javascript in memory + obj.refresh_list(undefined, list); + } + } + } catch(E) { + obj.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.delete_volume.exception'),E); + + obj.refresh_list(undefined, list); + } + } + ], + 'cmd_mark_library' : [ + ['command'], + function() { + try { + var list = util.functional.filter_list( + obj.sel_list, + function (o) { + return o.split(/_/)[0] == 'aou'; } - } - ], - 'cmd_refresh_list' : [ - ['command'], - function() { - obj.refresh_list(); - } - ], - 'cmd_transfer_volume' : [ - ['command'], - function() { - try { - obj.data.stash_retrieve(); - if (!obj.data.marked_library) { - alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.transfer_volume.alert')); - return; - } - - JSAN.use('util.functional'); - - var list = util.functional.filter_list( - obj.sel_list, - function (o) { - return o.split(/_/)[0] == 'acn'; - } - ); - - list = util.functional.map_list( - list, - function (o) { - return o.split(/_/)[1]; - } - ); - - var acn_list = util.functional.map_list( - list, - function (o) { - return obj.map_acn[ 'acn_' + o ].label(); - } - ).join(document.getElementById('commonStrings').getString('common.grouping_string')); - - var xml = ''; - xml += ''; - xml += document.getElementById('catStrings').getFormattedString('staff.cat.copy_browser.transfer.prompt', [acn_list, obj.data.hash.aou[ obj.data.marked_library.lib ].shortname()]); - xml += ''; - xml += '