Permalink
Browse files

Basic checkin functionality works

  • Loading branch information...
1 parent 957444b commit 297775dd80c95b55f8f80b7dbc35787365535d06 Amir Nathoo committed Jul 15, 2012
Showing with 174 additions and 28 deletions.
  1. +1 −0 .gitignore
  2. +0 −2 README.md
  3. +36 −0 README.rst
  4. BIN css/images/icons-18-white.png
  5. +0 −3 identity.json
  6. +6 −1 index.html
  7. +29 −13 js/main.js
  8. +79 −4 js/map.js
  9. +23 −5 js/salesforce.js
View
@@ -0,0 +1 @@
+identity.json
View
@@ -1,2 +0,0 @@
-Sales-Square
-============
View
@@ -0,0 +1,36 @@
+Ho to build Sales Square
+========================
+
+Sales Square is built using `Trigger.io <https://trigger.io>`_, here are the steps to build and test this app on a Mac in the iOS emulator.
+
+The steps to test on Windows / Android are similar and you can find more information here on `Getting started with Trigger.io <http://current-docs.trigger.io/getting-started/index.html>`_.
+
+Install the Trigger.io Toolkit
+-------------------------------
+
+1. Install the toolkit from https://trigger.io/forge/toolkit
+2. Start the Toolkit and create an account
+3. Create a new app and note the app directory
+
+Getting the code
+----------------
+
+1. Open a terminal and navigate to your app directory.
+2. Copy your identity.json file away and remove the template contents in the src directory:
+
+ cd src
+ mv identity.json ...
+ rm -rf *
+
+3. Checkout this repository and copy the identity.json file back:
+
+ git clone https://github.com/amirnathoo/Sales-Square .
+ cd ..
+ mv identity.json src/
+
+Running the app
+---------------
+
+1. In the Toolkit, click on the app name to build it. The first time this will take a minute or so, subsequent incremental builds will be very fast.
+
+2. Then click 'iOS' in the Run section of the app page. You'll see the full console output there and the iPhone emulator will start up in a few seconds.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,3 +0,0 @@
-{
- "uuid": "196c7104cafc11e185cd12313d1adcbe"
-}
View
@@ -28,7 +28,12 @@
<div data-role="page" id="three" data-url="three"></div>
- <div data-role="page" id="four" data-url="four"></div>
+ <div data-role="page" id="four" data-url="four">
+
+ <ul data-role="listview">
+
+ </ul>
+ </div>
</div><!-- /page -->
View
@@ -1,7 +1,9 @@
var state = {
token: "",
identity: null,
- opportunities: null
+ opportunities: null,
+ position: null,
+ location: ""
}
forge.tabbar.addButton({
@@ -27,7 +29,6 @@ forge.tabbar.addButton({
});
});
-
/* init */
$('#checkin').live('tap', function() {
if (state.token) {
@@ -38,6 +39,12 @@ $('#checkin').live('tap', function() {
}
});
+$('ul li a').live('tap', function() {
+ salesforce.post(state.identity.display_name + " is at " + state.location + " working on " + $(this).html());
+ map.addCheckin($(this).html(), state.position, state.identity.display_name);
+ location.hash = "#two";
+});
+
$(document).bind('pagechange', function() {
if (map.init) {
map.refreshMap();
@@ -46,34 +53,43 @@ $(document).bind('pagechange', function() {
}
forge.topbar.removeButtons();
- if (location.hash =="#three") {
+
+ if (location.hash == "#three") {
forge.topbar.addButton({
text: "Back",
- position: "left",
- type: "back"
+ position: "left"
+ }, function() {
+ location.hash = "#one";
+ forge.topbar.setTitle('Sales Square');
});
forge.topbar.addButton({
text: "Next",
position: "right"
}, function() {
location.hash = "#four";
- forge.topbar.setTitle('Select Opportunity')
+ forge.topbar.setTitle('Select Opportunity');
});
}
if (location.hash =="#four") {
forge.topbar.addButton({
text: "Back",
- position: "left",
- type: "back"
- });
- forge.topbar.addButton({
- text: "Next",
- position: "right"
+ position: "left"
}, function() {
- location.hash = "#five";
+ location.hash = "#one";
+ forge.topbar.setTitle('Sales Square');
});
+
+ $('ul').listview();
+ $('li').remove();
+ for (opp in state.opportunities) {
+ $('ul').append('<li><a href="#">'+state.opportunities[opp].Name+'</a></li>')
+ }
+
+ $('ul').listview('refresh');
}
});
+
+
View
@@ -1,27 +1,35 @@
var map = {
init: false,
+ checkins: null,
loadMap: function() {
forge.logging.log('Loading map');
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?key=AIzaSyAlFSCee70OJOiD7k-fz8e6ywXVVIkWErU&gt&sensor=true&callback=map.mapReady";
document.body.appendChild(script);
+
+ forge.prefs.get('checkins', function(checkins) {
+ map.checkins = JSON.parse(checkins) || {};
+ })
},
mapReady: function() {
forge.logging.log('Map loaded');
- map.gmap1Ready = true;
+ map.init = true;
map.initMap();
},
initMap: function() {
forge.geolocation.getCurrentPosition(function(position) {
- forge.logging.log('Location set');
+ forge.logging.log('Position set');
+ state.position = position;
+
+ map.getLocation(position.coords);
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude, true);
var myOptions = {
- zoom: 15,
+ zoom: 12,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
@@ -45,12 +53,17 @@ var map = {
zIndex: -1
});
});
+
+ for (ci in map.checkins) {
+ map.addCheckin(map.checkins[ci].opp, map.checkins[ci].position, map.checkins[ci].name);
+ }
});
},
refreshMap: function() {
forge.geolocation.getCurrentPosition(function(position) {
- forge.logging.log('Location set');
+ forge.logging.log('Position set');
+ state.position = position;
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude, true);
@@ -61,6 +74,68 @@ var map = {
map.marker.setPosition(latLng);
map.marker2.setPosition(latLng);
});
+ },
+
+ getLocation: function(coords) {
+ forge.request.ajax({
+ url: "http://maps.googleapis.com/maps/api/geocode/json?latlng="+coords.latitude+","+coords.longitude+"&sensor=true",
+ dataType: "json",
+ success: function(response) {
+ state.location = response.results[0].formatted_address;
+ forge.logging.log('Location set: '+state.location);
+ },
+ error: function(response) {
+ forge.logging.log('ERROR getting location, response:');
+ forge.logging.log(response);
+ }
+ });
+ },
+
+ addCheckin: function(opp, position, name) {
+ forge.logging.log('Adding checkin to map');
+ forge.logging.log('Opportunity: '+opp);
+ forge.logging.log('Position: '+position);
+ forge.logging.log('Name: '+name);
+
+ var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude, true);
+
+ if (map.checkins[name] && map.checkins[name].marker) {
+ map.checkins[name].marker.setPosition(latLng);
+ } else {
+ map.checkins[name] = {};
+ map.checkins[name].marker = new google.maps.Marker({
+ position: latLng,
+ title: name,
+ map: map.gmap2
+ });
+
+ google.maps.event.addListener(map.checkins[name].marker, 'click', function() {
+ if (map.checkins[name].infowindowopen) {
+ map.checkins[name].infowindow.close();
+ } else {
+ map.checkins[name].infowindow.open(map.gmap2, map.checkins[name].marker);
+ }
+ map.checkins[name].infowindowopen = !map.checkins[name].infowindowopen;
+ });
+ }
+
+ map.checkins[name].content = name + " is working on "+opp;
+ map.checkins[name].infowindow = new google.maps.InfoWindow({
+ content: map.checkins[name].content
+ });
+ map.checkins[name].opp = opp;
+ map.checkins[name].position = position;
+ map.checkins[name].name = name;
+
+ var obj = {};
+ for (var ci in map.checkins) {
+ obj[ci] = {};
+ obj[ci].name = map.checkins[ci].name;
+ obj[ci].opp = map.checkins[ci].opp;
+ obj[ci].position = map.checkins[ci].position;
+ }
+
+ forge.prefs.set('checkins', JSON.stringify(obj));
}
}
View
@@ -1,9 +1,6 @@
//TODO Implement refresh token otherwise this will stop working a while after initial oauth
-forge.enableDebug();
-
var salesforce = {
consumer_key: "3MVG9y6x0357HledXTja.viKSYW0gEMrDKbD6pf.AoDYMgQdxNAUAMdC6ra2TdamileUqZWSodRyqTdgJIAZH",
- consumer_secret: "1325734187136715755",
login: function() {
forge.tabs.openWithOptions({
@@ -12,7 +9,7 @@ var salesforce = {
title: "Salesforce Login"
}, function(data) {
state.token = decodeURIComponent(data.url.split('#access_token=')[1].split('&')[0]);
- //forge.prefs.set('token', state.token); TODO: implement refresh token functionlity, for now need to login each time
+ forge.prefs.set('token', state.token);
salesforce.getIdentity(decodeURIComponent(data.url.split('&id=')[1].split('&')[0]));
});
},
@@ -34,7 +31,7 @@ var salesforce = {
data = JSON.parse(data);
}
state.identity = data;
- //forge.prefs.set('token', JSON.stringify(state.identity)); TODO: implement refresh token functionlity, for now need to login each time
+ forge.prefs.set('identity', JSON.stringify(state.identity));
salesforce.getOpportunities();
},
error: function(data) {
@@ -65,6 +62,27 @@ var salesforce = {
forge.logging.log(data);
}
});
+ },
+
+ post: function(msg) {
+ forge.request.ajax({
+ url : state.identity.urls.feeds.replace("{version}", "25.0") + "/news/"+state.identity.user_id+"/feed-items",
+ type: "POST",
+ headers : {
+ 'Authorization' : 'OAuth ' + state.token
+ },
+ data: {
+ "type": "Text",
+ "text": msg
+ },
+ success : function(response) {
+ forge.logging.log('Success posting: '+msg)
+ },
+ error: function(data) {
+ forge.logging.log('ERROR posting');
+ forge.logging.log(data);
+ }
+ });
}
}

0 comments on commit 297775d

Please sign in to comment.