301 lines
12 KiB
PHP
301 lines
12 KiB
PHP
@extends("app.layout.base")
|
|
|
|
@section("title")
|
|
Booking Liste
|
|
@endsection
|
|
|
|
@section("content")
|
|
<main>
|
|
<h1 class="text-center sde-blue mb-0">{{__('msg.bookingliste')}}</h1>
|
|
{!! session()->get('ReservationExists') !!}
|
|
<div class="col w-100 mt-auto">
|
|
<div class="calendar-container">
|
|
<div class="calendar-container__header">
|
|
<button id="week-previous" class="calendar-container__btn fas fa-arrow-left" title="Previous">
|
|
<i class="icon ion-ios-arrow-back"></i>
|
|
</button>
|
|
<h2 id="title" class="calendar-container__title">{Måned} {År}</h2>
|
|
<button id="week-next" class="calendar-container__btn fas fa-arrow-right" title="Next">
|
|
<i class="icon ion-ios-arrow-forward"></i>
|
|
</button>
|
|
</div>
|
|
<div class="calendar-container__body">
|
|
<div id="calendar" class="calendar-table">
|
|
<div class="calendar-table__body">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<form method="post" action="{{ route("washing-reservations.store") }}" id="event-container" class="events-container">
|
|
@csrf
|
|
</form>
|
|
@if(count(\App\WashingMachine::all()) < 1)
|
|
<p style="margin: 0 18px;">{{__('msg.dereringenvaskemaskiner')}}.</p>
|
|
@endif
|
|
</div>
|
|
</main>
|
|
@endsection
|
|
|
|
@section("scripts")
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment-with-locales.min.js" integrity="sha512-qSnlnyh7EcD3vTqRoSP4LYsy2yVuqqmnkM9tW4dWo6xvAoxuVXyM36qZK54fyCmHoY1iKi9FJAUZrlPqmGNXFw==" crossorigin="anonymous"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/locale/da.min.js" integrity="sha512-rybyYvSnwg3zAZ/vjTTMoh8tOK0Z6tC2XCzr9e27M0xr8WU40IGo6SOP7FXXCyWgMyd3wZ8ln2nY4ce1ysYUfw==" crossorigin="anonymous"></script>
|
|
<script>
|
|
function generateCalendar(weekOffset = 0) {
|
|
const week = (moment().week() + weekOffset);
|
|
|
|
let weekDays = Array.apply(null, Array(7)).map((value, index) => {
|
|
return moment(index, "e").locale("da").startOf("week").weekday(index).format("ddd");
|
|
});
|
|
|
|
document.getElementById("title").innerHTML = '{{__('msg.ugestor')}} ' + moment().locale("da").day(weekDays[0]).week(week).isoWeek().toString();
|
|
|
|
const calendar = document.getElementById("calendar");
|
|
|
|
let header = document.createElement("div");
|
|
header.classList.add("calendar-table__header", "calendar-table__row");
|
|
|
|
let calendarBody = document.createElement("div");
|
|
calendarBody.classList.add("calendar-table__body");
|
|
|
|
let calendarRow = document.createElement("div");
|
|
calendarRow.classList.add("calendar-table__row")
|
|
calendarRow.id = "calenderRow";
|
|
|
|
weekDays.forEach(function (weekDay) {
|
|
let headerDay = document.createElement("div");
|
|
headerDay.classList.add("calendar-table__col");
|
|
|
|
headerDay.innerText = weekDay;
|
|
|
|
header.appendChild(headerDay);
|
|
|
|
let date = moment().locale("da").day(weekDay).week(week);
|
|
var datetext = moment().locale("da").day(weekDay).week(week).year() + "-" + prependZero((moment().locale("da").day(weekDay).week(week).month() + 1)) + "-" + prependZero(moment().locale("da").day(weekDay).week(week).date());
|
|
|
|
let dayHolder = document.createElement("div");
|
|
dayHolder.classList.add("calendar-table__col");
|
|
|
|
let day = document.createElement("div");
|
|
day.classList.add("calendar-table__item");
|
|
day.innerText = date.date();
|
|
|
|
dayHolder.appendChild(day);
|
|
|
|
dayHolder.onclick = function() {
|
|
onDateSelect(date, dayHolder, datetext);
|
|
}
|
|
|
|
calendarRow.appendChild(dayHolder);
|
|
});
|
|
|
|
calendarBody.appendChild(calendarRow);
|
|
|
|
calendar.innerHTML = "";
|
|
|
|
calendar.appendChild(header);
|
|
calendar.appendChild(calendarBody);
|
|
}
|
|
|
|
function onDateSelect(date, dayHolder, datetext) {
|
|
let events;
|
|
let locationz;
|
|
let machinez;
|
|
let buttonz;
|
|
|
|
let container = document.getElementById("event-container");
|
|
|
|
NodeList.prototype.forEach = Array.prototype.forEach;
|
|
var children = document.getElementById("calenderRow").childNodes;
|
|
|
|
children.forEach(function(item){
|
|
item.classList.remove("selected");
|
|
});
|
|
|
|
dayHolder.classList.add("selected");
|
|
|
|
let machine_id;
|
|
let location_id;
|
|
|
|
if(document.getElementById('washing-machines'))
|
|
machine_id = document.getElementById('washing-machines').value;
|
|
else
|
|
machine_id = 0;
|
|
|
|
if(document.getElementById('locations'))
|
|
location_id = document.getElementById('locations').value;
|
|
else
|
|
location_id = 0;
|
|
|
|
axios({
|
|
method: 'get',
|
|
url: '{{ route("washing-reservations.api") }}',
|
|
params: { 'date': date, 'machine_id': machine_id, 'datetext': datetext, 'location_id': location_id }
|
|
}).then(function (response) {
|
|
var data = response.data;
|
|
|
|
|
|
if(document.getElementById("locations") != undefined)
|
|
locationz = document.getElementById("locations");
|
|
else {
|
|
let span = document.createElement("span");
|
|
span.classList.add("events__title");
|
|
span.innerText = "Lokation";
|
|
|
|
let select = document.createElement("select");
|
|
select.classList.add("events__title");
|
|
select.id = "locations";
|
|
select.name = "location_id";
|
|
|
|
select.onchange = function() {
|
|
onDateSelect(date, dayHolder, datetext);
|
|
}
|
|
|
|
container.appendChild(span);
|
|
container.appendChild(select);
|
|
|
|
locationz = document.getElementById("locations");
|
|
}
|
|
if(document.getElementById("washing-machines") != undefined)
|
|
machinez = document.getElementById("washing-machines");
|
|
else {
|
|
let span = document.createElement("span");
|
|
span.classList.add("events__title");
|
|
span.innerText = "{{__('msg.maskiner')}}";
|
|
|
|
let select = document.createElement("select");
|
|
select.classList.add("events__title");
|
|
select.id = "washing-machines";
|
|
select.name = "machine_id";
|
|
|
|
select.onchange = function() {
|
|
onDateSelect(date, dayHolder, datetext);
|
|
}
|
|
|
|
container.appendChild(span);
|
|
container.appendChild(select);
|
|
|
|
machinez = document.getElementById("washing-machines");
|
|
}
|
|
if(document.getElementById("events") != undefined)
|
|
events = document.getElementById("events");
|
|
else {
|
|
let span = document.createElement("span");
|
|
span.classList.add("events__title");
|
|
span.innerText = "{{__('msg.tilgængeligetider')}}";
|
|
|
|
let select = document.createElement("select");
|
|
select.classList.add("events__title");
|
|
select.id = "events";
|
|
select.name = "time";
|
|
|
|
container.appendChild(span);
|
|
container.appendChild(select);
|
|
|
|
events = document.getElementById("events");
|
|
}
|
|
if(document.getElementById("create-reservation") != undefined)
|
|
buttonz = document.getElementById("create-reservation");
|
|
else {
|
|
let button = document.createElement("button");
|
|
|
|
button.id = "create-reservation";
|
|
button.innerText = "{{__('msg.reserver')}}";
|
|
button.type = "submit";
|
|
|
|
container.appendChild(button);
|
|
|
|
buttonz = document.getElementById("events");
|
|
}
|
|
|
|
let locations = data["locations"];
|
|
|
|
locationz.innerHTML = "";
|
|
locationz.onchange = function () {
|
|
onDateSelect(date, dayHolder, datetext);
|
|
}
|
|
|
|
for (let i = 0; i < locations.length; i++) {
|
|
let option = document.createElement("option");
|
|
option.text = locations[i]["name"];
|
|
option.value = locations[i]["id"];
|
|
|
|
if(location_id == locations[i]["id"])
|
|
option.selected = "selected";
|
|
|
|
locationz.appendChild(option);
|
|
}
|
|
|
|
let machines = data["washingmachines"];
|
|
|
|
machinez.innerHTML = "";
|
|
machinez.onchange = function () {
|
|
onDateSelect(date, dayHolder, datetext);
|
|
}
|
|
|
|
for (let i = 0; i < machines.length; i++) {
|
|
let option = document.createElement("option");
|
|
option.text = machines[i]["name"];
|
|
option.value = machines[i]["id"];
|
|
|
|
if(machine_id == machines[i]["id"])
|
|
option.selected = "selected";
|
|
|
|
machinez.appendChild(option);
|
|
}
|
|
|
|
events.innerHTML = "";
|
|
for (let hour = 8; hour <= 20; hour++) {
|
|
let value = datetext + " " + prependZero(hour) + ":00:00";
|
|
|
|
let option = document.createElement("option");
|
|
|
|
option.text = prependZero(hour) + ":00";
|
|
option.value = value;
|
|
option.id = value;
|
|
events.appendChild(option);
|
|
}
|
|
|
|
let unavailable_times = data["unavailable_times"];
|
|
|
|
unavailable_times.forEach(function (item, index) {
|
|
document.getElementById(item).remove();
|
|
});
|
|
|
|
if(events.childElementCount == 0){
|
|
let option = document.createElement("option");
|
|
option.disabled = "disabled";
|
|
option.text = "Der er ingen tilgængelige tider";
|
|
option.selected = "selected";
|
|
events.appendChild(option);
|
|
|
|
document.getElementById("create-reservation").disabled = "disabled";
|
|
} else {
|
|
document.getElementById("create-reservation").disabled = "";
|
|
}
|
|
});
|
|
}
|
|
|
|
function prependZero(value) {
|
|
if(value < 10)
|
|
return "0" + value;
|
|
return value;
|
|
}
|
|
|
|
let weekOffset = 0;
|
|
|
|
if(document.getElementById("calendar")) {
|
|
generateCalendar();
|
|
|
|
document.getElementById("week-previous").onclick = function () {
|
|
weekOffset--;
|
|
generateCalendar(weekOffset);
|
|
}
|
|
|
|
document.getElementById("week-next").onclick = function () {
|
|
weekOffset++;
|
|
generateCalendar(weekOffset);
|
|
}
|
|
}
|
|
</script>
|
|
@endsection
|