Ekapp/skolehjem/resources/views/app/washing-reservations/create.blade.php

301 lines
12 KiB
PHP
Raw Normal View History

2020-07-28 13:13:33 +00:00
@extends("app.layout.base")
2020-07-28 13:13:33 +00:00
@section("title")
Booking Liste
@endsection
@section("content")
<main>
<h1 class="text-center sde-blue mb-0">{{__('msg.bookingliste')}}</h1>
{!! session()->get('ReservationExists') !!}
2020-07-28 13:13:33 +00:00
<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>
2020-08-05 08:12:05 +00:00
@if(count(\App\WashingMachine::all()) < 1)
<p style="margin: 0 18px;">{{__('msg.dereringenvaskemaskiner')}}.</p>
2020-08-05 08:12:05 +00:00
@endif
2020-07-28 13:13:33 +00:00
</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();
2020-07-28 13:13:33 +00:00
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);
2020-08-05 06:27:33 +00:00
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());
2020-07-28 13:13:33 +00:00
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() {
2020-08-04 13:29:21 +00:00
onDateSelect(date, dayHolder, datetext);
2020-07-28 13:13:33 +00:00
}
calendarRow.appendChild(dayHolder);
});
calendarBody.appendChild(calendarRow);
calendar.innerHTML = "";
calendar.appendChild(header);
calendar.appendChild(calendarBody);
}
2020-08-04 13:29:21 +00:00
function onDateSelect(date, dayHolder, datetext) {
2020-07-28 13:13:33 +00:00
let events;
let locationz;
2020-07-28 13:13:33 +00:00
let machinez;
let buttonz;
let container = document.getElementById("event-container");
2020-08-03 10:57:14 +00:00
NodeList.prototype.forEach = Array.prototype.forEach;
2020-07-28 13:13:33 +00:00
var children = document.getElementById("calenderRow").childNodes;
children.forEach(function(item){
item.classList.remove("selected");
});
dayHolder.classList.add("selected");
2020-08-03 10:57:14 +00:00
let machine_id;
let location_id;
2020-08-03 10:57:14 +00:00
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;
2020-07-28 13:13:33 +00:00
axios({
method: 'get',
url: '{{ route("washing-reservations.api") }}',
params: { 'date': date, 'machine_id': machine_id, 'datetext': datetext, 'location_id': location_id }
2020-07-28 13:13:33 +00:00
}).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");
}
2020-07-28 13:13:33 +00:00
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')}}";
2020-07-28 13:13:33 +00:00
let select = document.createElement("select");
select.classList.add("events__title");
select.id = "washing-machines";
select.name = "machine_id";
2020-07-28 13:13:33 +00:00
2020-08-03 10:57:14 +00:00
select.onchange = function() {
2020-08-04 13:29:21 +00:00
onDateSelect(date, dayHolder, datetext);
2020-08-03 10:57:14 +00:00
}
2020-07-28 13:13:33 +00:00
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')}}";
2020-07-28 13:13:33 +00:00
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')}}";
2020-07-28 13:13:33 +00:00
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);
}
2020-07-28 13:13:33 +00:00
let machines = data["washingmachines"];
machinez.innerHTML = "";
2020-08-03 10:57:14 +00:00
machinez.onchange = function () {
2020-08-04 13:29:21 +00:00
onDateSelect(date, dayHolder, datetext);
2020-08-03 10:57:14 +00:00
}
2020-07-28 13:13:33 +00:00
for (let i = 0; i < machines.length; i++) {
let option = document.createElement("option");
option.text = machines[i]["name"];
option.value = machines[i]["id"];
2020-08-03 10:57:14 +00:00
if(machine_id == machines[i]["id"])
option.selected = "selected";
2020-07-28 13:13:33 +00:00
machinez.appendChild(option);
}
events.innerHTML = "";
for (let hour = 8; hour <= 20; hour++) {
2020-08-04 14:50:08 +00:00
let value = datetext + " " + prependZero(hour) + ":00:00";
2020-08-04 13:29:21 +00:00
2020-07-28 13:13:33 +00:00
let option = document.createElement("option");
2020-07-28 13:13:33 +00:00
option.text = prependZero(hour) + ":00";
option.value = value;
option.id = value;
events.appendChild(option);
}
2020-07-28 13:13:33 +00:00
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";
2020-07-28 13:13:33 +00:00
events.appendChild(option);
document.getElementById("create-reservation").disabled = "disabled";
} else {
document.getElementById("create-reservation").disabled = "";
2020-07-28 13:13:33 +00:00
}
});
}
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