From 7690125655e4d9d608af20f10d28f06c062772a2 Mon Sep 17 00:00:00 2001
From: erickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Date: Fri, 5 Mar 2010 15:20:34 +0000
Subject: [PATCH] added ability to use an external function (bypassing pcrud)
 for retrieving linked data lists

git-svn-id: svn://svn.open-ils.org/ILS/trunk@15707 dcc99617-32d9-48b4-a31d-7c20da2025e4
---
 .../web/js/dojo/openils/widget/AutoFieldWidget.js  | 33 +++++++++++++++-------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
index 3e5dd90461..f5be9c4e77 100644
--- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
+++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
@@ -36,6 +36,9 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
          *      represented as field names on the remote linked object.
          *      E.g.
          *      labelFormat : [ '${0} (${1})', 'obj_field_1', 'obj_field_2' ]
+         *  dataLoader : Bypass the default PermaCrud linked data fetcher and use this function instead.
+         *      Function arguments are (link class name, search filter, callback)
+         *      The fetched objects should be passed to the callback as an array
          */
         constructor : function(args) {
             for(var k in args)
@@ -427,17 +430,27 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                 oncomplete();
 
             } else {
-                var _cb = function(r) {
-                    oncomplete(openils.Util.readResponse(r, false, true));
-                };
-                if (this.searchFilter) {
-                    new openils.PermaCrud().search(linkClass, this.searchFilter, {
-                        async : !this.forceSync, oncomplete : _cb
-                    });
+
+                if(this.dataLoader) {
+
+                    // caller provided an external function for retrieving the data
+                    this.dataLoader(linkClass, this.searchFilter, oncomplete);
+
                 } else {
-                    new openils.PermaCrud().retrieveAll(linkClass, {
-                        async : !this.forceSync, oncomplete : _cb
-                    });
+
+                    var _cb = function(r) {
+                        oncomplete(openils.Util.readResponse(r, false, true));
+                    };
+
+                    if (this.searchFilter) {
+                        new openils.PermaCrud().search(linkClass, this.searchFilter, {
+                            async : !this.forceSync, oncomplete : _cb
+                        });
+                    } else {
+                        new openils.PermaCrud().retrieveAll(linkClass, {
+                            async : !this.forceSync, oncomplete : _cb
+                        });
+                    }
                 }
             }
 
-- 
2.11.0