You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2010/09/05 10:42:04 UTC

svn commit: r992729 - /ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js

Author: jleroux
Date: Sun Sep  5 08:42:04 2010
New Revision: 992729

URL: http://svn.apache.org/viewvc?rev=992729&view=rev
Log:
Closes "Dependent dropdowns mechanism does not work anymore" (https://issues.apache.org/jira/browse/OFBIZ-3922) - OFBIZ-3922

The getDependentDropdownValues() function uses now jQuery instead of Prototype (I used jQuery.post())


Modified:
    ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js

Modified: ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js
URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js?rev=992729&r1=992728&r2=992729&view=diff
==============================================================================
--- ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js (original)
+++ ofbiz/branches/jquery/framework/images/webapp/images/getDependentDropdownValues.js Sun Sep  5 08:42:04 2010
@@ -28,59 +28,52 @@
 // selected     = optional name of a selected option
 // callback     = optional javascript function called at end
 function getDependentDropdownValues(request, paramKey, paramField, targetField, responseName, keyName, descName, selected, callback) {
-	// parameters
-	var params = new Array();
-	params[paramKey] = $F(paramField);			
-	
-    var optionList = [];
-    var requestToSend = request;
-    new Ajax.Request(requestToSend, {
-        asynchronous: false,
-        parameters: params,
-        onSuccess: function(transport) {
-            var data = transport.responseText.evalJSON(true);                     
-            list = data[responseName];
-            list.each(function(value) {
-            	if (typeof value == 'string') {            	
-	                values = value.split(': ');
-	                if (values[1].indexOf(selected) >=0) {
-	                    optionList.push("<option selected='selected' value = "+values[1]+" >"+values[0]+"</option>");
-	                } else {
-	                    optionList.push("<option value = "+values[1]+" >"+values[0]+"</option>");
-	                }
-            	} else {
-            		if (value[keyName] == selected) {
-            			optionList.push("<option selected='selected' value = " + value[keyName] +" >"+ value[descName] + "</option>");
-            		} else {
-            			optionList.push("<option value = " + value[keyName] + " >" + value[descName] + "</option>");
-            		}
-            	}
-            });
-            $(targetField).update(optionList);
-            if ((list.size() < 1) || ((list.size() == 1) && list[0].indexOf("_NA_") >=0)) {                
-                if ($(targetField).visible()) {
-                    Effect.Fade(targetField, {duration: 1.5});
+	data = [ { name: paramKey, value: jQuery('#' + paramField).val()} ];  // get requested value from parent dropdown field 
+    jQuery.post(request, data, function(result) { 
+        optionList = '';
+        list = result[responseName];
+        // Create and show dependent select options
+        jQuery.each(list, function (key, value) {
+            if (typeof value == 'string') {
+                values = value.split(': ');
+                if (values[1].indexOf(selected) >=0) {
+                    optionList += "<option selected='selected' value = " + values[1] + " >" + values[0] + "</option>";
+                } else {
+                    optionList +=  "<option value = " + values[1] + " >" + values[0] + "</option>";
                 }
             } else {
-                if (!$(targetField).visible()) {
-                    Effect.Appear(targetField, {duration: 0.0});
+                if (value[keyName] == selected) {
+                    optionList += "<option selected='selected' value = " + value[keyName] + " >" + value[descName] + "</option>";
+                } else {
+                    optionList += "<option value = " + value[keyName] + " >" + value[descName] + "</option>";
                 }
             }
-            if (callback != null)
-            	eval(callback);
+        });
+        target = '#' + targetField;
+        jQuery(target).html(optionList);
+        // Hide/show the dependent dropdown
+        if ((list.size() < 1) || ((list.size() == 1) && list[0].indexOf("_NA_") >=0)) {                
+            if (jQuery(target).is(':visible')) {
+                jQuery(target).fadeOut();
+            }
+        } else {
+            if (!jQuery(target).is(':visible')) {
+                jQuery(target).fadeIn();
+            }
         }
-    });
+        if (callback != null) eval(callback);
+    }, 'json');
 }
-
+  
 // calls any service already mounted as an event
 function getServiceResult(request, params) {
-	var data;
-	new Ajax.Request(request, {
+    var data;
+    new Ajax.Request(request, {
         asynchronous: false,
         parameters: params,
         onSuccess: function(transport) {
-			data = transport.responseText.evalJSON(true);  			
-		}
-	});
-	return data;
-}
+            data = transport.responseText.evalJSON(true);           
+        }
+    });
+    return data;
+}
\ No newline at end of file