Skip to content

Instantly share code, notes, and snippets.

@dmozzy
Created April 16, 2012 12:50
Show Gist options
  • Save dmozzy/2398589 to your computer and use it in GitHub Desktop.
Save dmozzy/2398589 to your computer and use it in GitHub Desktop.
Task List javascript
function getTasks() {
$.mobile.showPageLoadingMsg("a", "Loading Tasks", false);
$.getJSON( '/tasks',
function(data) {
$('#tasks-list').empty();
navigator.geolocation.getCurrentPosition(function(position) {
$.each( data.tasks, function(i, task) {
var distance = calcDistance(position.coords.latitude, position.coords.longitude, task.taskLat, task.taskLng)/1000.0;
distance = distance.toFixed(1);
$('<div><a href="#" data-role="button" id="task-' + task.taskId +'">' + distance + " kms:" + task.taskName + '</a></div>').appendTo($('#tasks-list'));
$('#task-' + task.taskId).click(function(){
$("form[name='task-edit-form'] input[name='taskId']").val(task.taskId);
$("form[name='task-edit-form'] input[name='taskName']").val(task.taskName);
$("form[name='task-edit-form'] input[name='taskLocationId']").val(task.taskLocationId);
$.mobile.changePage($("#task-edit-page"), { transition: "pop", role: "dialog", reverse: false } );
});
});
$('#tasks-list').trigger( 'create' );
$.mobile.hidePageLoadingMsg();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment