for large sets of holds, usually around 10 or more, the holds display takes a little...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 19 Sep 2010 19:15:48 +0000 (19:15 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 19 Sep 2010 19:15:48 +0000 (19:15 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@17817 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js

index 6bc4c9e..4ef30e5 100644 (file)
@@ -678,12 +678,12 @@ SelfCheckManager.prototype.drawHoldsPage = function() {
                 }
 
                 fieldmapper.standardRequest( // fetch the hold objects with fleshed details
-                    ['open-ils.circ', 'open-ils.circ.hold.details.batch.retrieve.atomic'],
+                    ['open-ils.circ', 'open-ils.circ.hold.details.batch.retrieve'],
                     {   async : true,
                         params : [self.authtoken, ids],
-
-                        oncomplete : function(rr) {
-                            self.drawHolds(openils.Util.readResponse(rr));
+                        onresponse : function(rr) {
+                            progressDialog.hide();
+                            self.insertHold(openils.Util.readResponse(rr));
                         }
                     }
                 );
@@ -692,54 +692,45 @@ SelfCheckManager.prototype.drawHoldsPage = function() {
     );
 }
 
-/**
- * Fetch and add a single hold to the list of holds
- */
-SelfCheckManager.prototype.drawHolds = function(holds) {
-
-    holds = holds.sort(
-        // sort available holds to the top of the list
-        // followed by queue position order
-        function(a, b) {
-            if(a.status == 4) return -1;
-            if(a.queue_position < b.queue_position) return -1;
-            return 1;
-        }
-    );
-
-    this.holds = holds;
+SelfCheckManager.prototype.insertHold = function(data) {
+    var row = this.holdTemplate.cloneNode(true);
 
-    progressDialog.hide();
+    if(data.mvr.isbn()) {
+        this.byName(row, 'jacket').setAttribute('src', '/opac/extras/ac/jacket/small/' + data.mvr.isbn());
+    }
 
-    for(var i in holds) {
+    this.byName(row, 'title').innerHTML = data.mvr.title();
+    this.byName(row, 'author').innerHTML = data.mvr.author();
 
-        var data = holds[i];
-        var row = this.holdTemplate.cloneNode(true);
+    if(data.status == 4) {
 
-        if(data.mvr.isbn()) {
-            this.byName(row, 'jacket').setAttribute('src', '/opac/extras/ac/jacket/small/' + data.mvr.isbn());
-        }
+        // hold is ready for pickup
+        this.byName(row, 'status').innerHTML = localeStrings.HOLD_STATUS_READY;
 
-        this.byName(row, 'title').innerHTML = data.mvr.title();
-        this.byName(row, 'author').innerHTML = data.mvr.author();
+    } else {
 
-        if(data.status == 4) {
+        // hold is still pending
+        this.byName(row, 'status').innerHTML = 
+            dojo.string.substitute(
+                localeStrings.HOLD_STATUS_WAITING,
+                [data.queue_position, data.potential_copies]
+            );
+    }
 
-            // hold is ready for pickup
-            this.byName(row, 'status').innerHTML = localeStrings.HOLD_STATUS_READY;
+    // find the correct place the table to slot in the hold based on queue position
 
-        } else {
+    var position = (data.status == 4) ? 0 : data.queue_position;
+    row.setAttribute('position', position);
 
-            // hold is still pending
-            this.byName(row, 'status').innerHTML = 
-                dojo.string.substitute(
-                    localeStrings.HOLD_STATUS_WAITING,
-                    [data.queue_position, data.potential_copies]
-                );
+    for(var i = 0; i < this.holdTbody.childNodes.length; i++) {
+        var node = this.holdTbody.childNodes[i];
+        if(Number(node.getAttribute('position')) >= position) {
+            this.holdTbody.insertBefore(row, node);
+            return;
         }
-
-        this.holdTbody.appendChild(row);
     }
+
+    this.holdTbody.appendChild(row);
 }