348 lines
14 KiB
Plaintext
348 lines
14 KiB
Plaintext
@using BeWoPlanerMobil.Models
|
|
@using BeWoPlanerMobil.Util
|
|
@model SchedulerModel
|
|
|
|
@{
|
|
if(TempData[TempDataConstants.DoLogoutKey] is bool doLogout && doLogout)
|
|
{
|
|
<text>
|
|
<script type="text/javascript">
|
|
$("#second-logout-form").submit();
|
|
</script>
|
|
</text>
|
|
}
|
|
}
|
|
|
|
<script type="text/javascript">
|
|
function alldayChange() {
|
|
try {
|
|
const isAllDay = $("#all-day-switch").is(":checked");
|
|
|
|
const startDate = $("#scheduler-start-date").val().substring(0, 10);
|
|
const endDate = $("#scheduler-end-date").val().substring(0, 10);
|
|
|
|
$("#scheduler-start-date, #scheduler-end-date").prop("type", isAllDay ? "date" : "datetime-local");
|
|
|
|
$("#scheduler-start-date").val((isAllDay ? startDate : `${startDate}T${moment().format("hh:mm")}`));
|
|
$("#scheduler-end-date").val((isAllDay ? endDate : `${endDate}T${moment().format("hh:mm")}`));
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
$("#insert-appointment-form").ready(function () {
|
|
calcPrependTextSizes();
|
|
});
|
|
|
|
function calcPrependTextSizes() {
|
|
try {
|
|
const width = getMaxWidth("scheduler-form-prepend-text");
|
|
|
|
if(width <= 0) {
|
|
return;
|
|
}
|
|
|
|
$(".scheduler-form-prepend-text").width(width);
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function resetInsertAppointmentForm() {
|
|
try {
|
|
$.get("@Url.Action("ResetSelectedAppointment")")
|
|
.always(function() {
|
|
if($(window).width() < 768) {
|
|
hideAppointmentForm();
|
|
}
|
|
});
|
|
|
|
$("#subject, #location, #notice").val("");
|
|
|
|
$("#scheduler-start-date, #scheduler-end-date").prop("type", "datetime-local");
|
|
|
|
$("#scheduler-end-date").val(moment().format("YYYY-MM-DD[T]hh:mm"));
|
|
|
|
$("#scheduler-start-date").val(moment().format("YYYY-MM-DD[T]hh:mm"));
|
|
|
|
$("#resources-popup input:checked, #customers-popup input:checked, #employees-popup input:checked").each(function() {
|
|
$(this).prop("checked", false);
|
|
});
|
|
|
|
$("#selected-resources-list, #selected-employees-list, #selected-customers-list").empty();
|
|
|
|
$("#IsAllDay").prop("checked", false);
|
|
$("#IsPrivate").prop("checked", false);
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function validateAppointmentForm() {
|
|
const isAllDay = $("#IsAllDay").prop("checked") === true;
|
|
|
|
var start = window.moment(new Date($("#scheduler-start-date").val()));
|
|
var end = window.moment(new Date($("#scheduler-end-date").val()));
|
|
|
|
if(start.isValid() === false || end.isValid() === false) {
|
|
hideSpinner();
|
|
|
|
showMessagePopupWithHtml("Fehler", '<div class="alert alert-danger" role="alert">Die Zeit- und/oder Datumsangaben sind nicht korrekt.</div>');
|
|
return;
|
|
}
|
|
|
|
if(end.isBefore(start)) {
|
|
hideSpinner();
|
|
|
|
showMessagePopupWithHtml("Fehler", '<div class="alert alert-danger" role="alert">Das Startdatum muss vor dem Enddatum liegen.</div>');
|
|
return;
|
|
}
|
|
|
|
var selectedOids = [];
|
|
var oidString = "";
|
|
|
|
$("#resources-popup input:checked").each(function () {
|
|
const id = $(this).attr("id");
|
|
selectedOids.push(id.split("-")[1]);
|
|
});
|
|
|
|
for(let i = 0; i < selectedOids.length; i++) {
|
|
oidString += selectedOids[i] + ",";
|
|
}
|
|
|
|
$.get("@Url.Action("CheckResourcesAvailability", "Scheduler")", {start: start.format("DD.MM.YYYY HH:mm"), end: end.format("DD.MM.YYYY HH:mm"), resourceOids: oidString, allDay: isAllDay}).done(function (result) {
|
|
if(result.length > 1) {
|
|
try {
|
|
hideSpinner();
|
|
|
|
if(result.includes("Fehler!")) {
|
|
window.showErrorMessagePopup(result.substring(7));
|
|
return;
|
|
} else {
|
|
showMessagePopupWithHtml("Überschneidung",
|
|
result,
|
|
function () {
|
|
$("#messagePopup .modal-body").html();
|
|
showSpinner();
|
|
insertOrUpdateAppointment(start.format("DD.MM.YYYY"), end.format("DD.MM.YYYY"), start.format("HH:mm"), end.format("HH:mm"));
|
|
},
|
|
false);
|
|
}
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
return;
|
|
}
|
|
} else {
|
|
insertOrUpdateAppointment(start.format("DD.MM.YYYY"), end.format("DD.MM.YYYY"), start.format("HH:mm"), end.format("HH:mm"));
|
|
}
|
|
});
|
|
}
|
|
|
|
function insertOrUpdateAppointment(formattedStartDate, formattedEndDate, formattedStartTime, formattedEndTime) {
|
|
$.get(
|
|
"@Url.Action("CheckForOverlappingAppointments", "Scheduler")",
|
|
{
|
|
startDateRaw: formattedStartDate,
|
|
endDateRaw: formattedEndDate,
|
|
startTimeRaw: formattedStartTime,
|
|
endTimeRaw: formattedEndTime
|
|
}
|
|
).done(function (result) {
|
|
if(false === checkJson(result)) {
|
|
logWarning("insertOrUpdateAppointment: Der zurückgegebene Wert ist kein gültiges JSON!");
|
|
return;
|
|
}
|
|
|
|
const isOverlapping = parseJason(result);
|
|
|
|
if(isOverlapping === true) {
|
|
hideSpinner();
|
|
$("#messagePopup .modal-body").html('<div class="alert alert-warning" role="alert">Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin.<br/> Möchten Sie ihn wirklich speichern?</div>');
|
|
showMessagePopupWithCallback(
|
|
"Überschneidung",
|
|
null,
|
|
function () {
|
|
$("#messagePopup .modal-body").html();
|
|
showSpinner();
|
|
$("#insert-appointment-form").submit();
|
|
},
|
|
false);
|
|
} else {
|
|
$("#insert-appointment-form").submit();
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
@using(Html.BeginForm("InsertOrUpdateAppointment", "Scheduler", FormMethod.Post, new { id = "insert-appointment-form" }))
|
|
{
|
|
<div class="mt-0">
|
|
<div class="form-row">
|
|
<div class="col mx-0 pr-1">
|
|
<div class="form-group mb-1 mr-0 pr-0">
|
|
<div class="input-group">
|
|
<div class="input-group-prepend">
|
|
<div class="input-group-text">
|
|
Start
|
|
</div>
|
|
</div>
|
|
<input type="datetime-local" autocomplete="on" id="scheduler-start-date" name="StartDate" class="form-control" value="@Model.StartDateToEdit" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="col mx-0 pr-1">
|
|
<div class="form-group mb-1 mr-0 pr-0">
|
|
<div class="input-group date">
|
|
<div class="input-group-prepend">
|
|
<div class="input-group-text">
|
|
Ende
|
|
</div>
|
|
</div>
|
|
<input type="datetime-local" autocomplete="on" id="scheduler-end-date" name="EndDate" class="form-control" value="@Model.EndDateToEdit" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="col-6 mx-auto">
|
|
<div class="custom-control custom-switch custom-control-inline mx-auto">
|
|
<input type="checkbox" class="custom-control-input" id="is-private-switch" name="IsPrivate" />
|
|
<label class="custom-control-label" for="is-private-switch">Privat</label>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 mx-auto">
|
|
<div class="custom-control custom-switch custom-control-inline mx-auto">
|
|
<input type="checkbox" class="custom-control-input" id="all-day-switch" onchange = "alldayChange()" name="IsAllDay" />
|
|
<label class="custom-control-label" for="all-day-switch">Ganztägig</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if(Model.HasResourcesEmployeesOrCustomers)
|
|
{
|
|
<div class="form-row">
|
|
@if(Model.HasRightToViewEmployeeAppointments && Model.HasRightToInsertEmployeeAppointments)
|
|
{
|
|
<div class="col-md">
|
|
<div class="form-group my-1">
|
|
<button type="button" class="btn btn-bewo-employee w-100" data-toggle="modal" data-target="#employees-popup">Mitarbeiter</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
@if(Model.HasRightToViewCustomerSelectionInScheduler && Model.HasRightToInsertCustomerAppointments)
|
|
{
|
|
<div class="col-md">
|
|
<div class="form-group my-1">
|
|
<button type="button" class="btn btn-bewo-customers w-100" data-toggle="modal" data-target="#customers-popup">Klienten</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
@if(Model.HasRightToViewAllResourceAppointments && Model.HasRightToInsertRessourceAppointments && Model.ResourceCategories2Resources.Any())
|
|
{
|
|
<div class="col-md">
|
|
<div class="form-group my-1">
|
|
<button type="button" class="btn btn-bewo-resource w-100" data-toggle="modal" data-target="#resources-popup">Ressourcen</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
if(Model.HasRightToViewEmployeeAppointments && Model.HasRightToInsertEmployeeAppointments ||
|
|
Model.HasRightToViewCustomerSelectionInScheduler && Model.HasRightToInsertCustomerAppointments ||
|
|
Model.HasRightToViewAllResourceAppointments && Model.HasRightToInsertRessourceAppointments)
|
|
{
|
|
<div class="form-row">
|
|
<div class="col">
|
|
@if(Model.HasRightToViewEmployeeAppointments && Model.HasRightToInsertEmployeeAppointments)
|
|
{
|
|
<div id="scheduler-selected-employees-container">
|
|
@Html.Partial("SchedulerEmployeeSelectionPartial", Model)
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div class="form-row">
|
|
<div class="col mx-0">
|
|
@if(Model.HasRightToViewCustomerSelectionInScheduler && Model.HasRightToInsertCustomerAppointments)
|
|
{
|
|
<div id="scheduler-selected-customer-container">
|
|
@Html.Partial("SchedulerCustomerSelectionPartial", Model)
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="col mx-0">
|
|
@if(Model.HasRightToViewAllResourceAppointments && Model.HasRightToInsertRessourceAppointments)
|
|
{
|
|
<div id="scheduler-selected-resources-container">
|
|
@Html.Partial("SchedulerResourceSelectionPartial", Model)
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
@* Betreff *@
|
|
<div class="form-row">
|
|
<div class="col-md">
|
|
<div class="form-group mb-1">
|
|
<div class="input-group">
|
|
<div class="input-group-prepend">
|
|
<div class="input-group-text scheduler-form-prepend-text">
|
|
Betreff
|
|
</div>
|
|
</div>
|
|
<input type="text" autocomplete="on" id="subject" name="Subject" class="form-control" maxlength="256" value="@Model.SubjectToEdit" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* Ort *@
|
|
<div class="form-row">
|
|
<div class="col-md">
|
|
<div class="form-group mb-1">
|
|
<div class="input-group">
|
|
<div class="input-group-prepend">
|
|
<div class="input-group-text scheduler-form-prepend-text">
|
|
Ort
|
|
</div>
|
|
</div>
|
|
<input type="text" autocomplete="on" id="location" name="Location" class="form-control" maxlength="256" value="@Model.LocationToEdit" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@* Notiz *@
|
|
<div class="form-row">
|
|
<div class="col-md">
|
|
<div class="form-group mb-1">
|
|
<div class="input-group">
|
|
<div class="input-group-prepend">
|
|
<div class="input-group-text scheduler-form-prepend-text">
|
|
Notiz
|
|
</div>
|
|
</div>
|
|
<textarea class="form-control" autocomplete="on" id="notice" name="Notice" maxlength="1024">@Model.DescriptionToEdit</textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@* Abbrechen- und Anlegen-Button *@
|
|
<div class="w-100 bd-highlight mt-3">
|
|
<div class="ml-0 bd-highlight float-left">
|
|
<button type="button" class="btn btn-primary" id="reset-button" onclick="resetInsertAppointmentForm()">Abbrechen</button>
|
|
</div>
|
|
<div class="ml-3 bd-highlight float-right">
|
|
<button type="button" class="btn btn-primary" id="create-button" onclick="submitInsertAppointmentForm()">Speichern</button>
|
|
</div>
|
|
</div> |