added ability to use an external function (bypassing pcrud) for retrieving linked...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 5 Mar 2010 15:20:34 +0000 (15:20 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 5 Mar 2010 15:20:34 +0000 (15:20 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15707 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js

index 3e5dd90..f5be9c4 100644 (file)
@@ -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
+                        });
+                    }
                 }
             }