From 7ca134b6d0859271f0b3bef5efbe78cd57e2a975 Mon Sep 17 00:00:00 2001 From: Jeff Godin Date: Mon, 16 Apr 2012 10:01:31 -0400 Subject: [PATCH] Summarize copy availability in search results Summary of available copies in search results. Next, need to display call numbers. Signed-off-by: Jeff Godin --- .../opac/skin/tadlv3/xml/result/result_table.xml | 130 +++++++++++++++------ 1 file changed, 93 insertions(+), 37 deletions(-) diff --git a/Open-ILS/web/opac/skin/tadlv3/xml/result/result_table.xml b/Open-ILS/web/opac/skin/tadlv3/xml/result/result_table.xml index a1e05e9841..c5ff85bbfc 100644 --- a/Open-ILS/web/opac/skin/tadlv3/xml/result/result_table.xml +++ b/Open-ILS/web/opac/skin/tadlv3/xml/result/result_table.xml @@ -144,11 +144,14 @@ var item_cnt = 0; var max_items = 4; + var copySummaryObj = new Object(); + var count_copies_unavail = 0; + var count_copies_avail = 0; dojo.query('volume', item).forEach(function(vol) { - if (item_cnt >= max_items) { - return output.innerHTML; - } + //if (item_cnt >= max_items) { + // return output.innerHTML; + //} if (vol.getAttribute('deleted') == 't') { return; } @@ -171,9 +174,12 @@ } }); dojo.query('copy', vol).forEach(function (cp) { - if (item_cnt >= max_items) { - return; - } + var cp_status; + var cp_location; + var cp_circ_lib; + //if (item_cnt >= max_items) { + // return; + //} if (cp.getAttribute('deleted') == 't') { return; } @@ -185,6 +191,7 @@ var visible_status; dojo.query('status', cp).forEach(function (status) { visible_status = status.getAttribute('opac_visible'); + cp_status = status; }); if (visible_status == 'f') { return; @@ -192,53 +199,102 @@ /* Ensure the circulation library is visible */ var lib_vis; - dojo.query('circlib', cp).forEach(function (status) { - lib_vis = status.getAttribute('opac_visible'); + dojo.query('circ_lib', cp).forEach(function (circ_lib) { + lib_vis = circ_lib.getAttribute('opac_visible'); + cp_circ_lib = circ_lib; }); if (lib_vis != 't') { return; } - var cp_entry = dojo.create('div'); var loc_visible; - var vol_appended = false; dojo.query('location', cp).forEach(function (location) { loc_visible = location.getAttribute('opac_visible'); - if (loc_visible == 't') { - if (!vol_appended) { - var cn = dojo.create('span', { style: "font-weight: bold;" }, cp_entry); - var cn_txt = dojo.doc.createTextNode(vol.getAttribute('label')); - cn.appendChild(cn_txt); - vol_appended = true; - } - var loc = dojo.create('span', { "style": "font-weight: bold;"}, cp_entry); - var loc_txt = dojo.doc.createTextNode(' - ' + BT.textContent(location)); - loc.appendChild(loc_txt); - } + cp_location = location; }); if (loc_visible != 't') { return; } - dojo.query('circ_lib', cp).forEach(function (circ_lib) { - var cp_lib = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry, "first"); - var cp_lib_txt = dojo.doc.createTextNode(circ_lib.getAttribute('name') + ' - '); - cp_lib.appendChild(cp_lib_txt); - }); - dojo.query('status', cp).forEach(function (status) { - var cp_status = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry); - var cp_status_txt = dojo.doc.createTextNode(' (' + BT.textContent(status) + ')'); - cp_status.appendChild(cp_status_txt); - }); + // at this point we have vol, cp_circ_lib, cp_location, cp_status + var status_id = cp_status.getAttribute('ident'); + if (!(status_id in {0:1, 7:1, 109:1})) { + count_copies_unavail++; + return; + } else { + count_copies_avail++; + } + var cp_circ_lib_txt = cp_circ_lib.getAttribute('name'); + var cp_location_txt = BT.textContent(cp_location); + // copySummaryObj[cp_circ_lib_txt][cp_location_txt]['count'] + // copySummaryObj[cp_circ_lib_txt][cp_location_txt]['labels'] + // copySummaryObj[cp_circ_lib_txt][cp_location_txt]['reshelving_count'] + var libkey = cp_circ_lib_txt; + var lockey = cp_location_txt; + if (!copySummaryObj[libkey]) { + copySummaryObj[libkey] = new Object(); + copySummaryObj[libkey][lockey] = new Object(); + copySummaryObj[libkey][lockey]['labels'] = new Object(); + copySummaryObj[libkey][lockey]['count'] = 0; + copySummaryObj[libkey][lockey]['reshelving_count'] = 0; + } + copySummaryObj[libkey][lockey]['count']++; + copySummaryObj[libkey][lockey]['labels'][vol.getAttribute('label')] = 1; item_cnt++; - if (item_cnt >= max_items) { - dojo.create('br', null, cp_entry); - cp_entry.appendChild(dojo.doc.createTextNode(opac_strings.MORE_COPIES_FULL_RECORD)); - } - output.appendChild(cp_entry); + //if (item_cnt >= max_items) { + // dojo.create('br', null, cp_entry); + // cp_entry.appendChild(dojo.doc.createTextNode(opac_strings.MORE_COPIES_FULL_RECORD)); + //} + //output.appendChild(cp_entry); }); }); - + var numLibs = 0; + for (var lib in copySummaryObj) { + numLibs++; + } + if (numLibs == 0) { return; } + if (numLibs == 1) { + var sumdiv = dojo.create('div', { "style": "font-weight: bold;" }); + // output the grouped-by-location summary + for (var sumlib in copySummaryObj) { + //output the "at lib" + var atlib = dojo.create('div', null, sumdiv); + atlib.appendChild(dojo.doc.createTextNode('At ' + sumlib)); + for (var sumloc in copySummaryObj[sumlib]) { + // available copies in each location + var sumcount = copySummaryObj[sumlib][sumloc]['count']; + var sumreshelving = copySummaryObj[sumlib][sumloc]['reshelving_count']; + var summary_line = sumcount + ' available in ' + sumloc; + var locdiv = dojo.create('div', null, sumdiv); + locdiv.appendChild(dojo.doc.createTextNode(summary_line)); + } + } + output.appendChild(sumdiv); + } else { + // output the grouped-by-library summary + for (var libname in copySummaryObj) { + var copycount = 0; + for (var loc in copySummaryObj[libname]) { + copycount = copycount + copySummaryObj[libname][loc]['count']; + } + } + var libdiv = dojo.create('div'); + var libcontent = dojo.create('span', { "style": "font-weight: bold;" }); + var libtext = dojo.doc.createTextNode(copycount + ' available at ' + libname); + libcontent.appendChild(libtext); + libdiv.appendChild(libcontent); + output.appendChild(libdiv); + } + // display the count of unavailable items, if any + if (count_copies_unavail > 0) { + other_or_null = (count_copies_avail > 0) ? 'other ' : ' '; + item_or_items = (count_copies_unavail > 1) ? 'items' : 'item'; + output.appendChild( + dojo.doc.createTextNode( + count_copies_unavail + " " + other_or_null + item_or_items + " not currently available" + ) + ); + } return output.innerHTML; ]]> -- 2.11.0