1
0
Fork 0
mirror of https://github.com/shouptech/share-a-bike.git synced 2026-02-03 12:29:42 +00:00

new project

This commit is contained in:
mikeshoup@gmail.com 2010-12-17 04:42:46 +00:00
parent bf5e05f267
commit ca7d51c4c7
13 changed files with 324 additions and 0 deletions

View file

@ -0,0 +1,90 @@
function MainAssistant(argFromPusher) {
}
MainAssistant.prototype = {
setup: function() {
Ares.setupSceneAssistant(this);
},
cleanup: function() {
Ares.cleanupSceneAssistant(this);
},
// The find button has been tapped
findButtonTap: function(inSender) {
// Start Spinning
this.showSpinner(true);
// API URL for BCycle
var url = 'http://api.bcycle.com/services/mobile.svc/ListKiosks';
var gpsSuccess = true;
var gpsResult = 0;
var onGpsSuccess = function(result) {
gpsResult = result;
};
var onGpsFailure = function(result) {
gpsSuccess = false;
this.showSpinner(false);
};
// Function for when AJAX request is complete
var onAjaxComplete = function(transport) {
var kiosks = [5];
kiosks[0] = {name: "Name 1", distance: "0.1 mi", address: "100 Fake St", bikes: "0", docks: "1"};
kiosks[1] = {name: "Name 2", distance: "0.2 mi", address: "100 Fake St", bikes: "0", docks: "1"};
kiosks[2] = {name: "Name 3", distance: "0.3 mi", address: "100 Fake St", bikes: "0", docks: "1"};
kiosks[3] = {name: "Name 4", distance: "0.4 mi", address: "100 Fake St", bikes: "0", docks: "1"};
kiosks[4] = {name: "Name 5", distance: "12.2 mi", address: "100 Fake St", bikes: "0", docks: "1"};
// Display Kiosks
this.listModel = {
items: kiosks
};
this.controller.setWidgetModel("kioskList", this.listModel);
// We're done, stop spinning
this.showSpinner(false);
}.bind(this);
var onAjaxFailure = function(transport) {
// There has been a failure, stop spinning
this.showSpinner(false);
};
// Get GPS Coord
this.getGpsCoord(onGpsSuccess, onGpsFailure);
if(gpsSuccess) {
// Place AJAX request
this.ajaxRequest(url, onAjaxComplete, onAjaxFailure);
};
},
// Find GPS Coordinate
getGpsCoord: function(onSuccess, onFailure) {
this.controller.serviceRequest('palm://com.palm.location', {
method:"getCurrentPosition",
parameters:{},
onSuccess: onSuccess,
onFailure: onFailure
});
},
// Perform AJAX request to BCycle API
ajaxRequest: function(url, onComplete, onFailure) {
var kioskRequest = new Ajax.Request(url, {
method: "get",
evalJSON: 'force',
contentType: 'application/x-www-form-urlencoded',
requestHeaders: {
"USER_AGENT": navigator.userAgent
},
onComplete: onComplete,
onFailure: onFailure
});
},
// Function to start/stop spinning
showSpinner: function(show) {
this.controller.get('findButton').mojo[(show ? 'activate' : 'deactivate')]();
},
};

View file

@ -0,0 +1,7 @@
function StageAssistant() {
}
StageAssistant.prototype.setup = function() {
this.controller.pushScene({name: "main", disableSceneScroller: true});
this.controller.setWindowOrientation("free");
};

View file

@ -0,0 +1,54 @@
opus.Gizmo({
name: "main",
dropTarget: true,
ontap: "mainTap",
type: "Palm.Mojo.Panel",
h: "100%",
styles: {
zIndex: 2,
opacity: 1,
bgImage: "images/Sharrow-BG.jpg"
},
chrome: [
{
name: "findButton",
ontap: "findButtonTap",
disabled: undefined,
label: "Find Kiosks",
type: "Palm.Mojo.ActivityButton",
l: 0,
t: 0
},
{
name: "scroller1",
scrollPosition: {
left: 0,
top: 0
},
type: "Palm.Mojo.Scroller",
l: 0,
t: 261,
styles: {
cursor: "move",
overflow: "hidden"
},
controls: [
{
name: "kioskList",
dropTarget: true,
items: [],
useSampleData: false,
title: undefined,
itemHtml: "<div class=\"palm-row\">\n <div class=\"kiosk_left_col\">\n <div class=\"kiosk_name\">#{name}</div>\n <div class=\"kiosk_address\">#{address}</div>\n </div>\n <div class=\"kiosk_right_col\">\n <div class=\"kiosk_distance\">#{distance}</div>\n <div class=\"kiosk_availability\">#{bikes}B #{docks}D</div>\n </div>\n</div>",
swipeToDelete: false,
rowTapHighlight: false,
rowFocusHighlight: false,
type: "Palm.Mojo.List",
l: 0,
t: 0,
h: 100
}
]
}
]
});

