Add wrapper for datetime picker widget

This commit is contained in:
Christopher C. Wells 2020-01-27 14:56:37 -08:00
parent 4a81e2c5a9
commit 26b54b114e
16 changed files with 115 additions and 86 deletions

View File

@ -1,12 +1,36 @@
/* Baby Buddy
*
* Default namespace for the Baby Buddy app.
*/
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
*
* Default namespace for the Baby Buddy app.
*/
var BabyBuddy = function () {
var BabyBuddy = {};
return BabyBuddy;
return {};
}();
/**
* Baby Buddy Datetime Picker
*
* Provides modifications and defaults for the base datetime picker widget.
*/
BabyBuddy.DatetimePicker = function ($, moment) {
return {
init: function (element, options) {
var defaultOptions = {
buttons: { showToday: true },
defaultDate: 'now',
format: 'L LT',
ignoreReadonly: true,
locale: moment.locale(),
useCurrent: false
};
element.datetimepicker($.extend(defaultOptions, options));
}
};
}(jQuery, moment);

View File

@ -41,8 +41,8 @@
{% block page %}{% endblock %}
<script src="{% static "babybuddy/js/vendor.js" %}"></script>
<script src="{% static "babybuddy/js/app.js" %}"></script>
<script>moment.locale('{{ LOCALE }}');</script>
<script src="{% static "babybuddy/js/app.js" %}"></script>
{% block javascript %}{% endblock %}
</body>

View File

@ -32,13 +32,10 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_birth_date').datetimepicker({
format: 'L',
locale: '{{ LOCALE }}',
viewMode: 'years',
extraFormats: ['YYYY-MM-DD']
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_birth_date'), {
format: 'L',
viewMode: 'years',
extraFormats: ['YYYY-MM-DD']
});
</script>
{% endblock %}

View File

@ -31,12 +31,6 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_time').datetimepicker({
defaultDate: 'now',
format: 'L LT',
locale: '{{ LOCALE }}'
});
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'));
</script>
{% endblock %}

View File

@ -31,17 +31,9 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_start').datetimepicker({
format: 'L LT',
locale: '{{ LOCALE }}',
useCurrent: false
});
$('#datetimepicker_end').datetimepicker({
defaultDate: 'now',
format: 'L LT',
locale: '{{ LOCALE }}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'));
</script>
{% endblock %}

View File

@ -31,17 +31,9 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_start').datetimepicker({
format: 'L LT',
locale: '{{ LOCALE }}',
useCurrent: false
});
$('#datetimepicker_end').datetimepicker({
defaultDate: 'now',
format: 'L LT',
locale: '{{ LOCALE }}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'));
</script>
{% endblock %}

View File

@ -31,12 +31,6 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_time').datetimepicker({
defaultDate: 'now',
format: 'L LT',
locale: '{{ LOCALE }}'
});
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'));
</script>
{% endblock %}

View File

@ -26,12 +26,8 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_start').datetimepicker({
defaultDate: 'now',
format: 'L LTS',
locale: '{{ LOCALE }}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_time'), {
format: 'L LTS'
});
</script>
{% endblock %}

View File

@ -31,17 +31,12 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_start').datetimepicker({
format: 'L LTS',
locale: '{{ LOCALE }}',
useCurrent: false
});
$('#datetimepicker_end').datetimepicker({
defaultDate: 'now',
format: 'L LTS',
locale: '{{ LOCALE }}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_start'), {
defaultDate: false,
format: 'L LTS'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_end'), {
format: 'L LTS'
});
</script>
{% endblock %}

View File

@ -31,12 +31,9 @@
{% block javascript %}
<script type="text/javascript">
$(function () {
$('#datetimepicker_date').datetimepicker({
defaultDate: 'now',
format: 'L',
locale: '{{ LOCALE }}'
});
BabyBuddy.DatetimePicker.init($('#datetimepicker_date'), {
format: 'L',
extraFormats: ['YYYY-MM-DD']
});
</script>
{% endblock %}

View File

@ -1,16 +1,40 @@
/* Baby Buddy
*
* Default namespace for the Baby Buddy app.
*/
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
*
* Default namespace for the Baby Buddy app.
*/
var BabyBuddy = function () {
var BabyBuddy = {};
return BabyBuddy;
return {};
}();
/**
* Baby Buddy Datetime Picker
*
* Provides modifications and defaults for the base datetime picker widget.
*/
BabyBuddy.DatetimePicker = function ($, moment) {
return {
init: function (element, options) {
var defaultOptions = {
buttons: { showToday: true },
defaultDate: 'now',
format: 'L LT',
ignoreReadonly: true,
locale: moment.locale(),
useCurrent: false
};
element.datetimepicker($.extend(defaultOptions, options));
}
};
}(jQuery, moment);
/* Baby Buddy Timer
*
* Uses a supplied ID to run a timer. The element using the ID must have

View File

@ -1,16 +1,40 @@
/* Baby Buddy
*
* Default namespace for the Baby Buddy app.
*/
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
*
* Default namespace for the Baby Buddy app.
*/
var BabyBuddy = function () {
var BabyBuddy = {};
return BabyBuddy;
return {};
}();
/**
* Baby Buddy Datetime Picker
*
* Provides modifications and defaults for the base datetime picker widget.
*/
BabyBuddy.DatetimePicker = function ($, moment) {
return {
init: function (element, options) {
var defaultOptions = {
buttons: { showToday: true },
defaultDate: 'now',
format: 'L LT',
ignoreReadonly: true,
locale: moment.locale(),
useCurrent: false
};
element.datetimepicker($.extend(defaultOptions, options));
}
};
}(jQuery, moment);
/* Baby Buddy Timer
*
* Uses a supplied ID to run a timer. The element using the ID must have

Binary file not shown.

File diff suppressed because one or more lines are too long