[76] | 1 | /** |
---|
| 2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
---|
| 3 | * |
---|
| 4 | * Published under the BSD license. |
---|
| 5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
| 6 | * of the license. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /** api: override = Ext.Ajax */ |
---|
| 10 | (function() { |
---|
| 11 | |
---|
| 12 | /** private: function[createComplete] |
---|
| 13 | * ``Function`` |
---|
| 14 | */ |
---|
| 15 | var createComplete = function(fn, cb) { |
---|
| 16 | return function(request) { |
---|
| 17 | if(cb && cb[fn]) { |
---|
| 18 | cb[fn].call(cb.scope || window, { |
---|
| 19 | responseText: request.responseText, |
---|
| 20 | responseXML: request.responseXML, |
---|
| 21 | argument: cb.argument |
---|
| 22 | }); |
---|
| 23 | } |
---|
| 24 | }; |
---|
| 25 | }; |
---|
| 26 | |
---|
| 27 | Ext.apply(Ext.lib.Ajax, { |
---|
| 28 | /** private: method[request] |
---|
| 29 | */ |
---|
| 30 | request: function(method, uri, cb, data, options) { |
---|
| 31 | options = options || {}; |
---|
| 32 | method = method || options.method; |
---|
| 33 | var hs = options.headers; |
---|
| 34 | if(options.xmlData) { |
---|
| 35 | if(!hs || !hs["Content-Type"]) { |
---|
| 36 | hs = hs || {}; |
---|
| 37 | hs["Content-Type"] = "text/xml"; |
---|
| 38 | } |
---|
| 39 | method = method || "POST"; |
---|
| 40 | data = options.xmlData; |
---|
| 41 | } else if(options.jsonData) { |
---|
| 42 | if(!hs || !hs["Content-Type"]) { |
---|
| 43 | hs = hs || {}; |
---|
| 44 | hs["Content-Type"] = "application/json"; |
---|
| 45 | } |
---|
| 46 | method = method || "POST"; |
---|
| 47 | data = typeof options.jsonData == "object" ? |
---|
| 48 | Ext.encode(options.jsonData) : options.jsonData; |
---|
| 49 | } |
---|
| 50 | // if POST method, options.form or options.params means |
---|
| 51 | // form-encoded data, so change content-type |
---|
| 52 | if ((method && method.toLowerCase() == "post") && |
---|
| 53 | (options.form || options.params) && |
---|
| 54 | (!hs || !hs["Content-Type"])) { |
---|
| 55 | hs = hs || {}; |
---|
| 56 | hs["Content-Type"] = "application/x-www-form-urlencoded"; |
---|
| 57 | } |
---|
| 58 | return OpenLayers.Request.issue({ |
---|
| 59 | success: createComplete("success", cb), |
---|
| 60 | failure: createComplete("failure", cb), |
---|
| 61 | method: method, |
---|
| 62 | headers: hs, |
---|
| 63 | data: data, |
---|
| 64 | url: uri |
---|
| 65 | }); |
---|
| 66 | }, |
---|
| 67 | |
---|
| 68 | /** private: method[isCallInProgress] |
---|
| 69 | * :params request: ``Object`` The XHR object. |
---|
| 70 | */ |
---|
| 71 | isCallInProgress: function(request) { |
---|
| 72 | // do not prevent our caller from calling abort() |
---|
| 73 | return true; |
---|
| 74 | }, |
---|
| 75 | |
---|
| 76 | /** private: method[abort] |
---|
| 77 | * :params request: ``Object`` The XHR object. |
---|
| 78 | */ |
---|
| 79 | abort: function(request) { |
---|
| 80 | request.abort(); |
---|
| 81 | } |
---|
| 82 | }); |
---|
| 83 | })(); |
---|