Created
April 16, 2012 12:50
-
-
Save dmozzy/2398589 to your computer and use it in GitHub Desktop.
Task List javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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