Remove custom frontend datetime handlers

This commit is contained in:
Christopher C. Wells 2022-08-14 10:37:02 -07:00 committed by Christopher C. Wells
parent 6176e678b3
commit 353533a6ef
35 changed files with 131 additions and 1981 deletions

View File

@ -1,9 +1,6 @@
if (typeof jQuery === 'undefined') {
throw new Error('Baby Buddy requires jQuery.')
}
if (typeof moment === 'undefined') {
throw new Error('Baby Buddy requires moment.js.')
}
/**
* Baby Buddy Namespace
@ -16,57 +13,6 @@ var BabyBuddy = function () {
return {};
}();
/**
* Datetime Picker.
*
* Provides modifications and defaults for the base datetime picker widget.
*
* @type {{init: BabyBuddy.DatetimePicker.init}}
*/
BabyBuddy.DatetimePicker = function (moment) {
return {
init: function (element, options) {
let defaultOptions = {
display: {
buttons: {
close: true,
today: true,
},
components: {
calendar: true,
clock: true,
date: true,
decades: true,
hours: true,
minutes: true,
month: true,
seconds: false,
useTwentyfourHour: false,
year: true,
},
icons: {
clear: 'icon-delete',
close: 'icon-cancel',
date: 'icon-calendar',
down: 'icon-arrow-down',
next: 'icon-angle-circled-right',
previous: 'icon-angle-circled-left',
time: 'icon-clock',
today: 'icon-today',
up: 'icon-arrow-up',
},
viewMode: 'clock',
},
localization: {
locale: moment.locale(),
},
};
new tempusDominus.TempusDominus(element, Object.assign(defaultOptions, options));
}
};
}(moment);
/**
* Pull to refresh.
*

View File

@ -1,7 +1,5 @@
@import 'variables';
@import '../../../node_modules/bootstrap/scss/bootstrap';
@import '../../../node_modules/@eonasdan/tempus-dominus/src/scss/variables';
@import '../../../node_modules/@eonasdan/tempus-dominus/src/scss/tempus-dominus';
@import '../../../**/static_src/scss/*';
@import '../fontello/css/babybuddy';

View File

@ -20,40 +20,6 @@
pointer-events: none;
}
.bootstrap-datetimepicker-widget {
// Set default text color for datetime picker.
color: $gray-400;
// Ensure widget appears above other elements (e.g. .submit-primary).
z-index: 1050;
}
// Datetime picker input styles.
.input-group {
&.datetimepicker {
// Make calendar icon large and use the primary theme color.
.input-group-text {
background: none;
border: 0;
color: map.get($theme-colors, 'primary');
padding-left: 0;
padding-right: 0;
}
// Style readonly input to look less like an input element.
.datetimepicker-input {
&[readonly] {
background: none;
border: 0;
color: $white;
cursor: pointer;
font-weight: bold;
}
}
}
}
// Use a full width, fixed button on smaller screens.
.submit-primary {
display: block;

View File

@ -42,8 +42,6 @@
{% block page %}{% endblock %}
<script src="{% static "babybuddy/js/vendor.js" %}"></script>
<script>moment.locale('{{ LOCALE }}');</script>
<script>moment.tz.setDefault('{{ TIMEZONE }}');</script>
<script src="{% static "babybuddy/js/app.js" %}"></script>
{% if user.is_authenticated %}
<script>BabyBuddy.PullToRefresh.init()</script>

View File

@ -14,20 +14,6 @@
<label for="id_{{ field.name }}" class="btn btn-outline-light btn-no-hover{% if field.value %} active{% endif %}">
{{ field.label }}
</label>
{% elif field|field_type == "datetimefield" or field|field_type == "datefield" %}
<div class="input-group input-group-lg datetimepicker"
id="datetimepicker_{{ field.name }}"
data-td-target-input="nearest"
data-td-target-toggle="nearest">
<span class="input-group-text px-2 rounded-start bg-dark"
data-td-target="#datetimepicker_{{ field.name }}"
data-td-toggle="datetimepicker"><i class="icon-calendar"></i></span>
{% if field.errors %}
{{ field|add_class:"datetimepicker-input form-control form-control-lg is-invalid" }}
{% else %}
{{ field|add_class:"datetimepicker-input form-control form-control-lg" }}
{% endif %}
</div>
{% elif 'choice' in field|field_type %}
{% if field.errors %}
{{ field|add_class:"form-select is-invalid" }}

View File

@ -8,7 +8,7 @@ from django.utils.translation import gettext as _
from taggit.forms import TagField
from core import models
from core.widgets import TagsEditor, ChildRadioSelect
from core.widgets import TagsEditor, ChildRadioSelect, DateTimeInput
def set_initial_values(kwargs, form_type):
@ -97,12 +97,7 @@ class ChildForm(forms.ModelForm):
if settings.BABY_BUDDY["ALLOW_UPLOADS"]:
fields.append("picture")
widgets = {
"birth_date": forms.DateInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_date",
}
),
"birth_date": DateTimeInput(),
}
@ -144,12 +139,7 @@ class PumpingForm(CoreModelForm, TaggableModelForm):
fields = ["child", "amount", "time", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"time": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_time",
}
),
"time": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -160,12 +150,7 @@ class DiaperChangeForm(CoreModelForm, TaggableModelForm):
fields = ["child", "time", "wet", "solid", "color", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect(),
"time": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_time",
}
),
"time": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -176,18 +161,8 @@ class FeedingForm(CoreModelForm, TaggableModelForm):
fields = ["child", "start", "end", "type", "method", "amount", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_start",
}
),
"end": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_end",
}
),
"start": DateTimeInput(),
"end": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -198,12 +173,7 @@ class NoteForm(CoreModelForm, TaggableModelForm):
fields = ["child", "note", "time", "tags"]
widgets = {
"child": ChildRadioSelect,
"time": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_time",
}
),
"time": DateTimeInput(),
}
@ -213,18 +183,8 @@ class SleepForm(CoreModelForm, TaggableModelForm):
fields = ["child", "start", "end", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_start",
}
),
"end": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_end",
}
),
"start": DateTimeInput(),
"end": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -235,12 +195,7 @@ class TemperatureForm(CoreModelForm, TaggableModelForm):
fields = ["child", "temperature", "time", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"time": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_time",
}
),
"time": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -251,12 +206,7 @@ class TimerForm(CoreModelForm):
fields = ["child", "name", "start"]
widgets = {
"child": ChildRadioSelect,
"start": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_start",
}
),
"start": DateTimeInput(),
}
def __init__(self, *args, **kwargs):
@ -276,18 +226,8 @@ class TummyTimeForm(CoreModelForm, TaggableModelForm):
fields = ["child", "start", "end", "milestone", "tags"]
widgets = {
"child": ChildRadioSelect,
"start": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_start",
}
),
"end": forms.DateTimeInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_end",
}
),
"start": DateTimeInput(),
"end": DateTimeInput(),
}
@ -297,12 +237,7 @@ class WeightForm(CoreModelForm, TaggableModelForm):
fields = ["child", "weight", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": forms.DateInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_date",
}
),
"date": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -313,12 +248,7 @@ class HeightForm(CoreModelForm, TaggableModelForm):
fields = ["child", "height", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": forms.DateInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_date",
}
),
"date": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -329,12 +259,7 @@ class HeadCircumferenceForm(CoreModelForm, TaggableModelForm):
fields = ["child", "head_circumference", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": forms.DateInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_date",
}
),
"date": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}
@ -345,12 +270,7 @@ class BMIForm(CoreModelForm, TaggableModelForm):
fields = ["child", "bmi", "date", "notes", "tags"]
widgets = {
"child": ChildRadioSelect,
"date": forms.DateInput(
attrs={
"autocomplete": "off",
"data-td-target": "#datetimepicker_date",
}
),
"date": DateTimeInput(),
"notes": forms.Textarea(attrs={"rows": 5}),
}

View File

@ -10,7 +10,7 @@ BabyBuddy.Timer = function ($) {
var runIntervalId = null;
var timerId = null;
var timerElement = null;
var lastUpdate = moment();
var lastUpdate = new Date();
var hidden = null;
var Timer = {
@ -18,14 +18,14 @@ BabyBuddy.Timer = function ($) {
timerId = timer_id;
timerElement = $('#' + element_id);
if (timerElement.length == 0) {
if (timerElement.length === 0) {
console.error('BBTimer: Timer element not found.');
return false;
}
if (timerElement.find('.timer-seconds').length == 0
|| timerElement.find('.timer-minutes').length == 0
|| timerElement.find('.timer-hours').length == 0) {
if (timerElement.find('.timer-seconds').length === 0
|| timerElement.find('.timer-minutes').length === 0
|| timerElement.find('.timer-hours').length === 0) {
console.error('BBTimer: Element does not contain expected children.');
return false;
}
@ -48,7 +48,7 @@ BabyBuddy.Timer = function ($) {
},
handleVisibilityChange: function() {
if (!document[hidden] && moment().diff(lastUpdate) > 10000) {
if (!document[hidden] && (new Date()) - lastUpdate > 1) {
Timer.update();
}
},
@ -83,11 +83,16 @@ BabyBuddy.Timer = function ($) {
$.get('/api/timers/' + timerId + '/', function(data) {
if (data && 'duration' in data) {
clearInterval(runIntervalId);
var duration = moment.duration(data.duration);
timerElement.find('.timer-hours').text(duration.hours());
timerElement.find('.timer-minutes').text(duration.minutes());
timerElement.find('.timer-seconds').text(duration.seconds());
lastUpdate = moment();
var duration = data.duration.split(/[\s:.]/)
if (duration.length === 5) {
duration[0] = parseInt(duration[0]) * 24 + parseInt(duration[1]);
duration[1] = duration[2];
duration[2] = duration[3];
}
timerElement.find('.timer-hours').text(parseInt(duration[0]));
timerElement.find('.timer-minutes').text(parseInt(duration[1]));
timerElement.find('.timer-seconds').text(parseInt(duration[2]));
lastUpdate = new Date()
if (data['active']) {
runIntervalId = setInterval(Timer.tick, 1000);

View File

@ -28,17 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.querySelector('#datetimepicker_date'), {
display: {
components: {
hours: false,
minutes: false,
seconds: false,
}
}
});
</script>
{% endblock %}

View File

@ -29,18 +29,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.querySelector('#datetimepicker_birth_date'), {
display: {
components: {
hours: false,
minutes: false,
seconds: false,
},
viewMode: 'years'
}
});
</script>
{% endblock %}

View File

@ -28,9 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_time'));
</script>
{% endblock %}

View File

@ -28,22 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_start'));
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_end'));
$('#id_type').change(function() {
var feed_type=$('#id_type').val();
if (feed_type === 'formula' || feed_type === 'fortified breast milk') {
$('#id_method').val('bottle');
}
});
$('#id_method').change(function() {
var method = $('#id_method').val();
if (['left breast', 'right breast', 'both breasts'].includes(method)) {
$('#id_type').val('breast milk');
}
});
</script>
{% endblock %}

View File

@ -28,17 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.querySelector('#datetimepicker_date'), {
display: {
components: {
hours: false,
minutes: false,
seconds: false,
}
}
});
</script>
{% endblock %}

View File

@ -28,17 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.querySelector('#datetimepicker_date'), {
display: {
components: {
hours: false,
minutes: false,
seconds: false,
}
}
});
</script>
{% endblock %}

View File

@ -28,9 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('#datetimepicker_time'));
</script>
{% endblock %}

View File

@ -28,9 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_time'));
</script>
{% endblock %}

View File

@ -28,10 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_start'));
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_end'));
</script>
{% endblock %}

View File

@ -28,9 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_time'));
</script>
{% endblock %}

View File

@ -23,9 +23,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_start'));
</script>
{% endblock %}

View File

@ -28,10 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_start'));
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_end'));
</script>
{% endblock %}

View File

@ -28,17 +28,3 @@
{% endif %}
{% include 'babybuddy/form.html' %}
{% endblock %}
{% block javascript %}
<script type="text/javascript">
BabyBuddy.DatetimePicker.init(document.getElementById('datetimepicker_date'), {
display: {
components: {
hours: false,
minutes: false,
seconds: false,
}
}
});
</script>
{% endblock %}

View File

@ -7,40 +7,6 @@ from django.utils.translation import gettext_lazy as _
register = template.Library()
@register.simple_tag(takes_context=True)
def datetimepicker_format(context, format_string="L LT"):
"""
Return a datetime format string for momentjs, with support for 24 hour time
override setting.
:param context: caller context data
:param format_string: the default format string (locale based)
:return: the format string to use, as 24 hour time if configured.
"""
try:
user = context["request"].user
if hasattr(user, "settings") and user.settings.language:
language = user.settings.language
else:
language = settings.LANGUAGE_CODE
except KeyError:
language = None
if settings.USE_24_HOUR_TIME_FORMAT:
if format_string == "L LT":
format_string = "L HH:mm"
elif format_string == "L LTS":
format_string = "L HH:mm:ss"
elif language and language == "en-GB":
# Force 12-hour format if 24 hour format is not configured for en-GB
# (Django default is 12H, momentjs default is 24H).
if format_string == "L LT":
format_string = "L h:mm a"
elif format_string == "L LTS":
format_string = "L h:mm:ss a"
return format_string
@register.filter()
def datetime_short(date):
"""

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, Optional
from django.forms import Widget, RadioSelect
from django.forms import Widget, RadioSelect, DateTimeInput as DateTimeInputBase
from django.utils import timezone
from . import models
@ -103,3 +104,10 @@ class ChildRadioSelect(RadioSelect):
if value != "":
option["picture"] = value.instance.picture
return option
class DateTimeInput(DateTimeInputBase):
input_type = "datetime-local"
def format_value(self, value):
return value.isoformat()

View File

@ -40,15 +40,6 @@ the language. If it does:
2. Build, collect, and commit the `/static` folder (see [`gulp updatestatic`](gulp-command-reference.md#updatestatic)).
1. Check if Moment offers a translation (in `node_modules/moment/locale/`) for
the language. If it does:
1. Add the Moment translation file path to [`gulpfile.config.js`](https://github.com/babybuddy/babybuddy/tree/master/gulpfile.config.js)
in `scriptsConfig.vendor`.
2. Build, collect, and commit the `/static` folder (see
[`gulp updatestatic`](gulp-command-reference.md#updatestatic)).
1. Run the development server, log in, and update the user language to test the
newly translated strings.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

1
static/babybuddy/js/app.124d3a444540.js generated Normal file
View File

@ -0,0 +1 @@
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,d=new Date,r=null,o={run:function(d,u){return t=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?r="hidden":void 0!==document.msHidden?r="msHidden":void 0!==document.webkitHidden&&(r="webkitHidden"),void window.addEventListener("focus",o.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[r]&&new Date-d>1&&o.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);var r=i.find(".timer-hours"),o=Number(r.text());r.text(o+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=new Date,e.active?n=setInterval(o.tick,1e3):i.addClass("timer-stopped")}})}};return o}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,d){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);

BIN
static/babybuddy/js/app.124d3a444540.js.gz generated Normal file

Binary file not shown.

View File

@ -1 +0,0 @@
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");if("undefined"==typeof moment)throw new Error("Baby Buddy requires moment.js.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.DatetimePicker=function(e){return{init:function(n,t){let i={display:{buttons:{close:!0,today:!0},components:{calendar:!0,clock:!0,date:!0,decades:!0,hours:!0,minutes:!0,month:!0,seconds:!1,useTwentyfourHour:!1,year:!0},icons:{clear:"icon-delete",close:"icon-cancel",date:"icon-calendar",down:"icon-arrow-down",next:"icon-angle-circled-right",previous:"icon-angle-circled-left",time:"icon-clock",today:"icon-today",up:"icon-arrow-up"},viewMode:"clock"},localization:{locale:e.locale()}};new tempusDominus.TempusDominus(n,Object.assign(i,t))}}}(moment),BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,o=moment(),d=null,r={run:function(o,u){return t=o,0==(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0==i.find(".timer-seconds").length||0==i.find(".timer-minutes").length||0==i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?d="hidden":void 0!==document.msHidden?d="msHidden":void 0!==document.webkitHidden&&(d="webkitHidden"),void window.addEventListener("focus",r.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[d]&&moment().diff(o)>1e4&&r.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),o=Number(t.text());if(o<59)t.text(o+1);else{t.text(0);var d=i.find(".timer-hours"),r=Number(d.text());d.text(r+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=moment.duration(e.duration);i.find(".timer-hours").text(t.hours()),i.find(".timer-minutes").text(t.minutes()),i.find(".timer-seconds").text(t.seconds()),o=moment(),e.active?n=setInterval(r.tick,1e3):i.addClass("timer-stopped")}})}};return r}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,o){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?o&&setInterval(this.update,o):(window.addEventListener("focus",t.handleVisibilityChange,!1),o&&setInterval(t.handleVisibilityChange,o))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);

Binary file not shown.

View File

@ -1 +1 @@
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");if("undefined"==typeof moment)throw new Error("Baby Buddy requires moment.js.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.DatetimePicker=function(e){return{init:function(n,t){let i={display:{buttons:{close:!0,today:!0},components:{calendar:!0,clock:!0,date:!0,decades:!0,hours:!0,minutes:!0,month:!0,seconds:!1,useTwentyfourHour:!1,year:!0},icons:{clear:"icon-delete",close:"icon-cancel",date:"icon-calendar",down:"icon-arrow-down",next:"icon-angle-circled-right",previous:"icon-angle-circled-left",time:"icon-clock",today:"icon-today",up:"icon-arrow-up"},viewMode:"clock"},localization:{locale:e.locale()}};new tempusDominus.TempusDominus(n,Object.assign(i,t))}}}(moment),BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,o=moment(),d=null,r={run:function(o,u){return t=o,0==(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0==i.find(".timer-seconds").length||0==i.find(".timer-minutes").length||0==i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?d="hidden":void 0!==document.msHidden?d="msHidden":void 0!==document.webkitHidden&&(d="webkitHidden"),void window.addEventListener("focus",r.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[d]&&moment().diff(o)>1e4&&r.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),o=Number(t.text());if(o<59)t.text(o+1);else{t.text(0);var d=i.find(".timer-hours"),r=Number(d.text());d.text(r+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=moment.duration(e.duration);i.find(".timer-hours").text(t.hours()),i.find(".timer-minutes").text(t.minutes()),i.find(".timer-seconds").text(t.seconds()),o=moment(),e.active?n=setInterval(r.tick,1e3):i.addClass("timer-stopped")}})}};return r}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,o){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?o&&setInterval(this.update,o):(window.addEventListener("focus",t.handleVisibilityChange,!1),o&&setInterval(t.handleVisibilityChange,o))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);
if("undefined"==typeof jQuery)throw new Error("Baby Buddy requires jQuery.");var BabyBuddy={};function preventDoubleSubmit(){return!1}BabyBuddy.PullToRefresh=function(e){return{init:function(){e.init({mainElement:"body",onRefresh:this.onRefresh})},onRefresh:function(){window.location.reload()}}}(PullToRefresh),$("form").off("submit",preventDoubleSubmit),$("form").on("submit",function(){$(this).on("submit",preventDoubleSubmit)}),BabyBuddy.Timer=function(e){var n=null,t=null,i=null,d=new Date,r=null,o={run:function(d,u){return t=d,0===(i=e("#"+u)).length?(console.error("BBTimer: Timer element not found."),!1):0===i.find(".timer-seconds").length||0===i.find(".timer-minutes").length||0===i.find(".timer-hours").length?(console.error("BBTimer: Element does not contain expected children."),!1):(n=setInterval(this.tick,1e3),void 0!==document.hidden?r="hidden":void 0!==document.msHidden?r="msHidden":void 0!==document.webkitHidden&&(r="webkitHidden"),void window.addEventListener("focus",o.handleVisibilityChange,!1))},handleVisibilityChange:function(){!document[r]&&new Date-d>1&&o.update()},tick:function(){var e=i.find(".timer-seconds"),n=Number(e.text());if(n<59)e.text(n+1);else{e.text(0);var t=i.find(".timer-minutes"),d=Number(t.text());if(d<59)t.text(d+1);else{t.text(0);var r=i.find(".timer-hours"),o=Number(r.text());r.text(o+1)}}},update:function(){e.get("/api/timers/"+t+"/",function(e){if(e&&"duration"in e){clearInterval(n);var t=e.duration.split(/[\s:.]/);5===t.length&&(t[0]=24*parseInt(t[0])+parseInt(t[1]),t[1]=t[2],t[2]=t[3]),i.find(".timer-hours").text(parseInt(t[0])),i.find(".timer-minutes").text(parseInt(t[1])),i.find(".timer-seconds").text(parseInt(t[2])),d=new Date,e.active?n=setInterval(o.tick,1e3):i.addClass("timer-stopped")}})}};return o}(jQuery),BabyBuddy.Dashboard=function(e){var n=null,t={watch:function(i,d){if(0==e("#"+i).length)return console.error("Baby Buddy: Dashboard element not found."),!1;void 0!==document.hidden?n="hidden":void 0!==document.msHidden?n="msHidden":void 0!==document.webkitHidden&&(n="webkitHidden"),void 0===window.addEventListener||void 0===document.hidden?d&&setInterval(this.update,d):(window.addEventListener("focus",t.handleVisibilityChange,!1),d&&setInterval(t.handleVisibilityChange,d))},handleVisibilityChange:function(){document[n]||t.update()},update:function(){location.reload()}};return t}(jQuery);

Binary file not shown.

File diff suppressed because one or more lines are too long