Permalink
Browse files

basic workflow for deferred checkins

  • Loading branch information...
1 parent 2a16652 commit 745140ca4a9e921aa2d1448470333b38372668d6 straup committed Apr 30, 2012
View
@@ -14,6 +14,10 @@ body {
padding: 0;
}
+#deferred {
+ display:none;
+}
+
#message {
border-bottom: solid thin;
margin-bottom: 10px;
@@ -118,6 +122,14 @@ select {
margin-bottom:20px;
}
+input[type=text] {
+ font-size:1.5em;
+ margin-bottom:20px;
+ border:solid thin;
+ width:99%;
+ padding:5px;
+}
+
input[type=submit] {
font-size:1.5em;
margin-bottom:20px;
@@ -1,4 +1,69 @@
-function privatesquare_deferred_store(checkin){
+function privatesquare_deferred_checkin(lat, lon, reason){
+
+ privatesquare_unset_status();
+
+ if (reason === 'offline'){
+ privatesquare_set_status("I've lost the network.");
+ }
+
+ if (reason === 'api error'){
+ privatesquare_set_status("foursquare is sad.");
+ }
+
+ else if (reason){
+ privatesquare_set_status(reason);
+ }
+
+ _privatesquare_show_map(lat, lon);
+
+ var w = $("#deferred_where");
+ w.attr("data-latitude", lat);
+ w.attr("data-longitude", lon);
+
+ $("#deferred_checkin").submit(privatesquare_deferred_checkin_submit);
+ $("#deferred_checkin").show();
+}
+
+function privatesquare_deferred_checkin_submit(){
+
+ var dt = new Date();
+ var ts = parseInt(dt.getTime() / 1000);
+
+ var w = $("#deferred_where");
+
+ var checkin = {
+ 'location': w.val(),
+ 'latitude': w.attr('data-latitude'),
+ 'longitude': w.attr('data-longitude'),
+ 'created': ts
+ };
+
+ privatesquare_deferred_store(checkin, function(){ alert("STORED"); });
+ return false;
+}
+
+function privatesquare_deferred_indicator(){
+
+ var store = new Store("privatesquare");
+ var deferred = store.get("deferred");
+
+ var count = (deferred) ? deferred.length : 0;
+
+ var wrapper = $("#deferred");
+ var indicator = $("#deferred_count");
+
+ if (count){
+ indicator.html(count + " pending");
+ wrapper.show();
+ }
+
+ else {
+ indicator.html("");
+ wrapper.hide();
+ }
+}
+
+function privatesquare_deferred_store(checkin, callback){
var store = new Store("privatesquare");
var deferred = store.get("deferred");
@@ -9,4 +74,10 @@ function privatesquare_deferred_store(checkin){
deferred.push(checkin);
store.set("deferred", deferred);
+
+ privatesquare_deferred_indicator();
+
+ if (callback){
+ callback(checkin);
+ }
}
@@ -86,9 +86,16 @@ function privatesquare_checkin(args, onsuccess){
}
function _privatesquare_geolocation_onsuccess(rsp){
+
var lat = rsp['coords']['latitude'];
var lon = rsp['coords']['longitude'];
- privatesquare_fetch_venues(lat, lon);
+
+ if (window.navigator.onLine){
+ privatesquare_fetch_venues(lat, lon);
+ return;
+ }
+
+ privatesquare_deferred_checkin(lat, lon, 'offline');
}
function privatesquare_search(){
@@ -156,7 +163,24 @@ function _foursquare_venues_onsuccess(rsp){
$("#status").html("");
if (rsp['stat'] != 'ok'){
- _privatesquare_api_error(rsp);
+
+ /*
+ I am unsure how I feel about this; the maybe better alternative
+ is to wrap the lat/lon used to call the API in all the various
+ callbacks... (20120429/straup)
+ */
+
+ var _okay = function(rsp){
+ var lat = rsp['coords']['latitude'];
+ var lon = rsp['coords']['longitude'];
+ privatesquare_deferred_checkin(lat, lon, 'api error');
+ };
+
+ var _not_okay = function(){
+ privatesquare_api_error(rsp);
+ }
+
+ navigator.geolocation.getCurrentPosition(_okay, _not_okay);
return;
}
@@ -0,0 +1,8 @@
+<div id="deferred">
+
+<form method="POST" id="deferred_checkin" style="display:none;">
+ <input type="text" id="deferred_where" placeholder="Where are you?" />
+ <input type="submit" value="THIS WILL HAPPEN" />
+</form>
+
+</div>
View
@@ -31,6 +31,11 @@
{if $cfg.enable_feature_deferred_checkins}
<script type="text/javascript" src="{$cfg.abs_root_url}javascript/privatesquare.deferred.js?version={$version}"></script>
<script type="text/javascript" src="{$cfg.abs_root_url}javascript/store.js?version={$version}"></script>
+ <script type="text/javascript">
+{literal}
+ $(document).ready(privatesquare_deferred_indicator);
+{/literal}
+ </script>
{/if}
{/if}
@@ -71,6 +76,12 @@ var _cfg={literal}{{/literal}
<a href="{$cfg.user|@urls_history_for_user}export/">export</a>
|
</span>
+{if $cfg.enable_feature_deferred_checkins}
+ <span id="deferred">
+ <span id="deferred_count"></span>
+ |
+ </span>
+{/if}
<a href="{$cfg.abs_root_url}signout/">logout</a>
{else}
{if $cfg.enable_feature_signin}
@@ -6,7 +6,10 @@
<div id="status"></div>
<div id="map-wrapper"></div>
-{if 0}<div id="map" class="map" data-hash="false" data-touch="true" data-mousewheel="true" data-provider="toner"></div>{/if}
+
+{if $cfg.enable_feature_deferred_checkins}
+{include file="inc_deferred_checkin.txt"}
+{/if}
<div id="venues" style="display:none;">

0 comments on commit 745140c

Please sign in to comment.