From 4a1a9c8d91dc82196146de99a9e532ac5e58988c Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Thu, 10 Mar 2011 05:07:28 -0500 Subject: [PATCH] fleshing prefix/suffix/class for call numbers, for Item Status and Holdings Maintenance. some list infrastructure for sharing/caching data between cell rendering functions --- .../perlmods/lib/OpenILS/Application/AppUtils.pm | 23 +++++- .../src/perlmods/lib/OpenILS/Application/Cat.pm | 11 ++- .../src/perlmods/lib/OpenILS/Application/Circ.pm | 2 +- .../lib/OpenILS/Application/Search/Biblio.pm | 15 ++++ .../staff_client/chrome/content/main/constants.js | 4 +- .../xul/staff_client/chrome/content/util/list.js | 19 +++-- .../xul/staff_client/server/cat/copy_browser.js | 3 + Open-ILS/xul/staff_client/server/circ/util.js | 87 +++++++++++++++++++--- .../server/locale/en-US/circ.properties | 3 + Open-ILS/xul/staff_client/server/patron/util.js | 3 +- 10 files changed, 143 insertions(+), 27 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index ec5c56fd93..8b297015bd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -713,7 +713,7 @@ sub fetch_copy_location_by_name { } sub fetch_callnumber { - my( $self, $id ) = @_; + my( $self, $id, $flesh ) = @_; my $evt = undef; my $e = OpenILS::Event->new( 'ASSET_CALL_NUMBER_NOT_FOUND', id => $id ); @@ -726,6 +726,27 @@ sub fetch_callnumber { 'open-ils.cstore.direct.asset.call_number.retrieve', $id ); $evt = $e unless $cn; + if ($flesh && $cn) { + $cn->prefix( + $self->simplereq( + 'open-ils.cstore', + 'open-ils.cstore.direct.asset.call_number_prefix.retrieve', $cn->prefix + ) + ); + $cn->suffix( + $self->simplereq( + 'open-ils.cstore', + 'open-ils.cstore.direct.asset.call_number_suffix.retrieve', $cn->suffix + ) + ); + $cn->label_class( + $self->simplereq( + 'open-ils.cstore', + 'open-ils.cstore.direct.asset.call_number_class.retrieve', $cn->label_class + ) + ); + } + return ( $cn, $evt ); } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm index 7cd1b5ec6b..c5e5b83324 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Cat.pm @@ -660,9 +660,14 @@ sub _build_volume_list { $search_hash->{deleted} = 'f'; my $e = new_editor(); - my $vols = $e->search_asset_call_number([$search_hash, { 'order_by' => { - 'acn' => 'oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib' - } } ] ); + my $vols = $e->search_asset_call_number([ + $search_hash, + { + flesh => 1, + flesh_fields => { acn => ['prefix','suffix','label_class'] }, + 'order_by' => { 'acn' => 'oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib' } + } + ]); my @volumes; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm index 67b2dc1a3d..7040592193 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ.pm @@ -974,7 +974,7 @@ sub copy_details { flesh => 2, flesh_fields => { acp => ['call_number'], - acn => ['record'] + acn => ['record','prefix','suffix','label_class'] } } ]) or return $e->event; 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 624321938c..f277385c2b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2227,6 +2227,21 @@ sub fetch_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", +); + +sub fetch_fleshed_cn { + my( $self, $client, $id ) = @_; + my( $cn, $evt ) = $apputils->fetch_callnumber( $id, 1 ); + return $evt if $evt; + return $cn; +} + + +__PACKAGE__->register_method( method => "fetch_copy_by_cn", api_name => 'open-ils.search.copies_by_call_number.retrieve', signature => q/ 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 c28b5f2d66..cb0235b1b6 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -81,8 +81,8 @@ var api = { 'CHECKOUT_RENEW' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.renew' }, 'CIRC_MODIFIER_LIST' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.circ_modifier.retrieve.all' }, 'CLEAR_HOLD_SHELF' : { 'app' : 'open-ils.circ', 'method' : 'open-ils.circ.hold.clear_shelf.process', 'secure' : false }, - 'FM_ACN_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.callnumber.retrieve', 'secure' : false }, - 'FM_ACN_RETRIEVE.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.callnumber.retrieve.authoritative', 'secure' : false }, + 'FM_ACN_RETRIEVE' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.callnumber.fleshed.retrieve', 'secure' : false }, + 'FM_ACN_RETRIEVE.authoritative' : { 'app' : 'open-ils.search', 'method' : 'open-ils.search.callnumber.fleshed.retrieve.authoritative', 'secure' : false }, 'FM_ACN_TREE_UPDATE' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.volume.fleshed.batch.update' }, 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.copy_tree.retrieve', 'secure' : false }, 'FM_ACN_TREE_LIST_RETRIEVE_VIA_RECORD_ID_AND_ORG_IDS.authoritative' : { 'app' : 'open-ils.cat', 'method' : 'open-ils.cat.asset.copy_tree.retrieve.authoritative', 'secure' : false }, 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 dc1570a841..fb46564b2c 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/list.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/list.js @@ -30,6 +30,7 @@ util.list.prototype = { 'init' : function (params) { var obj = this; + obj.scratch_data = {}; JSAN.use('util.widgets'); @@ -1016,11 +1017,11 @@ util.list.prototype = { if (typeof params.map_row_to_column == 'function') { - label = params.map_row_to_column(params.row,this.columns[i]); + label = params.map_row_to_column(params.row,this.columns[i],this.scratch_data); } else if (typeof this.map_row_to_column == 'function') { - label = this.map_row_to_column(params.row,this.columns[i]); + label = this.map_row_to_column(params.row,this.columns[i],this.scratch_data); } if (this.columns[i].type == 'checkbox') { treecell.setAttribute('value',label); } else { treecell.setAttribute('label',label ? label : ''); } @@ -1032,11 +1033,11 @@ util.list.prototype = { if (typeof params.map_row_to_columns == 'function') { - labels = params.map_row_to_columns(params.row,this.columns); + labels = params.map_row_to_columns(params.row,this.columns,this.scratch_data); } else if (typeof this.map_row_to_columns == 'function') { - labels = this.map_row_to_columns(params.row,this.columns); + labels = this.map_row_to_columns(params.row,this.columns,this.scratch_data); } for (var i = 0; i < labels.length; i++) { @@ -1070,13 +1071,13 @@ util.list.prototype = { var value = ''; if (typeof params.map_row_to_column == 'function') { - value = params.map_row_to_column(params.row,this.columns[i]); + value = params.map_row_to_column(params.row,this.columns[i],this.scratch_data); } else { if (typeof this.map_row_to_column == 'function') { - value = this.map_row_to_column(params.row,this.columns[i]); + value = this.map_row_to_column(params.row,this.columns[i],this.scratch_data); } } if (typeof value == 'string' || typeof value == 'number') { @@ -1817,9 +1818,11 @@ util.list.prototype = { }, // Default for the map_row_to_columns function for .init 'std_map_row_to_columns' : function(error_value) { - return function(row,cols) { + return function(row,cols,scratch) { // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } } // cols contains all of the objects listed above in columns + // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in) + if (!scratch) { scratch = {}; } var obj = {}; JSAN.use('util.error'); obj.error = new util.error(); @@ -1833,7 +1836,7 @@ util.list.prototype = { try { for (var i = 0; i < cols.length; i++) { switch (typeof cols[i].render) { - case 'function': try { values[i] = cols[i].render(my); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break; + case 'function': try { values[i] = cols[i].render(my,scratch); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break; case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break; default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; '; } 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 a66c9c49b3..dce48629f3 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -1525,7 +1525,10 @@ cat.copy_browser.prototype = { 'due_date', 'owning_lib', 'circ_lib', + 'label_class', + 'prefix', 'call_number', + 'suffix', 'copy_number', 'location', 'barcode', diff --git a/Open-ILS/xul/staff_client/server/circ/util.js b/Open-ILS/xul/staff_client/server/circ/util.js index e8a7086b5c..42ae218a34 100644 --- a/Open-ILS/xul/staff_client/server/circ/util.js +++ b/Open-ILS/xul/staff_client/server/circ/util.js @@ -571,22 +571,45 @@ circ.util.columns = function(modify,params) { 'flex' : 1, 'primary' : false, 'hidden' : true, - 'editable' : false, 'render' : function(my) { - if (my.acp && my.acp.call_number() == -1) { + 'editable' : false, 'render' : function(my,scratch_data) { + var acn_id; + if (my.acn) { + if (typeof my.acn == 'object') { + acn_id = my.acn.id(); + } else { + acn_id = my.acn; + } + } else if (my.acp) { + if (typeof my.acp.call_number() == 'object') { + acn_id = my.acp.call_number().id(); + } else { + acn_id = my.acp.call_number(); + } + } + if (!acn_id && acn_id != 0) { + return ''; + } else if (acn_id == -1) { return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged'); - } else if (my.acp && my.acp.call_number() == -2) { + } else if (acn_id == -2) { return document.getElementById('circStrings').getString('staff.circ.utils.retrieving'); } else { if (!my.acn) { - var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ my.acp.call_number() ]); - if (x.ilsevent) { - return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged'); + if (typeof scratch_data['acn_map'] == 'undefined') { + scratch_data['acn_map'] = {}; + } + if (typeof scratch_data['acn_map'][ acn_id ] == 'undefined') { + var x = network.simple_request("FM_ACN_RETRIEVE.authoritative",[ acn_id ]); + if (x.ilsevent) { + return document.getElementById('circStrings').getString('staff.circ.utils.not_cataloged'); + } else { + my.acn = x; + scratch_data['acn_map'][ acn_id ] = my.acn; + } } else { - my.acn = x; return x.label(); + my.acn = scratch_data['acn_map'][ acn_id ]; } - } else { - return my.acn.label(); } + return my.acn.label(); } }, 'persist' : 'hidden width ordinal' @@ -608,6 +631,46 @@ circ.util.columns = function(modify,params) { 'persist' : 'hidden width ordinal' }, { + 'id' : 'prefix', + 'fm_class' : 'acn', + 'label' : document.getElementById('circStrings').getString('staff.circ.utils.prefix'), + 'flex' : 1, + 'primary' : false, + 'hidden' : true, + 'editable' : false, 'render' : function(my) { + if (typeof my.acn == 'undefined') return ''; + return (typeof my.acn.prefix() == 'object') ? my.acn.prefix().label() : my.acn.prefix(); + }, + 'persist' : 'hidden width ordinal' + }, + { + 'id' : 'suffix', + 'fm_class' : 'acn', + 'label' : document.getElementById('circStrings').getString('staff.circ.utils.suffix'), + 'flex' : 1, + 'primary' : false, + 'hidden' : true, + 'editable' : false, 'render' : function(my) { + if (typeof my.acn == 'undefined') return ''; + return (typeof my.acn.suffix() == 'object') ? my.acn.suffix().label() : my.acn.suffix(); + }, + 'persist' : 'hidden width ordinal' + }, + { + 'id' : 'label_class', + 'fm_class' : 'acn', + 'label' : document.getElementById('circStrings').getString('staff.circ.utils.label_class'), + 'flex' : 1, + 'primary' : false, + 'hidden' : true, + 'editable' : false, 'render' : function(my) { + if (typeof my.acn == 'undefined') return ''; + return (typeof my.acn.label_class() == 'object') ? my.acn.label_class().name() : my.acn.label_class(); + }, + 'persist' : 'hidden width ordinal' + }, + + { 'id' : 'copy_number', 'fm_class' : 'acp', 'label' : document.getElementById('commonStrings').getString('staff.acp_label_copy_number'), @@ -2233,9 +2296,11 @@ circ.util.std_map_row_to_column = function(error_value) { }; */ circ.util.std_map_row_to_columns = function(error_value) { - return function(row,cols) { + return function(row,cols,scratch) { // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } } // cols contains all of the objects listed above in columns + // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in) + if (!scratch) { scratch = {}; } var obj = {}; JSAN.use('util.error'); obj.error = new util.error(); @@ -2249,7 +2314,7 @@ circ.util.std_map_row_to_columns = function(error_value) { try { for (var i = 0; i < cols.length; i++) { switch (typeof cols[i].render) { - case 'function': try { values[i] = cols[i].render(my); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break; + case 'function': try { values[i] = cols[i].render(my,scratch); } catch(E) { values[i] = error_value; obj.error.sdump('D_COLUMN_RENDER_ERROR',E); } break; case 'string' : cmd += 'try { ' + cols[i].render + '; values['+i+'] = v; } catch(E) { values['+i+'] = error_value; }'; break; default: cmd += 'values['+i+'] = "??? '+(typeof cols[i].render)+'"; '; } diff --git a/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties b/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties index c6f718d171..508e4041e9 100644 --- a/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties +++ b/Open-ILS/xul/staff_client/server/locale/en-US/circ.properties @@ -238,6 +238,9 @@ staff.circ.utils.offline.use_time=Use Time staff.circ.utils.not_cataloged=Not Cataloged staff.circ.utils.retrieving=Retrieving... staff.circ.utils.owning_lib=Owning Library +staff.circ.utils.prefix=Prefix +staff.circ.utils.suffix=Suffix +staff.circ.utils.label_class=Classification staff.circ.utils.loan_duration.short=Short staff.circ.utils.loan_duration.normal=Normal staff.circ.utils.loan_duration.long=Long diff --git a/Open-ILS/xul/staff_client/server/patron/util.js b/Open-ILS/xul/staff_client/server/patron/util.js index 0f235efb45..742b6b4995 100644 --- a/Open-ILS/xul/staff_client/server/patron/util.js +++ b/Open-ILS/xul/staff_client/server/patron/util.js @@ -540,9 +540,10 @@ patron.util.columns = function(modify,params) { } patron.util.std_map_row_to_columns = function(error_value) { - return function(row,cols) { + return function(row,cols,scratch) { // row contains { 'my' : { 'au' : {} } } // cols contains all of the objects listed above in columns + // scratch is a temporary space shared by all cells/rows (or just per row if not explicitly passed in) var obj = {}; obj.OpenILS = {}; JSAN.use('util.error'); obj.error = new util.error(); -- 2.11.0