1 if (Garmin == undefined) var Garmin = {}; 2 /** Copyright � 2007 Garmin Ltd. or its subsidiaries. 3 * 4 * Licensed under the Apache License, Version 2.0 (the 'License') 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an 'AS IS' BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 * @fileoverview Garmin.RemoteTransfer is a high-level API to transfer data to remote servers using POST, 17 * web service calls, and the like. 18 * 19 * @author Diana Chow diana.chow at garmin.com 20 * @version 1.0 21 */ 22 /** 23 * 24 * @class Garmin.RemoteTransfer 25 * @constructor 26 * 27 * requires Prototype and Garmin.DeviceDisplay 28 */ 29 Garmin.RemoteTransfer = function(){}; //just here for jsdoc 30 Garmin.RemoteTransfer = Class.create(); 31 Garmin.RemoteTransfer.prototype = { 32 33 initialize: function() { 34 this.ajaxRequest = null; 35 this.ajaxResponse = null; 36 this.apiResponse = null; 37 this.errorMsg = null; 38 }, 39 40 /** Open a REST request to a web service. The result is returned (if any) along 41 * with request status and any error info provided by the HTTP response. 42 * 43 * @param url - the URL of the web service endpoint 44 * @param ajaxOptions - options used for the ajax call. Please see http://www.prototypejs.org/api/ajax/options. 45 * @return a response hash containing the AJAX response object, and an error message if there was one. 46 * Ids of the response elements are response and error. 47 */ 48 openRequest: function(url, ajaxOptions) { 49 this.ajaxRequest = new Ajax.Request(url, ajaxOptions); 50 }, 51 52 /** Abort the active http request, if any. 53 */ 54 abortRequest: function() { 55 Ajax.Request.prototype.abort(this.ajaxRequest); 56 } 57 }; 58 59 /** 60 * Ajax.Request.abort 61 * extend the prototype.js Ajax.Request object so that it supports an abort method 62 */ 63 Ajax.Request.prototype.abort = function(xhr) { 64 // prevent and state change callbacks from being issued 65 xhr.transport.onreadystatechange = Prototype.emptyFunction; 66 // abort the XHR 67 xhr.transport.abort(); 68 // update the request counter 69 Ajax.activeRequestCount--; 70 }; 71 72 /** 73 * Error messages used by this class. 74 */ 75 Garmin.RemoteTransfer.MESSAGES = { 76 badRequestException: "There was a problem with the request. Check request parameters.", 77 /** 78 * Message used for general exceptions 79 */ 80 generalException: "An error occured while completing the request.", 81 /** 82 * Message used when there is no response from the request. 83 */ 84 noResponseException: "No response from the URL. Check URL and domain permissions.", 85 /** 86 * Message used when the URL is not found (404). 87 */ 88 urlNotFoundException: "The URL requested was not found (404). Check URL." 89 }; 90