added support for reading zip code db and alerting when alert msg is present
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Jun 2009 20:35:49 +0000 (20:35 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 4 Jun 2009 20:35:49 +0000 (20:35 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13319 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/actor/user/register.js

index a23e2b2..9435002 100644 (file)
@@ -243,10 +243,13 @@ function fleshFMRow(row, fmcls, args) {
     return widget;
 }
 
-function findWidget(wtype, fmfield) {
+function findWidget(wtype, fmfield, callback) {
     return widgetPile.filter(
         function(i){
-            return (i._wtype == wtype && i._fmfield == fmfield);
+            if(i._wtype == wtype && i._fmfield == fmfield) {
+                if(callback) return callback(i);
+                return true;
+            }
         }
     ).pop();
 }
@@ -285,6 +288,30 @@ function attachWidgetEvents(fmcls, fmfield, widget) {
                 );
         }
     }
+
+    if(fmclass = 'aua') {
+        switch(fmfield) {
+            case 'post_code':
+                dojo.connect(widget.widget, 'onChange',
+                    function(e) { 
+                        fieldmapper.standardRequest(
+                            ['open-ils.search', 'open-ils.search.zip'],
+                            {   async: true,
+                                params: [e],
+                                oncomplete : function(r) {
+                                    var res = openils.Util.readResponse(r);
+                                    var callback = function(w) { return w._addr == widget._addr; };
+                                    if(res.city) findWidget('aua', 'city', callback).widget.attr('value', res.city);
+                                    if(res.state) findWidget('aua', 'state', callback).widget.attr('value', res.state);
+                                    if(res.county) findWidget('aua', 'county', callback).widget.attr('value', res.county);
+                                    if(res.alert) alert(res.alert);
+                                }
+                            }
+                        );
+                    }
+                );
+        }
+    }
 }
 
 function getByName(node, name) {