2017-10-29 20:01:13 +00:00
|
|
|
/* Baby Buddy Dashboard
|
|
|
|
*
|
|
|
|
* Provides a "watch" function to update the dashboard at one minute intervals
|
|
|
|
* and/or on visibility state changes.
|
|
|
|
*/
|
|
|
|
BabyBuddy.Dashboard = function ($) {
|
|
|
|
var runIntervalId = null;
|
|
|
|
var dashboardElement = null;
|
|
|
|
var lastUpdate = moment();
|
|
|
|
|
|
|
|
var Dashboard = {
|
2017-11-11 22:27:42 +00:00
|
|
|
watch: function(element_id, refresh_rate) {
|
2017-10-29 20:01:13 +00:00
|
|
|
dashboardElement = $('#' + element_id);
|
|
|
|
|
|
|
|
if (dashboardElement.length == 0) {
|
|
|
|
console.error('Baby Buddy: Dashboard element not found.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-11 22:27:42 +00:00
|
|
|
runIntervalId = setInterval(this.update, refresh_rate);
|
2017-10-29 20:01:13 +00:00
|
|
|
|
|
|
|
Visibility.change(function (e, state) {
|
|
|
|
if (state == 'visible' && moment().diff(lastUpdate) > 60000) {
|
|
|
|
Dashboard.update();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
update: function() {
|
|
|
|
// TODO: Someday maybe update in place?
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return Dashboard;
|
|
|
|
}(jQuery);
|