You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2013/11/19 19:55:24 UTC
git commit: TAP5-2224: t5/core/ajax should return a RequestWrapper
Updated Branches:
refs/heads/master 57f7db250 -> 06ce2fbed
TAP5-2224: t5/core/ajax should return a RequestWrapper
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/06ce2fbe
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/06ce2fbe
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/06ce2fbe
Branch: refs/heads/master
Commit: 06ce2fbed946e252afa2740fe3e41e3ecb6e5b52
Parents: 57f7db2
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Nov 19 10:55:16 2013 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Nov 19 10:55:16 2013 -0800
----------------------------------------------------------------------
.../org/apache/tapestry5/t5-core-dom.coffee | 29 ++++++++++++++++----
1 file changed, 24 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/06ce2fbe/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
index a1cc726..4916690 100644
--- a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
+++ b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
@@ -620,6 +620,25 @@ define ["underscore", "./utils", "./events", "jquery"],
#if jquery
# Wrapper around the `jqXHR` object
+ class RequestWrapper
+
+ constructor: (@jqxhr) ->
+
+ # Abort a running ajax request
+ abort: -> @jqxhr.abort()
+#elseif prototype
+ # Wrapper around the Prototype `Ajax.Request` object
+ class RequestWrapper
+
+ constructor: (@req) ->
+
+ # Abort a running ajax request
+ abort: -> throw "Cannot abort Ajax request when using Prototype."
+#endif
+
+
+#if jquery
+ # Wrapper around the `jqXHR` object
class ResponseWrapper
constructor: (@jqxhr, data) ->
@@ -668,7 +687,7 @@ define ["underscore", "./utils", "./events", "jquery"],
# Returns the module's exports
ajaxRequest = (url, options = {}) ->
#if jquery
- $.ajax
+ jqxhr = $.ajax
url: url
type: options.method?.toUpperCase() or "POST"
contentType: options.contentType
@@ -676,6 +695,7 @@ define ["underscore", "./utils", "./events", "jquery"],
data: options.data
# jQuery doesn't have the equivalent of Protoype's onException
error: (jqXHR, textStatus, errorThrown) ->
+ return if textStatus is "abort"
message = "Request to #{url} failed with status #{textStatus}"
text = jqXHR.statusText
if not _.isEmpty text
@@ -693,6 +713,7 @@ define ["underscore", "./utils", "./events", "jquery"],
options.success and options.success(new ResponseWrapper jqXHR, data)
return
+ new RequestWrapper jqxhr
#elseif prototype
finalOptions =
method: options.method or "post"
@@ -733,11 +754,9 @@ define ["underscore", "./utils", "./events", "jquery"],
options.success and options.success(new ResponseWrapper response)
return
- new Ajax.Request(url, finalOptions)
+ new RequestWrapper (new Ajax.Request url, finalOptions)
#endif
- return exports
-
# The main export is a function that wraps a DOM element as an ElementWrapper; additional functions are attached as
# properties.
#
@@ -833,4 +852,4 @@ define ["underscore", "./utils", "./events", "jquery"],
# it is always safe to get the body.
body: wrapElement document.body
- return exports
\ No newline at end of file
+ return exports