AutoFieldWidget linked class autoloaders, etc.
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 2 Nov 2010 03:00:57 +0000 (03:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 2 Nov 2010 03:00:57 +0000 (03:00 +0000)
* leave linked selector disabled until entries are fetched;
* added support for applying default linked class object loaders;
* added default loader for acq providers, since large sets of
providers can take an excessive amount of time w/ direct pcrud call.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@18572 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index e6ec7c9..3fff2b1 100644 (file)
@@ -413,8 +413,10 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             this.widget = new dijit.form.FilteringSelect(this.dijitArgs, this.parentNode);
             this.widget.searchAttr = this.widget.labelAttr = vfield.selector || vfield.name;
             this.widget.valueAttr = vfield.name;
+            this.widget.attr('disabled', true);
 
             var oncomplete = function(list) {
+                self.widget.attr('disabled', false);
 
                 if(self.labelFormat) 
                     self.widget.labelAttr = '_label';
@@ -477,6 +479,9 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
 
             } else {
 
+                if(!this.dataLoader && openils.widget.AutoFieldWidget.defaultLinkedDataLoader[linkClass])
+                    this.dataLoader = openils.widget.AutoFieldWidget.defaultLinkedDataLoader[linkClass];
+
                 if(this.dataLoader) {
 
                     // caller provided an external function for retrieving the data
@@ -651,5 +656,30 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
 
     openils.widget.AutoFieldWidget.localeStrings = dojo.i18n.getLocalization("openils.widget", "AutoFieldWidget");
     openils.widget.AutoFieldWidget.cache = {};
+    openils.widget.AutoFieldWidget.defaultLinkedDataLoader = {};
+
+    /* Custom provider-as-link-class fetcher.  Fitler is ignored.  
+     * All viewable providers are retrieved.
+     */
+    openils.widget.AutoFieldWidget.defaultLinkedDataLoader.acqpro = 
+            function(linkClass, fitler, oncomplete) { 
+
+        fieldmapper.standardRequest(
+            ['open-ils.acq', 'open-ils.acq.provider.org.retrieve'],
+            {
+                async : true,
+                params : [openils.User.authtoken],
+                oncomplete : function(r) {
+                    var resp;
+                    var list = [];
+                    while(resp = r.recv()) {
+                        var pro = resp.content();
+                        if(pro) list.push(pro);
+                    }
+                    oncomplete(list);
+                }
+            }
+        );
+    }
 }