|
|
|
|
83
|
|
83
|
|
84
|
$(document).on('click', 'button.delete-history', function (e) {
|
84
|
$(document).on('click', 'button.delete-history', function (e) {
|
85
|
e.preventDefault();
|
85
|
e.preventDefault();
|
86
|
var moment = parseInt($(this).parents('div.media').attr('data-moment'));
|
|
|
|
|
86
|
var moment = parseInt($(this).parents('tr').attr('data-moment'));
|
87
|
|
87
|
|
88
|
$.ajax({
|
88
|
$.ajax({
|
89
|
url: '/me/history/' + moment,
|
89
|
url: '/me/history/' + moment,
|
|
|
|
|
91
|
})
|
91
|
})
|
92
|
.done(function (response) {
|
92
|
.done(function (response) {
|
93
|
if (response) {
|
93
|
if (response) {
|
94
|
var media = $('div.media[data-moment="' + moment + '"]');
|
|
|
|
|
94
|
var media = $('tr[data-moment="' + moment + '"]');
|
95
|
var panel = $(media).parents('div.panel');
|
95
|
var panel = $(media).parents('div.panel');
|
96
|
var previousCalories = parseInt($('input[name="current"][type="hidden"]').val());
|
96
|
var previousCalories = parseInt($('input[name="current"][type="hidden"]').val());
|
97
|
var calories = parseInt($(media).find('span.calories').text());
|
97
|
var calories = parseInt($(media).find('span.calories').text());
|
|
|
|
|
105
|
loadTrends();
|
105
|
loadTrends();
|
106
|
|
106
|
|
107
|
// Check if there are any more media elements in the panel. If not remove the panel.
|
107
|
// Check if there are any more media elements in the panel. If not remove the panel.
|
108
|
if ($(panel).find('div.media').length == 0) {
|
|
|
|
|
108
|
if ($(panel).find('tr').length == 0) {
|
109
|
$(panel).remove();
|
109
|
$(panel).remove();
|
110
|
}
|
110
|
}
|
111
|
}
|
111
|
}
|
|
|
|
|
137
|
else {
|
137
|
else {
|
138
|
$('div#history').prepend(
|
138
|
$('div#history').prepend(
|
139
|
$('<div class="panel panel-default">')
|
139
|
$('<div class="panel panel-default">')
|
140
|
.append('<div class="panel-heading"><h3 class="panel-title">' + momentDate + '</h3></div>')
|
|
|
141
|
.append('<div class="panel-body">'));
|
|
|
|
|
140
|
.append('<div class="panel-heading"><h3 class="panel-title"><a data-toggle="collapse" data-parent="#history" href="#' + momentDate.replace(/\s+/g, '-') + '">' + momentDate + '</a></h3></div>')
|
|
|
141
|
.append($('<div id="' + momentDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
|
|
|
142
|
.append($('<div class="panel-body">')
|
|
|
143
|
.append('<table class="class">'))));
|
142
|
|
144
|
|
143
|
panelBody = $('h3.panel-title:contains("' + momentDate + '")').parents('div.panel').find('div.panel-body');
|
145
|
panelBody = $('h3.panel-title:contains("' + momentDate + '")').parents('div.panel').find('div.panel-body');
|
144
|
}
|
146
|
}
|
145
|
|
147
|
|
146
|
$(panelBody).prepend(
|
148
|
$(panelBody).prepend(
|
147
|
$('<div class="media" data-moment="' + id + '">')
|
|
|
148
|
.append('<div class="media-object pull-right"><button class="btn btn-danger delete-history"><span class="glyphicon glyphicon-fire"></span></button></div>')
|
|
|
149
|
.append('<div class="media-body">')
|
|
|
150
|
.append('<h4 class="media-heading">' + product + ' (<span class="calories">' + calories + '</span> calories)</h4>'));
|
|
|
|
|
149
|
$('<tr data-moment="' + id + '">')
|
|
|
150
|
.append(
|
|
|
151
|
'<td>' + product + '</td>'
|
|
|
152
|
+ '<td class="text-right" style="width: 4em;"><span class="calories">' + calories + '</span></td>'
|
|
|
153
|
+ '<td class="text-center" style="width: 6em;"><button class="btn btn-danger delete-history"><span class="glyphicon glyphicon-fire"></span></button></td>'));
|
151
|
}
|
154
|
}
|
152
|
|
155
|
|
153
|
function getDailyCalories() {
|
156
|
function getDailyCalories() {
|
|
|
|
|
212
|
for (var i = 0; i < response.length; i++) {
|
215
|
for (var i = 0; i < response.length; i++) {
|
213
|
if (response[i]) {
|
216
|
if (response[i]) {
|
214
|
var momentDate = new Date(response[i].Date).toDateString();
|
217
|
var momentDate = new Date(response[i].Date).toDateString();
|
215
|
var moment = $('<div class="media" data-moment="' + response[i].Id + '">')
|
|
|
216
|
.append('<div class="media-object pull-right"><button class="btn btn-danger delete-history"><span class="glyphicon glyphicon-fire"></span></button></div>')
|
|
|
217
|
.append('<div class="media-body">')
|
|
|
218
|
.append('<h4 class="media-heading">' + response[i].Product + ' (<span class="calories">' + response[i].Calories + '</span> calories)</h4>');
|
|
|
|
|
218
|
var moment = $('<tr data-moment="' + response[i].Id + '">')
|
|
|
219
|
.append(
|
|
|
220
|
'<td>' + response[i].Product + '</td>'
|
|
|
221
|
+ '<td class="text-right" style="width: 4em;"><span class="calories">' + response[i].Calories + '</span></td>'
|
|
|
222
|
+ '<td class="text-center" style="width: 6em;"><button class="btn btn-danger delete-history"><span class="glyphicon glyphicon-fire"></span></button></td>');
|
219
|
|
223
|
|
220
|
if (!lastDate || lastDate != momentDate) {
|
224
|
if (!lastDate || lastDate != momentDate) {
|
221
|
lastDate = momentDate;
|
225
|
lastDate = momentDate;
|
222
|
|
226
|
|
223
|
if (panel) {
|
227
|
if (panel) {
|
224
|
$(panel).find('div.panel-body').append(moments);
|
|
|
|
|
228
|
$(panel).find('.table').append(moments);
|
225
|
$(history).append(panel);
|
229
|
$(history).append(panel);
|
226
|
moments = [];
|
230
|
moments = [];
|
227
|
panel = null;
|
231
|
panel = null;
|
228
|
}
|
232
|
}
|
229
|
|
233
|
|
230
|
panel = $('<div class="panel panel-default">')
|
234
|
panel = $('<div class="panel panel-default">')
|
231
|
.append('<div class="panel-heading"><h3 class="panel-title">' + lastDate + '</h3></div>')
|
|
|
232
|
.append('<div class="panel-body">');
|
|
|
|
|
235
|
.append('<div class="panel-heading"><h3 class="panel-title"><a data-toggle="collapse" data-parent="#history" href="#' + lastDate.replace(/\s+/g, '-') + '">' + lastDate + '</a></h3></div>')
|
|
|
236
|
.append($('<div id="' + lastDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
|
|
|
237
|
.append($('<div class="panel-body">')
|
|
|
238
|
.append('<table class="table">')));
|
233
|
}
|
239
|
}
|
234
|
|
240
|
|
235
|
moments.push(moment);
|
241
|
moments.push(moment);
|
|
|
|
|
240
|
$(panel).find('div.panel-body').append(moments);
|
246
|
$(panel).find('div.panel-body').append(moments);
|
241
|
$(history).append(panel);
|
247
|
$(history).append(panel);
|
242
|
}
|
248
|
}
|
|
|
249
|
|
|
|
250
|
$('.panel.panel-default > .panel-collapse').addClass('collapse');
|
|
|
251
|
$('.panel.panel-default:first > .panel-collapse').addClass('in');
|
243
|
}
|
252
|
}
|
244
|
});
|
253
|
});
|
245
|
}
|
254
|
}
|