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') { if (typeof jQuery === 'undefined') {
throw new Error('Baby Buddy requires jQuery.') 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 = function () {
var BabyBuddy = {}; return {};
return BabyBuddy;
}(); }();
/**
* 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 %} {% block page %}{% endblock %}
<script src="{% static "babybuddy/js/vendor.js" %}"></script> <script src="{% static "babybuddy/js/vendor.js" %}"></script>
<script src="{% static "babybuddy/js/app.js" %}"></script>
<script>moment.locale('{{ LOCALE }}');</script> <script>moment.locale('{{ LOCALE }}');</script>
<script src="{% static "babybuddy/js/app.js" %}"></script>
{% block javascript %}{% endblock %} {% block javascript %}{% endblock %}
</body> </body>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,16 +1,40 @@
/* Baby Buddy
*
* Default namespace for the Baby Buddy app.
*/
if (typeof jQuery === 'undefined') { if (typeof jQuery === 'undefined') {
throw new Error('Baby Buddy requires jQuery.') 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 = function () {
var BabyBuddy = {}; return {};
return BabyBuddy;
}(); }();
/**
* 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 /* Baby Buddy Timer
* *
* Uses a supplied ID to run a timer. The element using the ID must have * 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') { if (typeof jQuery === 'undefined') {
throw new Error('Baby Buddy requires jQuery.') 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 = function () {
var BabyBuddy = {}; return {};
return BabyBuddy;
}(); }();
/**
* 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 /* Baby Buddy Timer
* *
* Uses a supplied ID to run a timer. The element using the ID must have * 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