1 if (Garmin == undefined) var Garmin = {};
  2 /** The newer activity filter for synchronizing lists.  It makes an AJAX request
  3  * to a remote service in order to detect matches on the server.  It is dependent
  4  * on Garmin.Axm.ActivityMatch, which wraps around the json response making it 
  5  * easy to retrieve the JSON values via javascript.   
  6  *  
  7  * @author Diana Chow diana.chow.at.garmin.com
  8  * @version 1.0
  9  * @class Garmin.ActivityMatcher
 10  */ 
 11 Garmin.ActivityMatcher = function(deviceXml, allActivityIds, ajaxUrl, ajaxOptions, callback){}; //just here for jsdoc
 12 Garmin.ActivityMatcher = Class.create();
 13 Garmin.ActivityMatcher.prototype = {
 14     initialize: function(deviceXml, allActivityIds, ajaxUrl, ajaxOptions, callback) {
 15         this.allActivityIds = allActivityIds;
 16         this.ajaxUrl = ajaxUrl;
 17         this.ajaxOptions = ajaxOptions;
 18         this.ajaxOptions.parameters = {deviceXml: deviceXml, externalIds: allActivityIds};
 19         this.callback = callback;
 20         
 21         this.apiRequest = new Garmin.RemoteTransfer();
 22         this.apiResponse = null;
 23         
 24         this.activityMatches = null;
 25     },
 26     
 27     /** Run the filter.  Makes the AJAX request to find matching IDs on the
 28      * server and populates the filtered list. 
 29      */
 30     run: function() {
 31         
 32         this.ajaxOptions.onSuccess = function(xhr) {
 33             this.activityMatches = new Garmin.Axm.ActivityMatch(xhr.responseJSON);
 34         	this.callback();
 35     	}.bind(this);
 36         
 37         this.apiResponse = this.apiRequest.openRequest(this.ajaxUrl, this.ajaxOptions);
 38     },
 39     
 40     /** Get the matching JSON object for given activity ID from the original response object.
 41      * Null if not found or if activity matcher service is unavailable.
 42      */
 43     get: function(activityId) {
 44         if( this.activityMatches != null) {
 45             return this.activityMatches.getMatch(activityId);
 46         }
 47     }
 48 }
 49 
 50 /**
 51  * Wrapper for the Axm activityMatch JSON return object.  This is a lightweight wrapper.  All
 52  * it does is find the given activity in the original response object and return it.  You should access
 53  * the properties of that object directly.
 54  */
 55 if (Garmin.Axm == undefined) Garmin.Axm = {};
 56 Garmin.Axm.ActivityMatch = function(){}; // for jsdoc
 57 Garmin.Axm.ActivityMatch = Class.create();
 58 Garmin.Axm.ActivityMatch.prototype = {
 59     
 60     initialize: function(json) {
 61         if( json != null && json['matches'] != null) {
 62             this.activityMatchesJson = json['matches'];
 63         }
 64     },
 65     
 66     /** Looks up the match for the given external ID.  This returns the JSON object for 
 67      * direct access.  isMatch and isDeleted can be accessed directly from the return object:
 68      * 
 69      * returned.isMatch
 70      * returned.isDeleted
 71      * 
 72      * @return {JSON} the match result, or null if the ID is not found in the original response
 73      */
 74     getMatch: function(activityId) {
 75         return this.activityMatchesJson[activityId];
 76     }
 77 }