From aed493eb95bf660145003f024434296c91d1c8c3 Mon Sep 17 00:00:00 2001 From: Mateja Date: Mon, 16 Nov 2020 18:18:19 +0100 Subject: Validate from and to date on reserve from. Copy activities.js to reservations.js --- app/Http/Controllers/ReservationsController.php | 8 ++++++ public/js/reservations.js | 38 +++++++++++++++++++++++++ resources/views/pages/reserve.blade.php | 3 ++ 3 files changed, 49 insertions(+) diff --git a/app/Http/Controllers/ReservationsController.php b/app/Http/Controllers/ReservationsController.php index 1865f46..249d18a 100644 --- a/app/Http/Controllers/ReservationsController.php +++ b/app/Http/Controllers/ReservationsController.php @@ -92,6 +92,14 @@ class ReservationsController extends Controller $validator = Validator::make($request->all(), $rules, $messages); + $validator->after(function ($validator) use ($request) { + $fromStamp = strtotime($request->sdate . ' ' . $request->stime); + $toStamp = strtotime($request->edate . ' ' . $request->etime); + if (!($fromStamp < $toStamp)) { + $validator->errors()->add('time', 'FROM time and date needs to be before TO time and date.'); + } + }); + if ($validator->fails()) { return Redirect::back() ->withErrors($validator) diff --git a/public/js/reservations.js b/public/js/reservations.js index e69de29..94bee2d 100644 --- a/public/js/reservations.js +++ b/public/js/reservations.js @@ -0,0 +1,38 @@ +$.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('input[name="csrf-token"]').attr('content') + } +}); + +jQuery('select#call-sign').change(fillTable); +jQuery(document).ready(fillTable); + +function fillTable() { + tableData = jQuery('table#ajax-table>tbody').first(); + tableData.html('Loading...'); + + sign = jQuery('select#call-sign').first().val(); + + jQuery.post('/api/activities', {'call-sign': sign}, function (data, status) { + if (status === 'success') { + if (data.data.length > 0) { + tableData.empty(); + for (var i = 0, len = data.data.length; i < len; i++) { + tr = '' + data.data[i].operatorCall + '' + + '' + data.data[i].fromTime + '' + + '' + data.data[i].toTime + '' + + '' + data.data[i].specialCall + '' + + '' + data.data[i].frequencies + '' + + '' + data.data[i].qso + ''; + tableData.append(tr); + } + } + else { + tableData.html('No data...'); + } + } + else { + tableData.html('Error!'); + } + }); +} diff --git a/resources/views/pages/reserve.blade.php b/resources/views/pages/reserve.blade.php index 0bcab42..244d70a 100644 --- a/resources/views/pages/reserve.blade.php +++ b/resources/views/pages/reserve.blade.php @@ -37,6 +37,9 @@ +@error('time') +
{{ $message }}
+@enderror
-- cgit v1.2.3