001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.client.core;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011: import com.gwtext.client.util.JavaScriptObjectHelper;
012:
013: //http://extjs.com/forum/showthread.php?t=7072&highlight=Ajax+Connection
014: //http://extjs.com/forum/showthread.php?t=7737&highlight=Ajax+Connection
015: //http://extjs.com/forum/showthread.php?t=7249&highlight=Ajax+Connection
016:
017: /**
018: * Global Ajax request class. This class is a singleton and cannot be created directly.
019: */
020: public class Ajax extends Connection {
021:
022: private static Ajax instance;
023:
024: private Ajax(JavaScriptObject jsObj) {
025: this .jsObj = jsObj;
026: }
027:
028: public static Ajax getInstance() {
029: if (instance == null) {
030: instance = new Ajax(getSingleton());
031: }
032: return instance;
033: }
034:
035: private static native JavaScriptObject getSingleton() /*-{
036: return $wnd.Ext.Ajax;
037: }-*/;
038:
039: /**
040: * Whether a new request should abort any pending requests.
041: *
042: * @param autoAbort defaults to false
043: */
044: public void setAutoAbort(boolean autoAbort) {
045: JavaScriptObjectHelper.setAttribute(jsObj, "autoAbort",
046: autoAbort);
047: }
048:
049: /**
050: * Request headers which are added to each request made by this object.
051: *
052: * @param defaultHeaders default header params
053: */
054: public void setDefaultHeaders(NameValuePair[] defaultHeaders) {
055: JavaScriptObject paramObj = NameValuePair
056: .getJsObj(defaultHeaders);
057: JavaScriptObjectHelper.setAttribute(jsObj, "defaultHeaders",
058: paramObj);
059: }
060:
061: /**
062: * True to add a unique cache-buster param to GET requests.
063: *
064: * @param disableCaching defaults to true
065: */
066: public void setDisableCaching(boolean disableCaching) {
067: JavaScriptObjectHelper.setAttribute(jsObj, "disableCaching",
068: disableCaching);
069: }
070:
071: /**
072: * Extra parameters to each request made by this object.
073: *
074: * @param params extra params
075: */
076: public void setExtraParams(UrlParam[] params) {
077: JavaScriptObject paramObj = UrlParam.getJsObj(params);
078: JavaScriptObjectHelper.setAttribute(jsObj, "extraParams",
079: paramObj);
080: }
081:
082: /**
083: * The default HTTP method to be used for requests.
084: *
085: * @param method defaults to undefined; if not set but parms are present will use POST, otherwise GET
086: */
087: public void setMethod(Method method) {
088: JavaScriptObjectHelper.setAttribute(jsObj, "method", method
089: .getMethod());
090: }
091:
092: /**
093: * The timeout in milliseconds to be used for requests.
094: *
095: * @param timeout defaults to 30000
096: */
097: public void setTimeout(int timeout) {
098: JavaScriptObjectHelper.setAttribute(jsObj, "timeout", timeout);
099: }
100:
101: /**
102: * The default URL to be used for requests to the server.
103: *
104: * @param url the url to make the request to
105: */
106: public void setUrl(String url) {
107: JavaScriptObjectHelper.setAttribute(jsObj, "url", url);
108: }
109:
110: /**
111: * Serialize the passed form into a url encoded string
112: *
113: * @param formId the form id
114: * @return url encoded String
115: */
116: public native String serializeForm(String formId) /*-{
117: var conn = this.@com.gwtext.client.core.JsObject::getJsObj()();
118: return conn.serializeForm(formId);
119: }-*/;
120: }
|