Index: lams_flex/LamsFlexCommon/.flexLibProperties =================================================================== diff -u -rb59f524fb51096a8d3e8341a2dbb14b6b061bab7 -r52009d3ef4413375293c2ea6732eab7fc040db2c --- lams_flex/LamsFlexCommon/.flexLibProperties (.../.flexLibProperties) (revision b59f524fb51096a8d3e8341a2dbb14b6b061bab7) +++ lams_flex/LamsFlexCommon/.flexLibProperties (.../.flexLibProperties) (revision 52009d3ef4413375293c2ea6732eab7fc040db2c) @@ -2,26 +2,28 @@ - + - - + + - - + + + - + + @@ -35,25 +37,24 @@ - - - + + - - - - + + + + - + @@ -65,32 +66,32 @@ + - - - + - + + - - + + - - - + + + @@ -138,34 +139,34 @@ - + - - + + - + - - - + + + - + @@ -180,33 +181,33 @@ - + - - + - + + - - + + - + - + @@ -220,17 +221,17 @@ - + - + - + @@ -431,53 +432,53 @@ - + - + - + - + - + - + - - + + - - + + - + - + - - + + @@ -486,8 +487,8 @@ - + @@ -498,88 +499,88 @@ - + - - + + - + - + - + - + - - + + - - - - + + + + - - + + - - + + - - + + - - + + @@ -588,26 +589,26 @@ - - + + - - + + - + - + @@ -616,42 +617,42 @@ - + - - + + - + - + - - + + - + - + @@ -661,39 +662,39 @@ - + - + - - - + + + - + - + - - + + - + @@ -710,8 +711,8 @@ - + @@ -722,88 +723,88 @@ - + - - + + - - + + - + - + - + - + - + - + - + - - + - - + + + - - - + + + - + - + - + Index: lams_flex/LamsFlexCommon/src/org/lamsfoundation/lams/common/util/AjaxUtil.as =================================================================== diff -u --- lams_flex/LamsFlexCommon/src/org/lamsfoundation/lams/common/util/AjaxUtil.as (revision 0) +++ lams_flex/LamsFlexCommon/src/org/lamsfoundation/lams/common/util/AjaxUtil.as (revision 52009d3ef4413375293c2ea6732eab7fc040db2c) @@ -0,0 +1,96 @@ +package org.lamsfoundation.lams.common.util +{ + import flash.external.ExternalInterface; + import flash.utils.Dictionary; + + import mx.controls.Alert; + import mx.utils.StringUtil; + + /** + * A utility to perfom synchronous ajax calls + * A workaround for the flex shortcoming that only allows asynchronous calls + * + * NOTE: THIS CAN ONLY WORK ON THE SERVER, NOT FROM A STATIC FILE + * + * @author lfoxton + * + */ + public class AjaxUtil + { + public static const GET:String = "GET"; + public static const POST:String = "POST"; + + public function AjaxUtil(){} + + /** + * Makes an ajax call to the server so it can be done synchronously + * + * @param url the url to call + * @param params hashmap of the key,value pairs for the url params + * @param requestType GET or POST + * @return return object + * + */ + public static function send(url:String, params:Dictionary = null, requestType:String = GET):Object { + var ret:Object = null + if (ExternalInterface.available) { + var funcString:String = getAjaxFunction(url, params, requestType); + ret = ExternalInterface.call(funcString); + } else { + Alert.show("Browser not supported or javascript disabled"); + } + return ret; + } + + + /** + * Creates the neccesary javascript code to call the server + * with the given parmas + * @param url the url to call + * @param params hashmap of the key,value pairs for the url params + * @param requestType GET or POST + * @return return object + * + */ + private static function getAjaxFunction(url:String, params:Dictionary, requestType:String):String { + + var paramsStr:String = ""; + if (params != null) { + paramsStr += "?" + var i:int = 0; + for (var key:Object in params) { + if (i > 0) { + paramsStr += "&"; + } + paramsStr += key.toString() + "=" + params[key]; + i++; + } + } + + url += paramsStr; + + var ret:String = "function() {" + + "var xmlHttp;"+ + "try {" + + "xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');" + + "} catch(e) {" + + "try {" + + "xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');" + + "} catch(oc) {" + + "xmlHttp=null;" + + "}" + + "}" + + "if(!xmlHttp && typeof XMLHttpRequest != 'undefined') {" + + "xmlHttp=new XMLHttpRequest();" + + "} try {" + + "xmlHttp.open('"+ requestType + "','" + url + "', false);"+ + "xmlHttp.send();"+ + "return xmlHttp.responseText;" + + "}catch(x){alert(x)}"+ + "}"; + + return ret; + } + + } +} \ No newline at end of file