Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle on_ERROR_CODE in jquery remote function #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptProvider
/**
* @author Sergey Nebolsin ([email protected])
* @author Finn Herpich (finn.herpich <at> marfinn-software <dot> de)
* @author Manuel Boillod
*/
class JQueryProvider implements JavascriptProvider {
/**
Expand Down Expand Up @@ -127,7 +128,7 @@ class JQueryProvider implements JavascriptProvider {
out << ','

//*** success
out << 'success:function(data,textStatus){'
out << 'success:function(data,textStatus,XMLHttpRequest){'

if(attrs.onLoaded)
out << "${attrs.onLoaded};"
Expand Down Expand Up @@ -162,6 +163,33 @@ class JQueryProvider implements JavascriptProvider {

if(attrs.onComplete)
out << ",complete:function(XMLHttpRequest,textStatus){${attrs.onComplete}}"

//*** on_ERROR_CODE
boolean hasOnStatusCodes = false
attrs.each { k, v ->
def statusMatch = k =~ /^on(\d{3})$/
if (statusMatch.matches()){
//new status code
if (hasOnStatusCodes){
out << ","
} else {
out << ",statusCode: {"
hasOnStatusCodes = true
}
int status = statusMatch[0][1] as int
//All success 2xx codes and not modified 304 code
if ( status >= 200 && status < 300 || status == 304 ) {
//success parameters
out << "${status}:function(data,textStatus,XMLHttpRequest){${v}}"
} else {
//error parameters
out << "${status}:function(XMLHttpRequest,textStatus,errorThrown){${v}}"
}
}
}
if (hasOnStatusCodes){
out << "}"
}
}

/**
Expand Down