Parcourir la Source

added calorie totals to panels

bmallred 10 ans auparavant
Parent
Commettre
0a4b280da1
1 fichiers modifiés avec 21 ajouts et 2 suppressions
  1. 21 2
      public/js/grassfed.js

+ 21 - 2
public/js/grassfed.js

108
                if ($(panel).find('tr').length == 0) {
108
                if ($(panel).find('tr').length == 0) {
109
                    $(panel).remove();
109
                    $(panel).remove();
110
                }
110
                }
111
112
                updatePanelTotals();
111
            }
113
            }
112
        });
114
        });
113
    });
115
    });
137
        else {
139
        else {
138
            $('div#history').prepend(
140
            $('div#history').prepend(
139
                $('<div class="panel panel-default">')
141
                $('<div class="panel panel-default">')
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>')
142
                    .append('<div class="panel-heading"><h3 class="panel-title"><a data-toggle="collapse" data-parent="#history" href="#' + momentDate.replace(/\s+/g, '-') + '">' + momentDate + '</a><span class="pull-right badge">0</span></h3></div>')
141
                    .append($('<div id="' + momentDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
143
                    .append($('<div id="' + momentDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
142
                        .append($('<div class="panel-body">')
144
                        .append($('<div class="panel-body">')
143
                            .append('<table class="table">'))));
145
                            .append('<table class="table">'))));
154
156
155
        $('.panel.panel-default > .panel-collapse').addClass('collapse').find('.delete-history').hide();
157
        $('.panel.panel-default > .panel-collapse').addClass('collapse').find('.delete-history').hide();
156
        $('.panel.panel-default:first > .panel-collapse').addClass('in').find('.delete-history').show();
158
        $('.panel.panel-default:first > .panel-collapse').addClass('in').find('.delete-history').show();
159
        updatePanelTotals();
157
    }
160
    }
158
161
159
    function getDailyCalories() {
162
    function getDailyCalories() {
235
                                }
238
                                }
236
    
239
    
237
                                panel = $('<div class="panel panel-default">')
240
                                panel = $('<div class="panel panel-default">')
238
                                    .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>')
241
                                    .append('<div class="panel-heading"><h3 class="panel-title"><a data-toggle="collapse" data-parent="#history" href="#' + lastDate.replace(/\s+/g, '-') + '">' + lastDate + '</a><span class="pull-right badge">0</span></h3></div>')
239
                                    .append($('<div id="' + lastDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
242
                                    .append($('<div id="' + lastDate.replace(/\s+/g, '-') + '" class="panel-collapse">')
240
                                        .append($('<div class="panel-body">')
243
                                        .append($('<div class="panel-body">')
241
                                            .append('<table class="table">')));
244
                                            .append('<table class="table">')));
252
255
253
                    $('.panel.panel-default > .panel-collapse').addClass('collapse').find('.delete-history').hide();
256
                    $('.panel.panel-default > .panel-collapse').addClass('collapse').find('.delete-history').hide();
254
                    $('.panel.panel-default:first > .panel-collapse').addClass('in').find('.delete-history').show();
257
                    $('.panel.panel-default:first > .panel-collapse').addClass('in').find('.delete-history').show();
258
                    updatePanelTotals();
255
                }
259
                }
256
            });
260
            });
257
    }
261
    }
348
            doughnutChart.update();
352
            doughnutChart.update();
349
        }
353
        }
350
    }
354
    }
355
356
    function updatePanelTotals() {
357
        var panels = $('.panel');
358
        for (var i = 0; i < panels.length; i++) {
359
            var panel = panels[i];
360
            var total = 0;
361
362
            var calories = $(panel).find('span.calories');
363
            for (var j = 0; j < calories.length; j++) {
364
                total += parseInt($(calories[j]).text());
365
            }
366
367
            $(panel).find('span.badge').text(total);
368
        }
369
    }
351
});
370
});