package com.eas.client.xhr;

import com.google.gwt.xhr.client.XMLHttpRequest;

public class XMLHttpRequest2 extends XMLHttpRequest {

	protected XMLHttpRequest2() {
	}

	public static native XMLHttpRequest2 createAnon() /*-{
		if ($wnd.AnonXMLHttpRequest) {
			return new $wnd.AnonXMLHttpRequest();
		} else {
			return @com.google.gwt.xhr.client.XMLHttpRequest::create();
		}
	}-*/;

    public final native void open(String httpMethod, String url, String user, String password, boolean async) /*-{
		this.open(httpMethod, url, async, user, password);
    }-*/;
	  
    public final native void open(String httpMethod, String url, boolean async) /*-{
		this.open(httpMethod, url, async);
    }-*/;
    
	public final native <T> T getResponse() /*-{
		return this.response;
	}-*/;

	public final native String getResponseType() /*-{
		return this.responseType;
	}-*/;

	public final native int getTimeOut() /*-{
		return this.timeout;
	}-*/;

	public final native XmlHttpRequestUpload getUpload() /*-{
		return this.upload;
	}-*/;

	public final native boolean getWithCredentials() /*-{
		return this.withCredentials;
	}-*/;

	public final native void overrideMimeType(String mimeType) /*-{
		this.overrideMimeType(mimeType);
	}-*/;

	public final native <T> void send(T requestData) /*-{
		this.send(requestData);
	}-*/;

	public final native void setOnLoadStart(ProgressHandler handler) /*-{
		var _this = this;
		this.onloadstart = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onLoadStart(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setOnProgress(ProgressHandler handler) /*-{
		var _this = this;
		this.onprogress = function(evt) {
			handler.@com.eas.client.xhr.ProgressHandler::onProgress(Lcom/eas/client/xhr/ProgressEvent;)(evt);
		};
	}-*/;

	public final native void setOnAbort(ProgressHandler handler) /*-{
		var _this = this;
		this.onabort = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onAbort(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setOnError(ProgressHandler handler) /*-{
		var _this = this;
		this.onerror = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onError(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setOnLoad(ProgressHandler handler) /*-{
		var _this = this;
		this.onload = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onLoad(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setOnTimeOut(ProgressHandler handler) /*-{
		var _this = this;
		this.ontimeout = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onTimeOut(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setOnLoadEnd(ProgressHandler handler) /*-{
		var _this = this;
		this.onloadend = function() {
			handler.@com.eas.client.xhr.ProgressHandler::onLoadEnd(Lcom/google/gwt/xhr/client/XMLHttpRequest;)(_this);
		};
	}-*/;

	public final native void setResponseType(String responseType) /*-{
		this.responseType = responseType;
	}-*/;

	public final native void setTimeOut(int timeout) /*-{
		this.timeout = timeout;
	}-*/;

	public final native void setUpload(XmlHttpRequestUpload upload) /*-{
		this.upload = upload;
	}-*/;

	public final native void setWithCredentials(boolean withCredentials) /*-{
		this.withCredentials = withCredentials;
	}-*/;
}
@@ -808,99 +808,8 @@
 %0D%0A%0D%0A
-%09public final native String getResponseType() /*-%7B%0D%0A%09%09return this.responseType;%0D%0A%09%7D-*/;%0D%0A%0D%0A
 %09pub
@@ -3020,124 +3020,8 @@
 %0D%0A%0D%0A
-%09public final native void setResponseType(String responseType) /*-%7B%0D%0A%09%09this.responseType = responseType;%0D%0A%09%7D-*/;%0D%0A%0D%0A
 %09pub
@@ -3216,135 +3216,6 @@
 */;%0D
-%0A%0D%0A%09public final native void setWithCredentials(boolean withCredentials) /*-%7B%0D%0A%09%09this.withCredentials = withCredentials;%0D%0A%09%7D-*/;%0D
 %0A%7D

Fix for GWT2.5 support