Allow util.functional.convert_object_list_to_hash to handle more than fieldmapper...
authorJason Etheridge <jason@esilibrary.com>
Wed, 1 Jun 2011 07:16:05 +0000 (03:16 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 6 Jun 2011 16:09:28 +0000 (12:09 -0400)
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/util/functional.js

index 776a7f4..0dc9eb1 100644 (file)
@@ -89,11 +89,17 @@ util.functional.map_object_to_list = function(obj,f) {
     return new_list;
 }
 
-util.functional.convert_object_list_to_hash = function(list) {
+util.functional.convert_object_list_to_hash = function(list,key_field) {
     var my_hash = new Object();
     if (list) {
         for (var i = 0; i < list.length; i++) {
-            if (typeof list[i].id == 'function') {
+            if (key_field && typeof list[i][key_field] != 'undefined') {
+                if (typeof list[i][key_field] == 'function') {
+                    my_hash[ list[i][key_field]() ] = list[i];
+                } else {
+                    my_hash[ list[i][key_field] ] = list[i];
+                }
+            } else if (typeof list[i].id == 'function') {
                 my_hash[ list[i].id() ] = list[i];
             } else if (typeof list[i].code == 'function') {
                 my_hash[ list[i].code() ] = list[i];