Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ajax work

  • Loading branch information...
commit 4fc75fff86ac166966c28b9fb66e529d3837a464 1 parent ac9669d
@spockz authored
View
48 uhc-jscript/src/Language/UHC/JScript/JQuery/Ajax.hs
@@ -1,4 +1,4 @@
-module Language.UHC.JScript.JQuery.Ajax (AjaxOptions(..), JSAjaxOptions(..), ajax, toJSOptions) where
+module Language.UHC.JScript.JQuery.Ajax (AjaxOptions(..), JSAjaxOptions(..), AjaxCallback, ajaxBackend, ajax, toJSOptions) where
import Language.UHC.JScript.ECMA.String
import Language.UHC.JScript.Types
@@ -7,48 +7,52 @@ import Language.UHC.JScript.Primitives
import Data.List
+type AjaxCallback a = JSFunPtr (JSPtr a -> IO())
data AjaxOptions a = AjaxOptions {
ao_url :: String,
ao_requestType :: String,
ao_contentType :: String,
- ao_dataType :: String,
- ao_success :: JSFunPtr (JSPtr a -> IO()),
- ao_failure :: JSFunPtr (JSPtr a -> IO())
+ ao_dataType :: String
}
data JSAjaxOptions a = JSAjaxOptions {
- jsao_url :: JSString,
- jsao_requestType :: JSString,
- jsao_contentType :: JSString,
- jsao_dataType :: JSString,
- jsao_success :: JSFunPtr (JSPtr a -> IO()),
- jsao_failure :: JSFunPtr (JSPtr a -> IO())
+ url :: JSString,
+ requestType :: JSString,
+ contentType :: JSString,
+ dataType :: JSString
}
instance Show (AjaxOptions a) where
show jsopt= "AjaxOptions: " ++ intercalate " " [show $ ao_url jsopt]
instance Show (JSAjaxOptions a) where
- show jsopt = "JSAjaxOptions: " ++ intercalate " " [show $ jsao_url jsopt]
+ show jsopt = "JSAjaxOptions: " ++ intercalate " " [show $ url jsopt]
toJSOptions :: AjaxOptions a -> JSAjaxOptions a
toJSOptions options = let url' = toJS (ao_url options)
requestType' = toJS (ao_requestType options)
contentType' = toJS (ao_contentType options)
dataType' = toJS (ao_dataType options)
- in JSAjaxOptions { jsao_url = url'
- , jsao_requestType = requestType'
- , jsao_contentType = contentType'
- , jsao_dataType = dataType'
- , jsao_success = ao_success options
- , jsao_failure = ao_failure options}
-
-
-ajax :: AjaxOptions a -> IO ()
-ajax options = do o <- mkObj (toJSOptions options)
- _ajax o
+ in JSAjaxOptions { url = url'
+ , requestType = requestType'
+ , contentType = contentType'
+ , dataType = dataType'
+ }
+
+
+ajaxBackend :: (JSPtr a -> IO ()) -> AjaxOptions a -> AjaxCallback a -> AjaxCallback a -> IO ()
+ajaxBackend cont options onSuccess onFailure =
+ do let jsOptions = toJSOptions options
+ o <- mkObj jsOptions
+ _ <- setAttr "type" (requestType jsOptions) o
+ _ <- setAttr "success" onSuccess o
+ _ <- setAttr "error" onFailure o
+ _ajax o
+
+ajax :: AjaxOptions a -> AjaxCallback a -> AjaxCallback a -> IO ()
+ajax = ajaxBackend _ajax
View
30 uhc-jscript/src/Language/UHC/JScript/JQuery/AjaxQueue.hs
@@ -8,19 +8,23 @@ import Language.UHC.JScript.JQuery.Ajax
import Language.UHC.JScript.Assorted (alert, _alert)
-ajaxQ :: String -> AjaxOptions a -> IO ()
-ajaxQ queuename options = do alert (show $ options)
- alert (ao_url options)
- _alert (toJS $ ao_url options)
- _alert $ toJS (ao_requestType options)
- _alert $ toJS (ao_contentType options)
- _alert $ toJS (ao_dataType options)
- -- let foo = toJSOptions options
- -- _alert $ jsao_url foo
- -- alert (show $ toJSOptions options)
- o <- mkObj (toJSOptions options)
- return ()
- -- _ajaxQ (toJS queuename) o
+ajaxQ :: String -> AjaxOptions a -> AjaxCallback a -> AjaxCallback a -> IO ()
+ajaxQ queuename options onSuccess onFailure =
+ do alert (show $ options)
+ -- alert (ao_url options)
+ -- _alert (toJS $ ao_url options)
+ -- _alert $ toJS (ao_requestType options)
+ -- _alert $ toJS (ao_contentType options)
+ -- _alert $ toJS (ao_dataType options)
+ -- -- let foo = toJSOptions options
+ -- -- _alert $ jsao_url foo
+ -- -- alert (show $ toJSOptions options)
+ let jsOptions = toJSOptions options
+ o <- mkObj jsOptions
+ setAttr "type" (requestType jsOptions) o
+ _ <- setAttr "success" onSuccess o
+ _ <- setAttr "error" onFailure o
+ _ajaxQ (toJS queuename) o
foreign import jscript "$.ajaxq(%*)"
_ajaxQ :: JSString -> JSPtr a -> IO ()
Please sign in to comment.
Something went wrong with that request. Please try again.