Vandelay record match sets: fix bug loading some trees
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 14 Feb 2012 16:18:27 +0000 (11:18 -0500)
committerBill Erickson <berick@esilibrary.com>
Tue, 14 Feb 2012 17:39:54 +0000 (12:39 -0500)
Reported to me by Bill Erickson.  The Vandelay Record Match Sets
interface was failing to load some simple trees of match set points.

Example: http://pastesite.com/31643

The proximate symptom was this error message:

    Error: dojo.data.ItemFileReadStore: Invalid item argument.
    Source File: http://dev198.esilibrary.com/js/dojo/dojo/dojo.js
    Line: 119

but the root cause was a problem in dojoize_match_set_tree(), which
was failing to generate unique identifiers for each item in the data
store it's responsible for generating.

Since that function is only ever used to deal with trees where all the
nodes come from the database and have actual IDs, that function now uses
the database IDs as is rather than attempting to generate new ones.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>

Open-ILS/web/js/ui/default/conify/global/vandelay/match_set.js

index 87656a3..1de99e4 100644 (file)
@@ -418,20 +418,20 @@ function new_match_set_tree() {
  * ],
  *
  */
-function dojoize_match_set_tree(point, refgen) {
+function dojoize_match_set_tree(point, depth) {
     var root = false;
-    if (!refgen) {
+    if (!depth) {
         if (!point) {
             return new_match_set_tree();
         }
-        refgen = 0;
+        depth = 0;
         root = true;
     }
 
     var bathwater = point.children();
     point.children([]);
     var item = {
-        "id": (root ? "root" : refgen),
+        "id": (root ? "root" : point.id()),
         "name": render_vmsp_label(point),
         "match_point": point.clone(),
         "children": []
@@ -443,9 +443,9 @@ function dojoize_match_set_tree(point, refgen) {
     if (point.children()) {
         for (var i = 0; i < point.children().length; i++) {
             var child = point.children()[i];
-            item.children.push({"_reference": ++refgen});
+            item.children.push({"_reference": child.id()});
             results = results.concat(
-                dojoize_match_set_tree(child, refgen)
+                dojoize_match_set_tree(child, ++depth)
             );
         }
     }