mirror of https://github.com/snachodog/mybuddy.git
Check and update timer active state on update.
This commit is contained in:
parent
97dbf87e5b
commit
8168c74034
|
@ -36,9 +36,7 @@ BabyBuddy.Timer = function ($) {
|
||||||
// phones that lock with the timer page open.
|
// phones that lock with the timer page open.
|
||||||
Visibility.change(function (e, state) {
|
Visibility.change(function (e, state) {
|
||||||
if (state == 'visible' && moment().diff(lastUpdate) > 2000) {
|
if (state == 'visible' && moment().diff(lastUpdate) > 2000) {
|
||||||
clearInterval(runIntervalId);
|
|
||||||
Timer.update();
|
Timer.update();
|
||||||
runIntervalId = setInterval(Timer.tick, 1000);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -72,11 +70,19 @@ BabyBuddy.Timer = function ($) {
|
||||||
update: function() {
|
update: function() {
|
||||||
$.get('/api/timers/' + timerId + '/', function(data) {
|
$.get('/api/timers/' + timerId + '/', function(data) {
|
||||||
if (data && 'duration' in data) {
|
if (data && 'duration' in data) {
|
||||||
|
clearInterval(runIntervalId);
|
||||||
var duration = moment.duration(data.duration);
|
var duration = moment.duration(data.duration);
|
||||||
timerElement.find('.timer-hours').text(duration.hours());
|
timerElement.find('.timer-hours').text(duration.hours());
|
||||||
timerElement.find('.timer-minutes').text(duration.minutes());
|
timerElement.find('.timer-minutes').text(duration.minutes());
|
||||||
timerElement.find('.timer-seconds').text(duration.seconds());
|
timerElement.find('.timer-seconds').text(duration.seconds());
|
||||||
lastUpdate = moment();
|
lastUpdate = moment();
|
||||||
|
|
||||||
|
if (data['active']) {
|
||||||
|
runIntervalId = setInterval(Timer.tick, 1000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timerElement.addClass('timer-stopped');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#view-timer-detail {
|
#timer-status {
|
||||||
#timer-status {
|
font-size: $h1-font-size;
|
||||||
font-size: $h1-font-size;
|
font-weight: $display1-weight;
|
||||||
font-weight: $display1-weight;
|
|
||||||
|
&.timer-stopped {
|
||||||
|
color: theme-color('danger');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="jumbotron text-center{% if not object.active %} text-danger{% endif %}">
|
<div class="jumbotron text-center">
|
||||||
|
|
||||||
<div class="h1" id="timer-status">
|
<div class="h1{% if not object.active %} timer-stopped{% endif %}" id="timer-status">
|
||||||
<span class="timer-hours">{{ object.duration|hours }}</span>h
|
<span class="timer-hours">{{ object.duration|hours }}</span>h
|
||||||
<span class="timer-minutes">{{ object.duration|minutes }}</span>m
|
<span class="timer-minutes">{{ object.duration|minutes }}</span>m
|
||||||
<span class="timer-seconds">{{ object.duration|seconds }}</span>s
|
<span class="timer-seconds">{{ object.duration|seconds }}</span>s
|
||||||
|
|
Loading…
Reference in New Issue