GarminDeviceDisplay.js
Summary
Garmin.DeviceDisplay is a high-level UI widget for talking
with Garmin Devices.
Version: 1.0
Author: Michael Bina michael.bina.at.garmin.com
if (Garmin == undefined) var Garmin = {};
Garmin.DeviceDisplay = function(mainElement, options){};
Garmin.DeviceDisplay = Class.create();
Garmin.DeviceDisplay.prototype = {
initialize: function(mainElement, options) {
if(typeof(mainElement) == "string") {
this.mainElement = $(mainElement);
} else {
this.mainElement = mainElement;
}
this.options = null;
this.setOptions(options);
this.garminController = null;
this.tracks = null;
this.waypoints = null;
this._generateElements();
if (this.options.unlockOnPageLoad) {
this.getController(true);
}
if (this.options.autoFindDevices) {
this.startFindDevices();
}
},
getController: function(unlock) {
if (!this.garminController) {
try {
this.garminController = new Garmin.DeviceControl();
this.garminController.register(this);
} catch (e) {
this.handleException(e);
return null;
}
}
if (unlock && !this.isUnlocked()) {
if(this.garminController.unlock(this.options.pathKeyPairsArray)) {
this.setStatus("Plug-in initialized. Find some devices to get started.");
} else {
this.setStatus("The plug-in was not unlocked successfully.");
}
}
return this.garminController;
},
isUnlocked: function() {
return (this.garminController && this.garminController.isActivated());
},
setOptions: function(options) {
for(key in options || {}) {
if ( ! (key in Garmin.DeviceDisplayDefaultOptions) ) {
var err = new Error(key+" is not a valid option name, see Garmin.DeviceDisplayDefaultOptions");
err.name = "InvalidOptionException";
throw err;
}
}
this.options = Object.extend(Garmin.DeviceDisplayDefaultOptions, options || {});
},
_generateElements: function() {
if (BrowserSupport.isBrowserSupported() || !this.options.hideIfBrowserNotSupported) {
this._generateStatusElement();
if(this.options.showFindDevicesElement) {
this._generateFindDevicesElement();
}
if(this.options.showReadDataElement) {
this._generateReadDataElement();
}
if(this.options.showWriteDataElement) {
this._generateWriteDataElement();
}
this._generateAboutElement();
this.resetUI();
}
},
resetUI: function(statusMsg) {
this.hideProgressBar();
if(statusMsg) {
this.setStatus(statusMsg);
}
var noDevicesAvailable = this.garminController ? (this.getController().numDevices==0) : true;
if(this.options.showFindDevicesElement) {
if (this.findDevicesButton)
this.findDevicesButton.disabled = false;
if (this.deviceSelect)
this.deviceSelect.disabled = noDevicesAvailable;
if (this.cancelFindDevicesButton)
this.cancelFindDevicesButton.disabled = true;
if (this.readDataTypesSelect)
this.readDataTypesSelect.disabled = false;
}
if(this.options.showReadDataElement) {
if (this.readDataButton)
this.readDataButton.disabled = noDevicesAvailable;
if (this.cancelReadDataButton)
this.cancelReadDataButton.disabled = true;
}
if(this.options.showWriteDataElement) {
if (this.writeDataButton)
this.writeDataButton.disabled = noDevicesAvailable;
if (this.cancelWriteDataButton)
this.cancelWriteDataButton.disabled = true;
}
},
_generateStatusElement: function() {
this.statusElement = document.createElement("div");
Element.extend(this.statusElement);
this.statusElement.id = this.options.statusElementId;
this.statusElement.addClassName(this.options.elementClassName);
this.mainElement.appendChild(this.statusElement);
this.statusText = document.createElement("div");
Element.extend(this.statusText);
this.statusText.id = this.options.statusTextId;
this.statusElement.appendChild(this.statusText);
this.progressBar = document.createElement("div");
Element.extend(this.progressBar);
this.progressBar.id = this.options.progressBarId;
this.progressBarDisplay = document.createElement("div");
Element.extend(this.progressBarDisplay);
this.progressBarDisplay.id = this.options.progressBarDisplayId;
var wrapper = document.createElement("div");
Element.extend(wrapper);
wrapper.setStyle({position: 'relative'});
wrapper.appendChild(this.progressBarDisplay);
this.progressBar.appendChild(wrapper);
this.statusElement.appendChild(this.progressBar);
Element.hide(this.progressBar);
},
_createElement: function(id, text, type, parent) {
var elem = document.createElement(type);
Element.extend(elem);
if (type=="a") {
elem.href = location;
elem.innerHTML = text;
} else if (type=="button"){
elem.type = type;
elem.value = text;
}
elem.id = id;
parent.appendChild(elem);
return elem;
},
_generateFindDevicesElement: function() {
this.findDevicesElement = document.createElement("div");
Element.extend(this.findDevicesElement);
this.findDevicesElement.id = this.options.findDevicesElementId;
this.findDevicesElement.addClassName(this.options.elementClassName);
this.mainElement.appendChild(this.findDevicesElement);
this.findDevicesButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.findDevicesButton);
if (this.options.useLinks) {
this.findDevicesButton.href = "#";
this.findDevicesButton.innerHTML = this.options.findDevicesButtonText;
} else {
this.findDevicesButton.type = "button";
this.findDevicesButton.value = this.options.findDevicesButtonText;
}
this.findDevicesButton.id = this.options.findDevicesButtonId;
this.findDevicesButton.addClassName(this.options.actionButtonClassName);
this.findDevicesElement.appendChild(this.findDevicesButton);
this.findDevicesButton.onclick = function() {
this.startFindDevices();
}.bind(this)
if (this.options.showCancelFindDevicesButton) {
this.cancelFindDevicesButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.cancelFindDevicesButton);
if (this.options.useLinks) {
this.cancelFindDevicesButton.href = "#";
this.cancelFindDevicesButton.innerHTML = this.options.cancelFindDevicesButtonText;
} else {
this.cancelFindDevicesButton.type = "button";
this.cancelFindDevicesButton.value = this.options.cancelFindDevicesButtonText;
}
this.cancelFindDevicesButton.id = this.options.cancelFindDevicesButtonId;
this.cancelFindDevicesButton.addClassName(this.options.actionButtonClassName);
this.cancelFindDevicesButton.disabled = true;
this.cancelFindDevicesButton.onclick = function() {
this.cancelFindDevices();
}.bind(this)
this.findDevicesElement.appendChild(this.cancelFindDevicesButton);
}
if (!this.options.showDeviceButtonsOnLoad) {
if (this.findDevicesButton) {
Element.hide(this.findDevicesButton);
}
if (this.cancelFindDevicesButton)
Element.hide(this.cancelFindDevicesButton);
}
this.deviceSelectElement = document.createElement("span");
Element.extend(this.deviceSelectElement);
this.deviceSelectElement.id = this.options.deviceSelectElementId;
this.deviceSelectElement.innerHTML = "<span id=\"" + this.options.deviceSelectLabelId + "\">" + this.options.deviceSelectLabel + "</span>";
this.findDevicesElement.appendChild(this.deviceSelectElement);
this.deviceSelect = document.createElement("select");
Element.extend(this.deviceSelect);
this.deviceSelect.id = this.options.deviceSelectId;
this.deviceSelect.disabled = true;
this.deviceSelectElement.appendChild(this.deviceSelect);
if (!this.options.showDeviceSelectOnLoad || !this.options.showDeviceSelectOnSingle) {
Element.hide(this.deviceSelectElement);
}
},
_generateReadDataElement: function() {
this.readDataElement = document.createElement("div");
Element.extend(this.readDataElement);
this.readDataElement.id = this.options.readDataElementId;
this.readDataElement.addClassName(this.options.elementClassName);
this.mainElement.appendChild(this.readDataElement);
this.readDataButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.readDataButton);
if (this.options.useLinks) {
this.readDataButton.href = "#";
this.readDataButton.innerHTML = this.options.readDataButtonText;
} else {
this.readDataButton.type = "button";
this.readDataButton.value = this.options.readDataButtonText;
}
this.readDataButton.id = this.options.readDataButtonId;
this.readDataButton.addClassName(this.options.actionButtonClassName);
this.readDataButton.disabled = true;
this.readDataButton.onclick = function() {
this.readDataButton.disabled = true;
this.cancelReadDataButton.disabled = false;
this.showProgressBar();
if (this.options.showReadDataTypesSelect) {
this.readSpecificTypeFromDevice(this.readDataTypesSelect.value);
} else {
this.readFromDevice();
}
}.bind(this)
this.readDataElement.appendChild(this.readDataButton);
this.cancelReadDataButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.cancelReadDataButton);
if (this.options.useLinks) {
this.cancelReadDataButton.href = "#";
this.cancelReadDataButton.innerHTML = this.options.cancelReadDataButtonText;
} else {
this.cancelReadDataButton.type = "button";
this.cancelReadDataButton.value = this.options.cancelReadDataButtonText;
}
this.cancelReadDataButton.id = this.options.cancelReadDataButtonId;
this.cancelReadDataButton.addClassName(this.options.actionButtonClassName);
this.cancelReadDataButton.disabled = true;
this.cancelReadDataButton.onclick = function() {
this.resetUI();
this.hideProgressBar();
this.getController().cancelReadFromDevice();
}.bind(this)
this.readDataElement.appendChild(this.cancelReadDataButton);
if(this.options.showReadDataTypesSelect) {
this.readDataTypesSelect = document.createElement("select");
Element.extend(this.readDataTypesSelect);
this.readDataTypesSelect.id = this.options.readDataTypesSelectId;
this.readDataTypesSelect.disabled = true;
this.readDataElement.appendChild(this.readDataTypesSelect);
this.readDataTypesSelect.options[0] = new Option("GPS Data", "gpx");
this.readDataTypesSelect.options[1] = new Option("Training Data", "hst");
}
if(this.options.showReadTracksSelect) {
this.readTracksElement = document.createElement("div");
Element.extend(this.readTracksElement);
this.readTracksElement.id = this.options.readTracksElementId;
this.readTracksElement.addClassName(this.options.readResultsElementClass);
this.readTracksElement.innerHTML = "<span id=\"" + this.options.readTracksSelectLabelId + "\">" + this.options.readTracksSelectLabel + "</span>";
this.readTracksSelect = document.createElement("select");
Element.extend(this.readTracksSelect);
this.readTracksSelect.id = this.options.readTracksSelectId;
this.readTracksSelect.addClassName(this.options.readResultsSelectClass);
this.readTracksSelect.disabled = true;
this.readTracksElement.appendChild(this.readTracksSelect);
this.readDataElement.appendChild(this.readTracksElement);
if(!this.showReadResultsSelectOnLoad) {
Element.hide(this.readTracksElement);
}
}
if(this.options.showReadWaypointsSelect) {
this.readWaypointsElement = document.createElement("div");
Element.extend(this.readWaypointsElement);
this.readWaypointsElement.id = this.options.readWaypointsElementId;
this.readWaypointsElement.addClassName(this.options.readResultsElementClass);
this.readWaypointsElement.innerHTML = "<span id=\"" + this.options.readWaypointsSelectLabelId + "\">" + this.options.readWaypointsSelectLabel + "</span>";
this.readWaypointsSelect = document.createElement("select");
Element.extend(this.readWaypointsSelect);
this.readWaypointsSelect.id = this.options.readWaypointsSelectId;
this.readWaypointsSelect.addClassName(this.options.readResultsSelectClass);
this.readWaypointsSelect.disabled = true;
this.readWaypointsElement.appendChild(this.readWaypointsSelect);
this.readDataElement.appendChild(this.readWaypointsElement);
if(!this.showReadResultsSelectOnLoad) {
Element.hide(this.readWaypointsElement);
}
}
if(this.options.showReadGoogleMap) {
this.readGoogleMap = document.createElement("div");
Element.extend(this.readGoogleMap);
this.readGoogleMap.id = this.options.readGoogleMapId;
this.readGoogleMap.addClassName(this.options.readResultsElementClass);
this.readDataElement.appendChild(this.readGoogleMap);
this.readMapController = new Garmin.MapController(this.options.readGoogleMapId);
}
},
_generateWriteDataElement: function() {
this.writeDataElement = document.createElement("div");
Element.extend(this.writeDataElement);
this.writeDataElement.id = this.options.writeDataElementId;
this.writeDataElement.addClassName(this.options.elementClassName);
this.mainElement.appendChild(this.writeDataElement);
if (!this.options.getWriteData)
throw new Error("getWriteData() function is not defined");
this.writeDataButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.writeDataButton);
if (this.options.useLinks) {
this.writeDataButton.href = "#";
this.writeDataButton.innerHTML = this.options.writeDataButtonText;
} else {
this.writeDataButton.type = "button";
this.writeDataButton.value = this.options.writeDataButtonText;
}
this.writeDataButton.id = this.options.writeDataButtonId;
this.writeDataButton.addClassName(this.options.actionButtonClassName);
this.writeDataButton.disabled = true;
this.cancelWriteDataButton = document.createElement( this.options.useLinks ? "a" : "input" );
Element.extend(this.cancelWriteDataButton);
if (this.options.useLinks) {
this.cancelWriteDataButton.href = "#";
this.cancelWriteDataButton.innerHTML = this.options.cancelWriteDataButtonText;
} else {
this.cancelWriteDataButton.type = "button";
this.cancelWriteDataButton.value = this.options.cancelWriteDataButtonText;
}
this.cancelWriteDataButton.id = this.options.cancelWriteDataButtonId;
this.cancelWriteDataButton.addClassName(this.options.actionButtonClassName);
this.cancelWriteDataButton.disabled = false;
this.writeDataButton.onclick = function() {
this.writeDataButton.disabled = true;
this.cancelWriteDataButton.disabled = false;
this.showProgressBar();
this.getController().writeToDevice(this.options.getWriteData(), this.options.getWriteDataFileName());
}.bind(this);
this.cancelWriteDataButton.onclick = function() {
this.resetUI();
this.hideProgressBar();
this.getController().cancelWriteToDevice();
}.bind(this);
this.writeDataElement.appendChild(this.writeDataButton);
this.writeDataElement.appendChild(this.cancelWriteDataButton);
},
_generateAboutElement: function() {
this.aboutElement = document.createElement("div");
Element.extend(this.aboutElement);
this.aboutElement.id = "aboutElement";
this.aboutElement.addClassName(this.options.elementClassName);
this.mainElement.appendChild(this.aboutElement);
this.copyrightText = document.createElement("span");
this.copyrightText.innerHTML = "Powered by <a href='http://www.garmin.com/products/communicator/' target='_new'>Garmin Communicator</a>";
this.aboutElement.appendChild(this.copyrightText);
},
onStartWriteToDevice: function(json) {
this.setStatus("Writing data to to the device");
},
onCancelWriteToDevice: function(json) {
this.setStatus("Writing cancelled");
},
onWaitingWriteToDevice: function(json) {
if(confirm(json.message.getText())) {
this.setStatus('Overwriting file');
json.controller.respondToMessageBox(true);
} else {
this.setStatus('Will not be overwriting file');
json.controller.respondToMessageBox(false);
}
},
onProgressWriteToDevice: function(json) {
this.updateProgressBar(json.progress.getPercentage());
this.setStatus(json.progress);
},
onFinishWriteToDevice: function(json) {
this.resetUI("Data written to the device.");
if (this.options.afterFinishWriteToDevice) {
this.options.afterFinishWriteToDevice(json.message, this);
}
},
startFindDevices: function() {
this.getController(true);
if(this.findDevicesButton)
this.findDevicesButton.disabled = true;
if (this.cancelFindDevicesButton)
this.cancelFindDevicesButton.disabled = !this.isUnlocked();
if (this.isUnlocked()) {
this.getController().findDevices();
}
},
cancelFindDevices: function() {
this.resetUI();
this.getController().cancelFindDevices();
},
onStartFindDevices: function(json) {
this.setStatus("Looking for connected devices...");
},
onFinishFindDevices: function(json) {
this.resetUI();
if(json.controller.numDevices > 0) {
var devices = json.controller.getDevices();
if (devices.length > 1) {
this.setStatus("Found " + devices.length + " devices.");
} else {
this.setStatus("Found " + devices[0].getDisplayName() + ".");
}
if(this.options.showFindDevicesElement) {
if (this.options.showDeviceButtonsOnFound) {
if (this.findDevicesButton)
Element.show(this.findDevicesButton);
if (this.cancelFindDevicesButton)
Element.show(this.cancelFindDevicesButton);
} else {
if (this.findDevicesButton)
Element.hide(this.findDevicesButton);
if (this.cancelFindDevicesButton)
Element.hide(this.cancelFindDevicesButton);
}
if (devices.length < 2 && !this.options.showDeviceSelectOnSingle) {
Element.hide(this.deviceSelectElement);
} else {
Element.show(this.deviceSelectElement);
}
this._listDevices(devices);
}
if (this.options.autoReadData) {
this.showProgressBar();
if (this.options.showReadDataTypesSelect) {
this.readSpecificTypeFromDevice(this.readDataTypesSelect.value);
} else {
this.readFromDevice();
}
}
if (this.options.autoWriteData) {
this.showProgressBar();
this.getController().writeToDevice(this.options.getWriteData(), this.options.getWriteDataFileName());
}
} else {
if ((this.options.autoReadData || this.options.autoWriteData) && !this.options.showStatusElement) {
alert(this.options.noDeviceDetectedStatusText);
}
this.setStatus(this.options.noDeviceDetectedStatusText);
if(this.options.showFindDevicesElement) {
if (this.options.showFindDevicesButton) {
Element.show(this.findDevicesButton);
}
if (this.options.showCancelFindDevicesButton) {
Element.show(this.cancelFindDevicesButton);
}
if (this.options.showDeviceSelectNoDevice) {
Element.show(this.deviceSelectElement);
}
}
}
},
onCancelFindDevices: function(json) {
this.resetUI("Find cancelled");
},
_listDevices: function(devices) {
this._clearHtmlSelect(this.deviceSelect);
if(this.options.showFindDevicesElement) {
for( var i=0; i < devices.length; i++ ) {
this.deviceSelect.options[i] = new Option(devices[i].getDisplayName(),devices[i].getNumber());
if(devices[i].getNumber() == this.getController().deviceNumber) {
this.deviceSelect.selectedIndex = i;
}
}
this.deviceSelect.onchange = function() {
var device = this.getController().getDevices()[this.deviceSelect.value];
this.setStatus("Using " + device.getDisplayName());
this.getController().setDeviceNumber(this.deviceSelect.value);
}.bind(this)
this.deviceSelect.disabled = false;
}
},
_clearHtmlSelect: function(select) {
if(select) {
select.size = 0;
}
},
readFromDevice: function() {
var deviceNumber = this.getController().deviceNumber;
var device = this.getController().getDevices()[deviceNumber];
if (device.supportDeviceDataTypeRead("hst")) {
this.getController().readFromDeviceFitness();
} else if (device.supportDeviceDataTypeRead("gpx")) {
this.getController().readFromDevice();
} else {
var error = new Error("This device does not have read support for known file types");
error.name = "InvalidTypeException";
this.handleException(error);
}
},
readSpecificTypeFromDevice: function(extension) {
var deviceNumber = this.getController().deviceNumber;
var device = this.getController().getDevices()[deviceNumber];
if (extension == "hst") {
this.getController().readFromDeviceFitness();
} else if (extension == "gpx") {
this.getController().readFromDevice();
} else {
var error = new Error("This device does not have read support for file type: " + extension);
error.name = "InvalidTypeException";
this.handleException(error);
}
},
onProgressReadFromDevice: function(json) {
if(this.options.showProgressBar) {
this.updateProgressBar(json.progress.getPercentage());
}
this.setStatus(json.progress);
},
onCancelReadFromDevice: function(json) {
this.setStatus(this.options.cancelReadStatusText);
},
onFinishReadFromDevice: function(json) {
this.resetUI("Data read from device.");
var gpsData = json.controller.gpsData;
this.clearMapDisplay();
if (this.options.showReadTracksSelect || this.options.showReadWaypointsSelect) {
this.setStatus("Parsing track data...");
var factory = new Garmin.GpsDataFactory();
factory.parseGpxDocument(gpsData);
this.tracks = factory.getTracks();
this.waypoints = factory.getWaypoints();
var foundStatus = "";
if(this.options.showReadTracksSelect || !(this.options.showReadTracksSelect || this.options.showReadWaypointsSelect)) {
foundStatus += this.tracks.length + " tracks";
}
if(this.options.showReadTracksSelect && this.options.showReadWaypointsSelect || !(this.options.showReadTracksSelect || this.options.showReadWaypointsSelect)) {
foundStatus += " and ";
}
if(this.options.showReadWaypointsSelect || !(this.options.showReadTracksSelect || this.options.showReadWaypointsSelect)) {
foundStatus += this.waypoints.length + " waypoints";
}
foundStatus += " found.";
this.setStatus(foundStatus);
this._listTracks(this.tracks);
this._listWayPoints(this.waypoints);
if(!this.showReadResultsSelectOnLoad) {
if(this.tracks.length > 0 && this.options.showReadTracksSelect) {
Element.show(this.readTracksElement);
}
if(this.waypoints.length > 0 && this.options.showReadWaypointsSelect) {
Element.show(this.readWaypointsElement);
}
}
}
if (this.options.afterFinishReadFromDevice) {
this.options.afterFinishReadFromDevice(json.controller.gpsDataString, gpsData, json.controller.gpsDataType);
}
},
_listTracks: function(tracks) {
if(this.options.showReadTracksSelect) {
var tracksDrawable = 0;
this._clearHtmlSelect(this.readTracksSelect);
for( var i=0; i < tracks.length; i++ ) {
var trk = tracks[i];
if(this.options.loadTracksWithoutATimestamp || trk.isDrawable()) {
var trackName = (trk.getStartDate() != null) ? trk.getStartDate().getDateString() + " (Duration: " + trk.getDuration() + ")" : "Track "+(i+1);
this.readTracksSelect.options[i] = new Option(trackName, i);
tracksDrawable++;
}
}
if(tracksDrawable > 0) {
if (this.readTracksSelect.selectedIndex == -1) {
this.readTracksSelect.selectedIndex = 0;
}
this.displayTrack(tracks[this.readTracksSelect.selectedIndex]);
this.readTracksSelect.onchange = function() {
var trk = this.tracks[this.readTracksSelect.selectedIndex];
this.displayTrack(trk);
}.bind(this)
this.readTracksSelect.disabled = false;
} else {
this.readTracksSelect.disabled = true;
}
}
},
_listWayPoints: function(waypoints) {
if(this.options.showReadWaypointsSelect) {
this._clearHtmlSelect(this.readTracksSelect);
this._clearHtmlSelect(this.readWaypointsSelect);
if (waypoints.length > 0) {
for( var i=0; i < waypoints.length; i++ ) {
var wpt = waypoints[i];
this.readWaypointsSelect.options[i] = new Option(wpt.getName(),i);
}
this.readWaypointsSelect.onchange = function() {
var wpt = this.waypoints[this.readWaypointsSelect.selectedIndex];
this.displayWayPoint(wpt);
}.bind(this)
this.readWaypointsSelect.disabled = false;
} else {
this.readWaypointsSelect.disabled = true;
}
}
},
displayTrack: function(track) {
if(this.options.showReadGoogleMap) {
this.readMapController.map.clearOverlays();
this.readMapController.centerAndScale(track.getStartLat(), track.getStartLng());
this.readMapController.drawTrack(track);
}
},
displayWayPoint: function(wpt) {
if(this.options.showReadGoogleMap) {
this.readMapController.map.clearOverlays();
this.readMapController.centerAndScale(wpt.getLat(), wpt.getLng());
this.readMapController.drawWayPoint(wpt);
}
},
getWaypoints: function() {
return this.waypoints;
},
getTracks: function() {
return this.tracks;
},
clearMapDisplay: function() {
if(this.options.showReadGoogleMap) {
this.readMapController.map.clearOverlays();
}
},
setStatus: function(statusText) {
if(this.options.showStatusElement) {
this.statusText.innerHTML = statusText;
}
},
showProgressBar: function() {
if(this.options.showStatusElement && this.options.showProgressBar) {
Element.show(this.progressBar);
}
},
hideProgressBar: function() {
if(this.options.showStatusElement && this.options.showProgressBar) {
Element.hide(this.progressBar);
}
},
updateProgressBar: function(value) {
if(this.options.showStatusElement && this.options.showProgressBar && value) {
var percent = (value <= 100) ? value : 100;
this.progressBarDisplay.style.width = percent + "%";
}
},
onException: function(json) {
this.handleException(json.msg);
},
handleException: function(error) {
if (this.options.customExceptionHandler) {
this.options.customExceptionHandler(error);
} else {
var errorStatus;
var hideFromBrowser = false;
if (error.name == "PluginNotInstalledException" || error.name == "OutOfDatePluginException") {
errorStatus = error.message;
errorStatus += " <a href=\""+Garmin.DeviceDisplay.CONST.pluginDownload+"\" target=\"_blank\">Download</a> and install now.";
} else if(error.name == "BrowserNotSupportedException") {
errorStatus = error.message;
if (this.options.hideIfBrowserNotSupported)
hideFromBrowser = true;
} else {
errorStatus = error.name + ": " + error.message;
}
this.resetUI(errorStatus);
if (!this.options.showStatusElement && !hideFromBrowser) {
if (error.name == "PluginNotInstalledException" || error.name == "OutOfDatePluginException") {
if (window.confirm(error.message+"\nInstall now?")) {
window.open(Garmin.DeviceDisplay.CONST.pluginDownload, "_blank");
}
} else {
alert(errorStatus);
}
}
}
}
};
Garmin.DeviceDisplay.CONST = {
pluginDownload: "http://www.garmin.com/products/communicator/"
};
Garmin.DeviceDisplayDefaultOptions = function(){};
Garmin.DeviceDisplayDefaultOptions.prototype = {
unlockOnPageLoad: true,
pathKeyPairsArray: ["file:///C:/dev/", "bd04dc1f5e97a6ff1ea76c564d133b7e"],
elementClassName: "pluginElement",
useLinks: false,
hideIfBrowserNotSupported: false,
customExceptionHandler: null,
actionButtonClassName: "actionButton",
showStatusElement: true,
statusElementId: "statusBox",
statusTextId: "statusText",
showProgressBar: true,
progressBarId: "progressBar",
progressBarDisplayId: "progressBarDisplay",
showFindDevicesElement: true,
autoFindDevices: false,
showDeviceButtonsOnFound: true,
showDeviceButtonsOnLoad: true,
showFindDevicesButton: true,
findDevicesElementId: "deviceBox",
findDevicesButtonId: "findDevicesButton",
findDevicesButtonText: "Find Devices",
showCancelFindDevicesButton: false,
cancelFindDevicesButtonId: "cancelFindDevicesButton",
cancelFindDevicesButtonText: "Cancel Find Devices",
showDeviceSelectOnSingle: false,
showDeviceSelectNoDevice: false,
showDeviceSelectOnLoad: true,
deviceSelectElementId: "deviceSelectBox",
deviceSelectLabel: "Devices: ",
deviceSelectLabelId: "deviceSelectLabel",
deviceSelectId: "deviceSelect",
noDeviceDetectedStatusText: "No devices found.",
autoReadData: false,
showReadDataElement: true,
readDataElementId: "readBox",
readDataButtonId: "readDataButton",
readDataButtonText: "Get Data",
cancelReadDataButtonId: "cancelReadDataButton",
cancelReadDataButtonText: "Cancel Get Data",
cancelReadStatusText: "Read cancelled",
showReadResultsSelectOnLoad: false,
readResultsSelectClass: "readResultsSelect",
readResultsElementClass: "readResultsElement",
showReadTracksSelect: true,
readTracksElementId: "readTracksElement",
readTracksSelectId: "readTracksSelect",
readTracksSelectLabel: "Tracks: ",
readTracksSelectLabelId: "readTracksSelectLabel",
readWaypointsElementId: "readWaypointsElement",
showReadWaypointsSelect: true,
readWaypointsSelectId: "readWaypointsSelect",
readWaypointsSelectLabel: "Waypoints: ",
readWaypointsSelectLabelId: "readWaypointsSelectLabel",
showReadGoogleMap: false,
readGoogleMapId: "readMap",
showReadDataTypesSelect: false,
readDataTypesSelectId: "readDataTypesSelect",
afterFinishReadFromDevice: null,
loadTracksWithoutATimestamp: true,
autoWriteData: false,
showWriteDataElement: false,
writeDataButtonId: "writeDataButton",
writeDataButtonText: "Write",
cancelWriteDataButtonId: "cancelWriteDataButton",
cancelWriteDataButtonText: "Cancel Write",
afterFinishWriteToDevice: null,
getWriteData: null,
getWriteDataFileName: function(){ return "myData.gpx"; }
};
var DisplayBootstrap = {
require: function(libraryName) {
document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
},
load: function() {
$A(document.getElementsByTagName("script")).findAll(
function(s) { return (s.src && s.src.match(/GarminDeviceDisplay\.js(\?.*)?$/)) }
).each(
function(s) {
var path = s.src.replace(/GarminDeviceDisplay\.js(\?.*)?$/,'')+"../../";
var includes = s.src.match(/\?.*load=([a-z,]*)/);
var dependencies = 'garmin/device/GarminDeviceControl,garmin/device/GarminDevicePlugin,garmin/device/GarminGpsDataStructures,garmin/device/GoogleMapController,garmin/device/GarminDevice,garmin/util/Util-XmlConverter,garmin/util/Util-Broadcaster,garmin/util/Util-DateTimeFormat,garmin/util/Util-BrowserDetect,garmin/util/Util-PluginDetect,garmin/device/GarminObjectGenerator';
(includes ? includes[1] : dependencies).split(',').each(
function(include) { DisplayBootstrap.require(path+include+'.js') }
);
}
);
}
}
DisplayBootstrap.load();
Documentation generated by
JSDoc on Tue May 29 09:15:02 2007