Gracefully handle reporter class with no labels
authorBill Erickson <berick@esilibrary.com>
Tue, 4 Sep 2012 18:43:27 +0000 (14:43 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 4 Sep 2012 18:55:07 +0000 (14:55 -0400)
LP 1045964 -- unable to clone report template

The template interface was failing while rendering the reporter sources
drop-down when a reporter source (IDL class) had no label.  This adds a
sanity check around that.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/web/reports/xul/source-setup.js

index 245657b..d3b919c 100644 (file)
@@ -25,13 +25,21 @@ function sortNames (a,b) {
 }
 
 function sortLabels (a,b) {
-       var aname =  a.getAttributeNS(rptNS, 'label').toLowerCase();
-       if (!aname) aname = a.getAttribute('name');
-       if (!aname) aname = a.getAttribute('id');
+       var aname =  a.getAttributeNS(rptNS, 'label');
 
-       var bname =  b.getAttributeNS(rptNS, 'label').toLowerCase();
-       if (!bname) bname = b.getAttribute('name');
-       if (!bname) bname = b.getAttribute('id');
+       if (aname) {
+               aname = aname.toLowerCase();
+       } else {
+               aname = a.getAttribute('name') || a.getAttribute('id');
+       }
+
+       var bname =  b.getAttributeNS(rptNS, 'label');
+
+       if (bname) {
+               bname = bname.toLowerCase();
+       } else {
+               bname = b.getAttribute('name') || b.getAttribute('id');
+       }
 
        return aname < bname ? -1 : 1;
 }