1 if (Garmin == undefined) var Garmin = {}; 2 /** The list of activities on the device, including additional information 3 * associated with each activity related to state, such as: 4 * 5 * - whether it failed/succeeded upload 6 * - the input checkbox ID for the table 7 * - etc. 8 * 9 * The internal object is an array of Garmin.ActivityDirectory.Entry objects. 10 * The array is in descending order--order shouldn't matter though since you 11 * are accessing objects by ID anyway, like a hash. 12 * @author Diana Chow diana.chow.at.garmin.com 13 * @version 1.0 14 * @class Garmin.ActivityDirectory 15 */ 16 Garmin.ActivityDirectory = function(){}; //just here for jsdoc 17 Garmin.ActivityDirectory = Class.create({ 18 initialize: function() { 19 this.entries = new Array(); 20 }, 21 22 /** Add an entry to the directory by activity ID. 23 */ 24 addEntry: function(activityId, name, duration, displayElementId) { 25 var entry = new Garmin.ActivityDirectory.Entry(activityId, name, duration, null, displayElementId); 26 this.entries.push(entry); 27 return entry; 28 }, 29 30 /** Get the Garmin.ActivityDirectory.Entry object for the given activity ID. 31 * Null if not found. 32 */ 33 getEntry: function(activityId) { 34 var entrizzle = null; 35 for(var i=0; i < this.entries.length; i++) { 36 if( this.entries[i].id == activityId) { 37 entrizzle = this.entries[i]; 38 } 39 } 40 return entrizzle; 41 }, 42 43 /** Returns the array of entries in the same order they were initialized in. 44 */ 45 getEntries: function() { 46 return this.entries; 47 }, 48 49 /** Returns the first entry in the directory. 50 */ 51 getFirstEntry: function() { 52 return this.entries[0]; 53 }, 54 55 /** Get the number of activities that failed upload. 56 */ 57 getFailureCount: function() { 58 var failureCount = 0; 59 for(var i=0; i < this.entries.length; i++) { 60 if( this.entries[i].successfulUpload == false) { 61 failureCount++; 62 } 63 } 64 return failureCount; 65 }, 66 67 /** Returns a list (array) of just the IDs. 68 */ 69 getIds: function() { 70 var idList = new Array(); 71 for( var i=0; i < this.entries.length; i++) { 72 idList.push(this.entries[i].id); 73 } 74 return idList; 75 }, 76 77 /** Get the number of activities that succeeded upload. 78 */ 79 getSuccessCount: function() { 80 var successCount = 0; 81 for(var i=0; i < this.entries.length; i++) { 82 if( this.entries[i].successfulUpload == true) { 83 successCount++; 84 } 85 } 86 return successCount; 87 }, 88 89 /** Indicate that an activity failed upload. 90 */ 91 setFailed: function(activityId) { 92 if( this.getEntry(activityId) != null) { 93 this.getEntry(activityId).successfulUpload = false; 94 } 95 }, 96 97 /** Indicate that an activity succeeded upload. 98 */ 99 setSuccess: function(activityId) { 100 if( this.getEntry(activityId) != null) { 101 this.getEntry(activityId).successfulUpload = true; 102 } 103 }, 104 105 /** Get the number of activities in the directory. 106 */ 107 size: function() { 108 return this.entries ? this.entries.length : 0; 109 } 110 }); 111 112 /** An activity entry in the directory. 113 * Only the activity ID is required. The rest are optional. 114 */ 115 Garmin.ActivityDirectory.Entry = Class.create({ 116 initialize: function(activityId, name, duration, successfulUpload, displayElementId) { 117 this.id = activityId; 118 this.name = name; 119 this.duration = duration; 120 this.successfulUpload = successfulUpload; 121 this.displayElementId = displayElementId; 122 this.path = null; 123 } 124 }); 125 126