View file

@ -0,0 +1,9 @@
{
"id": "com.mikeshoup.share-a-bike",
"version": "0.0.1",
"vendor": "ShoupTech",
"type": "web",
"main": "index.html",
"title": "Share-a-Bike",
"icon": "icon.png"
}

107
trunk/share-a-bike/ares.js Normal file
View file

@ -0,0 +1,107 @@
opus = {
paths: {},
depends: [],
path: {
// match $[anything]/
pattern: /\$([^\/\\]*)(\/)?/g,
// replace macros of the form $pathname with the mapped value of paths.pathname
rewrite: function(inPath) {
var working, result = inPath;
do {
working = false;
result = result.replace(this.pattern, function(macro, name) {
working = true;
var path = opus.paths[name];
return path ? (path.charAt(path.length-1) == "/" ? path : path + "/") : "";
});
} while (working);
return result;
}
},
argify: function(inSearch) {
var args = inSearch.slice(1).split("&");
for (var i=0, a, nv; a=args[i]; i++) {
// convert "name=value" to [name, value]
nv = args[i] = a.split("=");
// and then to name: value
args[nv[0]] = nv.length > 1 ? nv[1] : true;
}
return args;
},
locateScript: function(inName) {
var l = inName.length;
var scripts = document.getElementsByTagName("script");
for(var i=0, s, src; (s=scripts[i]); i++) {
src = s.getAttribute("src") || "";
if(src.slice(-l) == inName) {
return src.slice(0, -l);
}
}
},
/*
depends() does (when evaluated in JS, basically, debug mode):
for dependencies that are packages (no extension [ug?])
- determine name, establish path (paths["opus-Aerie"] = "$opus/library/Aerie")
- load the package dependencies ($opus/library/Aerie/opus-Aerie-depends.js)
for all others:
- load the resources
*/
_depend: function(inPath) {
var tag, path = opus.path.rewrite(inPath);
if (path.slice(-3) == "css") {
// css
tag = '<link href="' + path + '" media="screen" rel="stylesheet" type="text/css" />';
//console.log("(css): " + path);
} else if (path.slice(-2) == "js") {
// js
//console.log("(js): " + path);
} else {
// package
// must encoded like so:
// [folder]/[name of package without extension]
var parts = path.split("/");
var name = parts.pop();
var folder = parts.join("/") + (parts.length ? "/" : "");
opus.paths[name] = folder;
//console.log("make alias: " + name + ": " + folder);
path = folder + name + "-depends.js";
//console.log("(depends): " + path);
}
if (!tag) {
tag = '<script src="' + path + '" type="text/javascript" x-mojo-version="1"></script>';
}
document.write(tag);
},
depends: function(inDepends) {
//console.info("processing dependencies");
var d;
if (d = inDepends.paths) {
for (var n in d) {
opus.paths[n] = d[n];
}
}
if (d = inDepends.nobuild) {
for (i=0; b=d[i]; i++) {
this._depend(b);
}
}
if (d = inDepends.build) {
for (var i=0, b; b=d[i]; i++) {
this._depend(b);
}
}
}
};
(function(){
if (!opus.paths.opus) {
opus.paths.opus = opus.locateScript("bootloader.js");
}
opus.args = opus.argify(location.search);
var app = opus.args.app || (opus.args.debug ? "depends.js" : "app.js");
document.write('<script src="' + app + '" onerror="opus._tryDebug()" type="text/javascript"></script>');
opus._tryDebug = function() {
app = "depends.js";
document.write('<script src="' + app + '" type="text/javascript"></script>');
};
})();

View file

@ -0,0 +1,4 @@
{
"Mojo": "0.1.0 (311)",
"Ares": "1.0.4"
}

View file

@ -0,0 +1,3 @@
{
"logLevel": 99
}

BIN
trunk/share-a-bike/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Share-a-Bike</title>
<link href="stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />
<script src="ares.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,13 @@
[
{
"source": "app\/assistants\/stage-assistant.js"
},
{
"source": "app\/views\/main\/main-chrome.js",
"scenes": "main"
},
{
"source": "app\/assistants\/main-assistant.js",
"scenes": "main"
}
]

View file

@ -0,0 +1,25 @@
.kiosk_left_col {
float: left;
}
.kiosk_right_col {
float: right;
}
.kiosk_name {
font-weight: bold;
font-size: 1em;
}
.kiosk_distance {
font-size: 1em;
}
.kiosk_address {
font-size: 0.8em;
}
.kiosk_availability {
font-size: 0.8em;
font-weight: bold;
text-align: right;
}