From 4e3232e57a1b8afde5aa71fb3b1bfd70fcf6ff92 Mon Sep 17 00:00:00 2001
From: MichiK <6341204+der-michik@users.noreply.github.com>
Date: Tue, 4 Dec 2018 21:03:32 +0100
Subject: [PATCH 1/9] Replace datepicker and remove datepicker inline JS
---
includes/sys_form.php | 15 +--------------
package.json | 3 ++-
resources/assets/js/forms.js | 33 +++++++++++++++++++++++++++++++++
resources/assets/js/vendor.js | 7 +++----
4 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/includes/sys_form.php b/includes/sys_form.php
index b5a957c0..3c31f43e 100644
--- a/includes/sys_form.php
+++ b/includes/sys_form.php
@@ -72,23 +72,10 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '')
$shortLocale = substr($locale, 0, 2);
return form_element($label, '
-
+
'
. '' . glyph('th') . '
-
', $dom_id);
}
diff --git a/package.json b/package.json
index 3c6dbca1..7a6191a5 100644
--- a/package.json
+++ b/package.json
@@ -14,11 +14,12 @@
},
"dependencies": {
"bootstrap": "^3.3.7",
- "bootstrap-datepicker": "^1.7.1",
"chart.js": "^1.0.2",
+ "eonasdan-bootstrap-datetimepicker": "^4.17.47",
"jquery": "^3.3.1",
"jquery-ui": "^1.11.2",
"moment": "^2.8.2",
+ "moment-timezone": "^0.4.0",
"select2": "^4.0.6-rc.1",
"select2-bootstrap-theme": "0.1.0-beta.10"
},
diff --git a/resources/assets/js/forms.js b/resources/assets/js/forms.js
index 13e42d26..f1581907 100644
--- a/resources/assets/js/forms.js
+++ b/resources/assets/js/forms.js
@@ -92,3 +92,36 @@ $(function () {
return ($(window).height() - 50) + 'px';
}).css('overflow-y', 'scroll');
});
+
+/*
+ * Add a datepicker to all date input fields.
+ */
+$(function () {
+ $('.input-group.date').each(function () {
+ var elem = $(this);
+ var opts = {
+ minDate: '',
+ maxDate: '',
+ locale: 'en',
+ format: 'YYYY-MM-DD',
+ widgetPositioning: {horizontal: 'auto', vertical: 'bottom'}
+ };
+ $.extend(opts, elem.data());
+ if (opts.minDate.length === 0) {
+ delete opts.minDate;
+ }
+ if (opts.maxDate.length === 0) {
+ delete opts.maxDate;
+ }
+ elem.children('input').attr('type', 'text');
+ elem.children().on('click', function (ev) {
+ ev.stopImmediatePropagation();
+ if (elem.data('DateTimePicker') === undefined) {
+ elem.datetimepicker(opts);
+ elem.data('DateTimePicker').show();
+ } else {
+ elem.data('DateTimePicker').toggle();
+ }
+ });
+ });
+});
diff --git a/resources/assets/js/vendor.js b/resources/assets/js/vendor.js
index f9cddad6..07561fdf 100644
--- a/resources/assets/js/vendor.js
+++ b/resources/assets/js/vendor.js
@@ -1,12 +1,11 @@
window.$ = window.jQuery = require('jquery');
require('imports-loader?define=>false!jquery-ui');
require('bootstrap');
-require('imports-loader?define=>false&exports=>false!bootstrap-datepicker');
-require('bootstrap-datepicker/js/locales/bootstrap-datepicker.de');
-require('bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css');
-require('imports-loader?this=>window!chart.js');
require('imports-loader?this=>window&define=>false&exports=>false!moment');
require('imports-loader?this=>window&define=>false&exports=>false!moment/locale/de');
+require('imports-loader?define=>false&exports=>false!eonasdan-bootstrap-datetimepicker');
+require('eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css');
+require('imports-loader?this=>window!chart.js');
require('./forms');
require('./sticky-headers');
require('./moment-countdown');
From ed5ee3235e5f377e9485fc0f65d6fe6571a91d2a Mon Sep 17 00:00:00 2001
From: MichiK <6341204+der-michik@users.noreply.github.com>
Date: Wed, 5 Dec 2018 18:43:51 +0100
Subject: [PATCH 2/9] Add timepickers in shifts view
---
includes/pages/user_shifts.php | 4 +++
resources/assets/js/forms.js | 42 ++++++++++++++++++++++++++
resources/views/pages/user-shifts.html | 21 +++----------
3 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 942b8849..7156212a 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -176,6 +176,9 @@ function view_user_shifts()
$days = load_days();
$rooms = load_rooms();
$types = load_types();
+ $locale = $session->get('locale');
+ $shortLocale = substr($locale, 0, 2);
+
if (!$session->has('shifts-filter')) {
$room_ids = [
@@ -253,6 +256,7 @@ function view_user_shifts()
),
]
),
+ 'short_locale' => $shortLocale,
'filled_select' => make_select($filled, $shiftsFilter->getFilled(), 'filled', __('Occupancy')),
'task_notice' =>
'
1'
diff --git a/resources/assets/js/forms.js b/resources/assets/js/forms.js
index f1581907..3f2014d0 100644
--- a/resources/assets/js/forms.js
+++ b/resources/assets/js/forms.js
@@ -125,3 +125,45 @@ $(function () {
});
});
});
+
+/*
+ * Add a timepicker to all time input fields.
+ */
+$(function () {
+ $('.input-group.time').each(function () {
+ var elem = $(this);
+ var opts = {
+ locale: 'en',
+ format: 'HH:mm',
+ widgetPositioning: {horizontal: 'auto', vertical: 'bottom'}
+ };
+ $.extend(opts, elem.data());
+ elem.children('input').attr('type', 'text');
+ elem.datetimepicker(opts);
+ elem.children('input').on('click', function (ev) {
+ ev.stopImmediatePropagation();
+ elem.data('DateTimePicker').toggle();
+ });
+ });
+});
+
+/*
+ * Button to set current time in time input fields.
+ */
+$(function () {
+ $('.input-group.time').each(function () {
+ var elem = $(this);
+ elem.find('button').on('click', function () {
+ var input = elem.children('input').first();
+ input.val(moment().format('HH:mm'));
+ var day_selector = $('#' + input.attr('id').replace('time', 'day'));
+ var days = day_selector.children('option');
+ days.each(function (i) {
+ if ($(days[i]).val() === moment().format('YYYY-MM-DD')) {
+ day_selector.val($(days[i]).val());
+ return false;
+ }
+ });
+ });
+ });
+});
diff --git a/resources/views/pages/user-shifts.html b/resources/views/pages/user-shifts.html
index 3b75ac7f..f467c6fd 100644
--- a/resources/views/pages/user-shifts.html
+++ b/resources/views/pages/user-shifts.html
@@ -1,16 +1,3 @@
-
-