-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
32 lines (32 loc) · 1.15 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function app(info){
console.log(info);
// take all checked entries, match their ID with info, POST to user (using API!)
// This is NOT an efficient algorithm, but it works
var checked_id = [];
$('.entry:checked').each(function(k,v){
checked_id.push(parseInt($(v).attr('id')));
});
$.each(info.entries, function(k,v){
if ($.inArray(v.id, checked_id) != -1){
console.log('Adding entry '+v.id);
var posting_entry = {};
if (v.message) posting_entry.message = v.message;
// Dailymile doesn't let you post entries without a message
else posting_entry.message = 'Imported using Dailymile Entry Importer from '+v.user.display_name;
if (v.geo) {
posting_entry.lat = v.geo.coordinates[1];
posting_entry.long = v.geo.coordinates[0];
}
if (v.workout) posting_entry.workout = v.workout;
// pretty sure every entry has an 'at' time
if (v.at) posting_entry.workout['completed_at'] = v.at;
console.log($.param(posting_entry));
// $.param is great! Screw nodejs's querystring lib, can't handle multidimensional objects
$.ajax({
'url': '/add_entry',
'type': 'POST',
'data': {data :$.param(posting_entry)}
});
}
});
}