Permalink
Browse files

Catches errors when receiving malformed JSON response on Tips; change…

…d Check-in result window to a scene; added mayorship info and specials info for venue upon checkin; Nearby Venues now sends the GPS's horizontal and vertical accuracy and altitude to Foursquare for more accurate results; GPS will now return a cached position that is at most 30 seconds old otherwise it grabs a new one
  • Loading branch information...
1 parent ea40d55 commit 9a67c21d278b7be301f10760d9ba83a15cc2cd0e @zhephree zhephree committed Dec 19, 2009
@@ -0,0 +1,144 @@
+function CheckinResultAssistant( checkinJSON,i) {
+ this.json=checkinJSON;
+ this.uid=i;
+}
+
+CheckinResultAssistant.prototype.setup = function() {
+ /* this function is for setup tasks that have to happen when the scene is first created */
+
+ /* use Mojo.View.render to render view templates and add them to the scene, if needed. */
+
+ /* setup widgets here */
+ this.controller.setupWidget("okButtonCheckin",
+ this.attributes = {},
+ this.OKButtonModel = {
+ buttonLabel: "Sweet",
+ disabled: false
+ }
+ );
+ Mojo.Event.listen(this.controller.get('okButtonCheckin'), Mojo.Event.tap, this.okTappedCheckin.bindAsEventListener(this));
+
+ /* add event handlers to listen to events from widgets */
+ this.initData(this.json);
+
+}
+
+CheckinResultAssistant.prototype.initData = function(checkinJSON) {
+
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog");
+ //set the title message
+ $('checkin-display').innerHTML = checkinJSON.checkin.message;
+ $('scores-box').innerHTML=" ";
+
+ //set the individual scores - handle changes in JSON response...
+ if(checkinJSON.checkin.scoring != undefined){
+ var scores=checkinJSON.checkin.scoring.score;
+ }else if(checkinJSON.checkin.scores != undefined){
+ var scores=checkinJSON.checkin.scores;
+ }else{
+ var scores=undefined;
+ }
+ if(scores != undefined) {
+ var totalpoints=0;
+ for(var i = 0; i < scores.length; i++) {
+ if (checkinJSON.checkin.scores[i] != undefined) {
+ var imgpath = scores[i].icon;
+ totalpoints+=parseInt(scores[i].points);
+ var msg = '+' + scores[i].points + ' ' +scores[i].message;
+ $('scores-box').innerHTML += '<div class="palm-row single"><div class="checkin-score"><img src="'+imgpath+'" /> <span>'+msg+'</span></div></div>';
+ }
+ }
+ var totalPts = (totalpoints != 1)? totalpoints+' pts': totalpoints+' pt';
+ $('score-title').innerHTML = "Score! That's " + totalPts;
+ }else{
+ this.noscores=true;
+ }
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - scores done");
+
+
+ //badges? we need stinkin' badges!
+ if(checkinJSON.checkin.badges != undefined) {
+ for(var b = 0; b < checkinJSON.checkin.badges.length;b++) {
+ var badge_name=checkinJSON.checkin.badges[b].name;
+ var badge_icon=checkinJSON.checkin.badges[b].icon;
+ var badge_text=checkinJSON.checkin.badges[b].description;
+ $('scores-box').innerHTML += '<div class="palm-row single"><div class="checkin-badge"><img src="'+badge_icon+'" width="32" height="32" /> <span>'+badge_name+': '+badge_text+'</span></div></div>';
+ }
+ }
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - badges done");
+
+
+ //handle mayorship. this is a cheap way to detect it, but it works.... for now
+ if(checkinJSON.checkin.mayor != undefined) {
+ /*var type=checkinJSON.checkin.mayor.type;
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - got a mayor");
+ if(type=="nochange") { //same ol' mayor
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - same mayor");
+
+ if(checkinJSON.checkin.mayor.user== undefined) { //we're the mayor still
+ $('checkin-mayorship').innerHTML = '<div class="palm-row single"><div class="checkin-badge"><span>'+checkinJSON.checkin.mayor.message+'</span></div></div>';
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - same mayor");
+ }
+ }else{ //we're the new mayor!
+ $('checkin-mayorship').innerHTML = '<div class="palm-row single"><div class="checkin-badge"><span>'+checkinJSON.checkin.mayor.message+'</span></div></div>';
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - new mayor");
+ }*/
+ $('checkin-mayorship').innerHTML = '<div class="palm-row single"><div class="checkin-badge"><span>'+checkinJSON.checkin.mayor.message+'</span></div></div>';
+
+ }else{
+ this.nomayor=true;
+ }
+
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - mayor done");
+
+
+ //specials!
+ if(checkinJSON.checkin.specials != undefined) {
+ for(var b = 0; b < checkinJSON.checkin.specials.length;b++) {
+ var special_type=checkinJSON.checkin.specials[b].type;
+ var special_msg=checkinJSON.checkin.specials[b].message;
+ switch(special_type) { //can be 'mayor','count','frequency','other' we're just gonna lump non-mayor specials into one category
+ case "mayor":
+ var spt="Mayor Special";
+ break;
+ default:
+ var spt="Foursquare Special";
+ break;
+ }
+ $('checkin_specials').innerHTML += '<div class="palm-group"><div class="palm-group-title" x-mojo-loc="">'+spt+'</div><div class="palm-list"><div class="listWhiteBox">'+special_msg+'</div></div></div>';
+ }
+ }
+ Mojo.Log.error("^^^^^^^^^^^^checkin dialog - badges done");
+
+
+ //make sure the next stays in the white box!
+ $('scores-box').innerHTML+='<br class="breaker"/>';
+
+
+
+}
+
+CheckinResultAssistant.prototype.okTappedCheckin = function() {
+ Mojo.Log.error("##############trying to close");
+ this.controller.stageController.popScene("checkin-result");
+}
+
+
+
+CheckinResultAssistant.prototype.activate = function(event) {
+ /* put in event handlers here that should only be in effect when this scene is active. For
+ example, key handlers that are observing the document */
+ if(this.noscores) {$("checkin-scores").hide();}
+ if(this.nomayor) {$("mayor-group").hide();}
+}
+
+
+CheckinResultAssistant.prototype.deactivate = function(event) {
+ /* remove any event handlers you added in activate and do any other cleanup that should happen before
+ this scene is popped or another scene is pushed on top */
+}
+
+CheckinResultAssistant.prototype.cleanup = function(event) {
+ /* this function should do any cleanup needed before the scene is destroyed as
+ a result of being popped off the scene stack */
+}
@@ -51,6 +51,7 @@ NearbyTipsAssistant.prototype.setup = function() {
NearbyTipsAssistant.prototype.getTips = function() {
if(_globals.tipsList==undefined) {
+ Mojo.Log.error("lat="+_globals.lat+", long="+_globals.long);
var url = 'http://api.foursquare.com/v1/tips.json';
var request = new Ajax.Request(url, {
method: 'get',
@@ -125,17 +126,25 @@ NearbyTipsAssistant.prototype.getTipsSuccess = function(response) {
Mojo.Log.error("****yay tips="+response.responseText);
if (response.responseJSON == undefined) {
- $('message').innerHTML = 'No Results Found';
+ Mojo.Log.error("****no tips");
+ $("spinnerId").mojo.stop();
+ $("spinnerId").hide();
+
+ $('message').innerHTML = 'There was an error parsing the results from Foursquare. Give it another shot later on.';
+ $('message').show();
}
else {
//Got Results... JSON responses vary based on result set, so I'm doing my best to catch all circumstances
this.tipsList = [];
-
+ Mojo.Log.error("****handling tips");
+
if(response.responseJSON.groups[0] != undefined) { //actually got some tips
+ Mojo.Log.error("****in tips group loop");
for(var g=0;g<response.responseJSON.groups.length;g++) {
var tarray=response.responseJSON.groups[g].tips;
var grouping=response.responseJSON.groups[g].type;
for(var t=0;t<tarray.length;t++) {
+ Mojo.Log.error("****in tips loop");
this.tipsList.push(tarray[t]);
var dist=this.tipsList[this.tipsList.length-1].distance;
var amile=0.000621371192;
@@ -195,7 +195,7 @@ NearbyVenuesAssistant.prototype.onGetNearbyVenues = function(event) {
//get the location
this.controller.serviceRequest('palm://com.palm.location', {
method: "getCurrentPosition",
- parameters: {},
+ parameters: {accuracy: 1, maximumAge:30},
onSuccess: this.gotLocation.bind(this),
onFailure: this.failedLocation.bind(this)
});
@@ -217,9 +217,16 @@ NearbyVenuesAssistant.prototype.gotLocation = function(event) {
//we got the location so now query it against 4square for a venue list
this.lat=event.latitude;
this.long=event.longitude;
+ this.hacc=event.horizAccuracy;
+ this.vacc=event.vertAccuracy;
+ this.altitude=event.altitude;
+ Mojo.Log.error("hacc="+this.hacc+", vacc="+this.vacc+", alt="+this.altitude);
_globals.lat=this.lat;
_globals.long=this.long;
- this.getVenues(event.latitude, event.longitude);
+ _globals.hacc=this.hacc;
+ _globals.vacc=this.vacc;
+ _globals.altitude=this.altitude;
+ this.getVenues(event.latitude, event.longitude,event.horizAccuracy,event.vertAccuracy,event.altitude);
} else {
$('message').innerHTML = "gps error: " + event.errorCode;
Mojo.Log.error("gps error: " + event.errorCode);
@@ -233,7 +240,7 @@ NearbyVenuesAssistant.prototype.failedLocation = function(event) {
Mojo.Controller.getAppController().showBanner("Location services required!", {source: 'notification'});
}
-NearbyVenuesAssistant.prototype.getVenues = function(latitude, longitude) {
+NearbyVenuesAssistant.prototype.getVenues = function(latitude, longitude,hacc,vacc,alt) {
$('message').innerHTML += '<br/>Searching Venues...';
Mojo.Log.error("--------lat="+latitude+", long="+longitude);
@@ -246,7 +253,7 @@ NearbyVenuesAssistant.prototype.getVenues = function(latitude, longitude) {
method: 'get',
evalJSON: 'force',
requestHeaders: {Authorization: auth}, //Not doing a search with auth due to malformed JSON results from it
- parameters: {geolat:latitude, geolong:longitude, r:.5, l:50, q:query},
+ parameters: {geolat:latitude, geolong:longitude, geohacc:hacc,geovacc:vacc, geoalt:alt,r:.5, l:50, q:query},
onSuccess: this.nearbyVenueRequestSuccess.bind(this),
onFailure: this.nearbyVenueRequestFailed.bind(this)
});
@@ -345,12 +345,14 @@ VenuedetailAssistant.prototype.checkInSuccess = function(response) {
var json=response.responseJSON;
Mojo.Log.error("^^^^^^^^^^^^^^^^made it here...");
- checkinDialog.mojo.close();
+ //checkinDialog.mojo.close();
//checkinDialog=null;
- var dialog = this.controller.showDialog({
- template: 'listtemplates/checkin-info',
- assistant: new CheckInDialogAssistant(this, json,this.uid)
- });
+ //var dialog = this.controller.showDialog({
+ // template: 'listtemplates/checkin-info',
+ // assistant: new CheckInDialogAssistant(this, json,this.uid)
+ //});
+ this.controller.stageController.pushScene({name: "checkin-result", transition: Mojo.Transition.crossFade},json,this.uid);
+
}
VenuedetailAssistant.prototype.checkInFailed = function(response) {
@@ -0,0 +1,23 @@
+<div id="checkinresult-main" class="palm-hasheader">
+ <div id='checkin-header'>
+ <span id="checkin-title" class="palm-header center">Check-in Success!</span>
+ </div>
+ <br/><br/>
+ <div id="checkin-display"></div>
+ <div class="palm-group" id="checkin-scores">
+ <div id='score-title' class="palm-group-title" x-mojo-loc=''></div>
+ <div class="palm-list">
+ <div id='scores-box' class='listWhiteBox'>
+ </div>
+ </div>
+ </div>
+ <div class="palm-group unlabeled" id="mayor-group">
+ <div id="checkin-mayorship"></div>
+ </div>
+
+ <div id="checkin_specials">
+ </div>
+
+
+ <div x-mojo-element="Button" id="okButtonCheckin"></div>
+</div>
@@ -19,12 +19,12 @@
<div id="go_button" x-mojo-element="Button"></div>
-->
<br/><br/>
-<div id='message' style='padding: 0 20px;'></div>
<div x-mojo-element="Spinner" id="spinnerId" class="spinnerClass" name="spinnerName"></div>
<div class="palm-group unlabeled" id='resultListBox' style='display:none;'>
<!--<div class="palm-group-title" x-mojo-loc=''>Search Results</div>-->
<div id="results-tips-list" x-mojo-element="List" ></div>
+<div id='message' style='padding: 0 20px;'></div>
</div>
<br/><br/><br/><br/><br/><br/>
Binary file not shown.
@@ -56,5 +56,9 @@
{
"scenes": "leaderboard",
"source": "app/assistants/leaderboard-assistant.js"
+ },
+ {
+ "scenes": "checkin-result",
+ "source": "app/assistants/checkin-result-assistant.js"
}
]

0 comments on commit 9a67c21

Please sign in to comment.