Created holds list interface and method to pull the list from storage
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Mar 2006 22:15:41 +0000 (22:15 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Mar 2006 22:15:41 +0000 (22:15 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@3335 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Circ/Holds.pm
Open-ILS/web/opac/common/js/sorttable.js [new file with mode: 0644]
Open-ILS/xul/staff_client/server/admin/hold_pull_list.js [new file with mode: 0644]
Open-ILS/xul/staff_client/server/admin/hold_pull_list.xml [new file with mode: 0644]

index 3f7f736..25bc1f0 100644 (file)
@@ -26,6 +26,7 @@ use OpenILS::Event;
 use OpenSRF::Utils::Logger qw(:logger);
 
 my $apputils = "OpenILS::Application::AppUtils";
+my $U = $apputils;
 
 
 
@@ -475,4 +476,30 @@ sub fetch_related_holds {
 }
 
 
+__PACKAGE__->register_method (
+       method          => "hold_pull_list",
+       api_name                => "open-ils.circ.hold_pull_list.retrieve",
+       signature       => q/
+               Returns a list of hold ID's that need to be "pulled"
+               by a given location
+       /
+);
+
+sub hold_pull_list {
+       my( $self, $conn, $authtoken, $limit, $offset ) = @_;
+       my( $reqr, $evt ) = $U->checkses($authtoken);
+       return $evt if $evt;
+
+       # the perm locaiton shouldn't really matter here since holds
+       # will exist all over and VIEW_HOLDS should be universal
+       $evt = $U->check_perms($reqr->id, $reqr->home_ou, 'VIEW_HOLD');
+       return $evt if $evt;
+
+       return $U->storagereq(
+               'open-ils.storage.direct.action.hold_request.pull_list.search.current_copy_circ_lib.atomic',
+               $reqr->home_ou, $limit, $offset ); # XXX change to workstation
+}
+
+
+
 1;
diff --git a/Open-ILS/web/opac/common/js/sorttable.js b/Open-ILS/web/opac/common/js/sorttable.js
new file mode 100644 (file)
index 0000000..ca85bd2
--- /dev/null
@@ -0,0 +1,189 @@
+/* 
+       Changed HTML entities to hex encoded entities
+       bill erickson
+       */
+
+addEvent(window, "load", sortables_init);
+
+var SORT_COLUMN_INDEX;
+
+function sortables_init() {
+    // Find all tables with class sortable and make them sortable
+    if (!document.getElementsByTagName) return;
+    tbls = document.getElementsByTagName("table");
+    for (ti=0;ti<tbls.length;ti++) {
+        thisTbl = tbls[ti];
+        if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) {
+            //initTable(thisTbl.id);
+            ts_makeSortable(thisTbl);
+        }
+    }
+}
+
+function ts_makeSortable(table) {
+    if (table.rows && table.rows.length > 0) {
+        var firstRow = table.rows[0];
+    }
+    if (!firstRow) return;
+    
+    /* We have a first row: assume it's the header, and make its contents clickable links*/
+    for (var i=0;i<firstRow.cells.length;i++) {
+        var cell = firstRow.cells[i];
+        var txt = ts_getInnerText(cell);
+        cell.innerHTML = '<a href="#" class="sortheader" onclick="ts_resortTable(this);return false;">'
+                       + txt +'<span class="sortarrow">&#160;&#160;&#160;</span></a>';
+    }
+}
+
+function ts_getInnerText(el) {
+       if (typeof el == "string") return el;
+       if (typeof el == "undefined") { return el };
+       if (el.innerText) return el.innerText;  //Not needed but it is faster
+       var str = "";
+       
+       var cs = el.childNodes;
+       var l = cs.length;
+       for (var i = 0; i < l; i++) {
+               switch (cs[i].nodeType) {
+                       case 1: //ELEMENT_NODE
+                               str += ts_getInnerText(cs[i]);
+                               break;
+                       case 3: //TEXT_NODE
+                               str += cs[i].nodeValue;
+                               break;
+               }
+       }
+       return str;
+}
+
+function ts_resortTable(lnk) {
+    // get the span
+    var span;
+    for (var ci=0;ci<lnk.childNodes.length;ci++) {
+        if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci];
+    }
+    var spantext = ts_getInnerText(span);
+    var td = lnk.parentNode;
+    var column = td.cellIndex;
+    var table = getParent(td,'TABLE');
+    
+    // Work out a type for the column
+    if (table.rows.length <= 1) return;
+    var itm = ts_getInnerText(table.rows[1].cells[column]);
+    sortfn = ts_sort_caseinsensitive;
+    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
+    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
+    if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
+    if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
+    SORT_COLUMN_INDEX = column;
+    var firstRow = new Array();
+    var newRows = new Array();
+    for (i=0;i<table.rows[0].length;i++) { firstRow[i] = table.rows[0][i]; }
+    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }
+
+    newRows.sort(sortfn);
+
+    if (span.getAttribute("sortdir") == 'down') {
+        ARROW = '&#160;&#160;&#8593;';
+        newRows.reverse();
+        span.setAttribute('sortdir','up');
+    } else {
+        ARROW = '&#160;&#160;&#8595;';
+        span.setAttribute('sortdir','down');
+    }
+    
+    /* We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
+     don't do sortbottom rows */
+    for (i=0;i<newRows.length;i++) { if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) table.tBodies[0].appendChild(newRows[i]);}
+    // do sortbottom rows only
+    for (i=0;i<newRows.length;i++) { if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) table.tBodies[0].appendChild(newRows[i]);}
+    
+    // Delete any other arrows there may be showing
+    var allspans = document.getElementsByTagName("span");
+    for (var ci=0;ci<allspans.length;ci++) {
+        if (allspans[ci].className == 'sortarrow') {
+            if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us?
+                allspans[ci].innerHTML = '&#160;&#160;&#160;';
+            }
+        }
+    }
+        
+    span.innerHTML = ARROW;
+}
+
+function getParent(el, pTagName) {
+       if (el == null) return null;
+       else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())        // Gecko bug, supposed to be uppercase
+               return el;
+       else
+               return getParent(el.parentNode, pTagName);
+}
+function ts_sort_date(a,b) {
+    // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
+    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
+    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
+    if (aa.length == 10) {
+        dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2);
+    } else {
+        yr = aa.substr(6,2);
+        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
+        dt1 = yr+aa.substr(3,2)+aa.substr(0,2);
+    }
+    if (bb.length == 10) {
+        dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2);
+    } else {
+        yr = bb.substr(6,2);
+        if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
+        dt2 = yr+bb.substr(3,2)+bb.substr(0,2);
+    }
+    if (dt1==dt2) return 0;
+    if (dt1<dt2) return -1;
+    return 1;
+}
+
+function ts_sort_currency(a,b) { 
+    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
+    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,'');
+    return parseFloat(aa) - parseFloat(bb);
+}
+
+function ts_sort_numeric(a,b) { 
+    aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX]));
+    if (isNaN(aa)) aa = 0;
+    bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); 
+    if (isNaN(bb)) bb = 0;
+    return aa-bb;
+}
+
+function ts_sort_caseinsensitive(a,b) {
+    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase();
+    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase();
+    if (aa==bb) return 0;
+    if (aa<bb) return -1;
+    return 1;
+}
+
+function ts_sort_default(a,b) {
+    aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]);
+    bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]);
+    if (aa==bb) return 0;
+    if (aa<bb) return -1;
+    return 1;
+}
+
+
+function addEvent(elm, evType, fn, useCapture)
+// addEvent and removeEvent
+// cross-browser event handling for IE5+,  NS6 and Mozilla
+// By Scott Andrew
+{
+  if (elm.addEventListener){
+    elm.addEventListener(evType, fn, useCapture);
+    return true;
+  } else if (elm.attachEvent){
+    var r = elm.attachEvent("on"+evType, fn);
+    return r;
+  } else {
+    alert("Handler could not be removed");
+  }
+} 
diff --git a/Open-ILS/xul/staff_client/server/admin/hold_pull_list.js b/Open-ILS/xul/staff_client/server/admin/hold_pull_list.js
new file mode 100644 (file)
index 0000000..99c7492
--- /dev/null
@@ -0,0 +1,122 @@
+
+var FETCH_HOLD_LIST                    = 'open-ils.circ:open-ils.circ.hold_pull_list.retrieve';
+var FETCH_COPY_LOCATIONS       = 'open-ils.search:open-ils.search.config.copy_location.retrieve.all';
+var FETCH_COPY                                 = 'open-ils.search:open-ils.search.asset.copy.retrieve';
+var FETCH_USER                                 = 'open-ils.actor:open-ils.actor.user.fleshed.retrieve';
+var FETCH_VOLUME                               = 'open-ils.search:open-ils.search.callnumber.retrieve';
+
+var myPerms                            = [ 'VIEW_HOLD' ];
+var HOLD_LIST_LIMIT    = 50;
+var numHolds                   = 0;
+
+var listOffset                 = 0;
+var copyLocations              = null;
+
+
+function pullListInit() {
+       fetchUser();
+       $('pl_user').appendChild(text(USER.usrname()));
+       $('pl_org').appendChild(text(findOrgUnit(USER.ws_ou()).name()));
+       setTimeout( function() { 
+               fetchHighestPermOrgs( SESSION, USER.id(), myPerms );
+               pullListFetchCopyLocations();
+               pullListFetchHolds();
+       }, 20 );
+}
+
+function pullListFetchCopyLocations() {
+       var req = new Request(FETCH_COPY_LOCATIONS);
+       req.send(true);
+       copyLocations = req.result();
+}
+
+function pullListFetchHolds() {
+       var req = new Request(FETCH_HOLD_LIST, SESSION, HOLD_LIST_LIMIT, listOffset );
+       req.callback(pullListDrawHolds);
+       req.send();
+}
+
+var holdRowTemplate;
+function pullListDrawHolds(r) {
+       var holds = r.getResultObject();
+
+       var tbody = $('pull_list_tbody');
+       if(!holdRowTemplate) 
+               holdRowTemplate = tbody.removeChild($('pull_list_row'));
+       numHolds = holds.length;
+
+       for( var h in holds ) {
+               var hold = holds[h];
+               var row = holdRowTemplate.cloneNode(true);
+               tbody.appendChild(row);
+               pullListDrawHold( tbody, row, hold, h );
+       }
+
+}
+
+function pullListDrawHold( tbody, row, hold, idx ) {
+
+       $n(row, 'date').appendChild(text(hold.request_time().replace(/\ .*/, "")));
+       
+       var treq = new Request( FETCH_MODS_FROM_COPY, hold.current_copy() );
+       treq.callback(
+               function(r) {
+                       pullListDrawTitle( tbody, row, hold, idx, r.getResultObject() );        });
+       treq.send();
+
+       var creq = new Request( FETCH_COPY, hold.current_copy() );
+       creq.callback(
+               function(r) {
+                       pullListDrawCopy( tbody, row, hold, idx, r.getResultObject() ); });
+       creq.send();
+
+       var ureq = new Request( FETCH_USER, SESSION, hold.usr() );
+       ureq.callback(
+               function(r) {
+                       pullListDrawUser( tbody, row, hold, idx, r.getResultObject() ); });
+       ureq.send();
+
+}
+
+
+function pullListDrawTitle( tbody, row, hold, idx, record ) {
+       $n(row, 'title').appendChild(text(record.title()));
+       $n(row, 'author').appendChild(text(record.author()));
+
+       var type = modsFormatToMARC(record.types_of_resource()[0]);
+       unHideMe($n(row, 'format_' + type));
+}
+
+
+function pullListDrawCopy( tbody, row, hold, idx, copy ) {
+       $n(row, 'barcode').appendChild(text(copy.barcode()));
+       for( var l in copyLocations ) {
+               var loc = copyLocations[l];
+               if( loc.id() == copy.location() ) {
+                       $n(row, 'copy_location').appendChild(text(loc.name()));
+                       break;
+               }
+       }
+       $n(row, 'copy_number').appendChild(text(copy.copy_number()));
+
+       var vreq = new Request(FETCH_VOLUME, copy.call_number());
+       vreq.callback(
+               function(r) { pullListDrawVolume( tbody, row, hold, idx, r.getResultObject() ); } );
+       vreq.send();
+}
+
+
+function pullListDrawUser( tbody, row, hold, idx, user ) {
+       $n(row, 'patron').appendChild(text(user.card().barcode()));
+}
+
+var callNumbers = [];
+function pullListDrawVolume( tbody, row, hold, idx, volume ) {
+       $n(row, 'call_number').appendChild(text(volume.label()));
+       callNumbers.push(volume.label());
+
+       if( (parseInt(idx) +1) == numHolds )
+               ts_resortTable($('pl_callnumber').getElementsByTagName('a')[0]);
+}
+
+
diff --git a/Open-ILS/xul/staff_client/server/admin/hold_pull_list.xml b/Open-ILS/xul/staff_client/server/admin/hold_pull_list.xml
new file mode 100644 (file)
index 0000000..007fd1c
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version='1.0'?>
+
+<!DOCTYPE html PUBLIC 
+       "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
+       <!ENTITY nbsp " "> <!-- calendar needs this entity -->
+]>
+
+
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude">
+
+       <head>
+               <title>Evergreen Holds Pull List</title>
+               <script language='javascript' src='/opac/common/js/utils.js'> </script>
+               <script language='javascript' src='/opac/common/js//config.js'> </script> 
+               <script language='javascript' src='/opac/common/js/CGI.js'> </script>
+               <script language='javascript' src='/opac/common/js/Cookie.js'> </script>
+       
+               <script language='javascript' src='/opac/common/js/slimtree.js'> </script>
+               <script language='javascript' src='/opac/common/js/JSON.js'> </script>
+               <script language='javascript' src='/opac/common/js/fmall.js'> </script>
+               <script language='javascript' src='/opac/common/js/fmgen.js'> </script>
+               <script language='javascript' src='/opac/common/js/Cookies.js'> </script>
+               <script language='javascript' src='/opac/common/js/opac_utils.js'> </script>
+               <script language='javascript' src='/opac/common/js/OrgTree.js'> </script>
+               <script language='javascript' src='/opac/common/js/org_utils.js'> </script>
+               <script language='javascript' src='/opac/common/js/init.js'> </script>
+               <script language='javascript' src='/opac/common/js/RemoteRequest.js'> </script>
+               <script language='javascript' src='/opac/common/js/sorttable.js'> </script>
+               <script language='javascript' src='adminlib.js'> </script>
+               <script language='javascript' src='hold_pull_list.js'> </script>
+               <link type='text/css' rel='stylesheet' href='admin.css'/>
+  
+               <style type='text/css'>
+                       a { color: black; text-decoration: none; }
+               </style>
+       </head>
+
+       <body onload='try{pullListInit();}catch(e){alert(js2JSON(e));}'>
+
+               <center>
+                       <h2>Evergreen Holds Pull List : <span id='pl_org'/></h2>
+
+                       <div style='position:absolute; top: 5px; right: 5px;'>
+                               <span>Welcome </span><b><span id='pl_user'/></b>
+                       </div>
+               
+                       <hr/><br/>
+
+                       <span>Note: Click on a column header to sort the column</span>
+
+                       <table witdh='85%' class='data_grid sortable' id='pl_table'>
+                               <thead>
+                                       <tr>
+                                               <td>Title</td>
+                                               <td>Author</td>
+                                               <td>Copy Location</td>
+                                               <td id='pl_callnumber'>Call Number</td>
+                                               <td>Item Bracode</td>
+                                               <td>Copy Number</td>
+                                               <td>Format</td>
+                                               <td>Patron Barcode</td>
+                                               <td>Hold Placement Date</td>
+                                       </tr>
+                               </thead>
+                               <tbody id='pull_list_tbody'>
+                                       <tr id='pull_list_row'>
+                                               <td name='title'/>
+                                               <td name='author'/>
+                                               <td name='copy_location'/>
+                                               <td name='call_number'/>
+                                               <td name='barcode'/>
+                                               <td name='copy_number'/>
+                                               <td>
+                                                       <span name='format_at'          class='hide_me'>Book</span>
+                                                       <span name='format_at-d'        class='hide_me'>Large Print Book</span>
+                                                       <span name='format_i'           class='hide_me'>Audiobook</span>
+                                                       <span name='format_g'           class='hide_me'>Video Recording</span>
+                                                       <span name='format_j'           class='hide_me'>Music</span>
+                                                       <span name='format_m'           class='hide_me'>Electronic Resource</span>
+                                               </td>
+                                               <td name='patron'/>
+                                               <td name='date'/>
+                                       </tr>
+                               </tbody>
+                       </table>
+               </center>
+       </body>
+</html>