From 0188673e1f16f15e37f97e197a3c5eee3cd93b0c Mon Sep 17 00:00:00 2001 From: Felix Hamann Date: Sun, 10 Jun 2018 20:51:41 +0200 Subject: [PATCH] added datepicker globally --- src/Foundation.hs | 1 + templates/home.hamlet | 10 +++---- templates/home.julius | 19 -------------- templates/standalone/datepicker.hamlet | 1 + templates/standalone/datepicker.julius | 36 ++++++++++++++++++++++++++ templates/widgets/form.hamlet | 1 + 6 files changed, 44 insertions(+), 24 deletions(-) delete mode 100644 templates/home.julius create mode 100644 templates/standalone/datepicker.hamlet create mode 100644 templates/standalone/datepicker.julius diff --git a/src/Foundation.hs b/src/Foundation.hs index be28d2245..ad8f9b5b8 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -482,6 +482,7 @@ instance Yesod UniWorX where $(widgetFile "standalone/inputs") $(widgetFile "standalone/tabber") $(widgetFile "standalone/alerts") + $(widgetFile "standalone/datepicker") withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet") -- The page to be redirected to when authentication is required. diff --git a/templates/home.hamlet b/templates/home.hamlet index f57e6d570..b827a56dd 100644 --- a/templates/home.hamlet +++ b/templates/home.hamlet @@ -30,11 +30,11 @@

Date picker -
- - - - + + + + +
diff --git a/templates/home.julius b/templates/home.julius deleted file mode 100644 index c62129e2c..000000000 --- a/templates/home.julius +++ /dev/null @@ -1,19 +0,0 @@ -document.addEventListener('DOMContentLoaded', function() { - 'use strict'; - - var config = { - enableTime: true, - altInput: true, - altFormat: "j. F Y, H:i", - dateFormat: "Y-m-d H:i", - time_24hr: true - }; - - flatpickr('#datetime-form1 [type="date"]', { - altFormat: "j. F Y", dateFormat: "Y-m-d", altInput: true - }); - flatpickr('#datetime-form1 [type="time"]', { - enableTime: true, noCalendar: true, altFormat: "H:i", dateFormat: "H:i", altInput: true, time_24hr: true - }); - flatpickr('#datetime-form2 input', config); -}); diff --git a/templates/standalone/datepicker.hamlet b/templates/standalone/datepicker.hamlet new file mode 100644 index 000000000..4ec550e09 --- /dev/null +++ b/templates/standalone/datepicker.hamlet @@ -0,0 +1 @@ + diff --git a/templates/standalone/datepicker.julius b/templates/standalone/datepicker.julius new file mode 100644 index 000000000..f056b5062 --- /dev/null +++ b/templates/standalone/datepicker.julius @@ -0,0 +1,36 @@ +document.addEventListener('DOMContentLoaded', function() { + "use strict"; + + var config = { + dtLocal: { + enableTime: true, + altInput: true, + altFormat: "j. F Y, H:i", + dateFormat: "Y-m-d H:i", + time_24hr: true + }, + d: { + altFormat: "j. F Y", + dateFormat: "Y-m-d", + altInput: true + }, + t: { + enableTime: true, + noCalendar: true, + altFormat: "H:i", + dateFormat: "H:i", + altInput: true, + time_24hr: true + } + }; + + Array.from(document.querySelectorAll('input[type="date"]')).forEach(function(el) { + flatpickr(el, config.d); + }); + Array.from(document.querySelectorAll('input[type="time"]')).forEach(function(el) { + flatpickr(el, config.t); + }); + Array.from(document.querySelectorAll('input[type="datetime-local"]')).forEach(function(el) { + flatpickr(el, config.dtLocal); + }); +}); diff --git a/templates/widgets/form.hamlet b/templates/widgets/form.hamlet index 91c015dd9..fdc9d5fb2 100644 --- a/templates/widgets/form.hamlet +++ b/templates/widgets/form.hamlet @@ -6,4 +6,5 @@ $case formLayout
$if not (Blaze.null $ fvLabel view)