Files
BeWoPlaner/BeWoPlanerMobil/Views/DevExpressScheduler/SchedulerPagePartial.cshtml
2026-06-29 13:45:41 +02:00

454 lines
22 KiB
Plaintext

@using BeWoPlanerMobil.Models
@using BeWoPlanerMobil.Util.SchedulerUtils
@using BeWoPlanerMobil.Views.DevExpressScheduler
@using BS.Shared.DataContracts
@using BS.Shared.DataContracts.Compact
@using DevExpress.XtraScheduler
@using MenuItem = DevExpress.Web.MenuItem
@using PopupMenuShowingEventArgs = DevExpress.Web.ASPxScheduler.PopupMenuShowingEventArgs
@model BeWoPlanerMobil.Models.DevExpressSchedulerModel
@functions
{
//ToDo: So das EditForm verändern!
//https://docs.devexpress.com/AspNetMvc/119776/components/scheduler/get-started/how-to-customize-the-appointment-dialog-using-view-model-api-working-with-custom-fields?utm_source=SupportCenter&utm_medium=website&utm_campaign=docs-feedback&utm_content=T743814
static AppointmentRecurrenceFormSettings CreateAppointmentRecurrenceFormSettings(CustomAppointmentTemplateContainer container)
{
return new AppointmentRecurrenceFormSettings
{
Name = "appointmentRecurrenceForm",
Width = Unit.Percentage(100),
IsRecurring = container.Appointment.IsRecurring,
DayNumber = container.RecurrenceDayNumber,
End = container.RecurrenceEnd,
Month = container.RecurrenceMonth,
OccurrenceCount = container.RecurrenceOccurrenceCount,
Periodicity = container.RecurrencePeriodicity,
RecurrenceRange = container.RecurrenceRange,
Start = container.Start,
WeekDays = container.RecurrenceWeekDays,
WeekOfMonth = container.RecurrenceWeekOfMonth,
RecurrenceType = container.RecurrenceType,
IsFormRecreated = container.IsFormRecreated
};
}
static void PopupMenuShowing(object s, PopupMenuShowingEventArgs e)
{
var menuId = e.Menu.MenuId;
var invisibleMenuItemNames = new List<string>
{
"StatusSubMenu",
"LabelSubMenu",
"StatusSubMenu",
"LabelSubMenu",
"NewAllDayEvent",
"NewRecurringEvent"
};
if(menuId == SchedulerMenuItemId.AppointmentMenu)
{
e.Menu.Items.Add(new MenuItem("In die Zeiterfassung übertragen", "ToServiceRecord"));
e.Menu.Items.Add(new MenuItem("Zusagen", "ConfirmApt"));
e.Menu.Items.Add(new MenuItem("Mit Vorbehalt zusagen", "MaybeApt"));
e.Menu.Items.Add(new MenuItem("Absagen", "CancelApt"));
}
if(menuId == SchedulerMenuItemId.DefaultMenu)
{
e.Menu.Items.Add(new MenuItem("Verfügbare Mitarbeiter anzeigen", "ShowAvailableEmployees"));
}
e.Menu.ClientSideEvents.PopUp = "OnAppointmentMenuPopup";
foreach(MenuItem item in e.Menu.Items)
{
if(invisibleMenuItemNames.Contains(item.Name))
{
item.Visible = false;
}
if(item.Name == "SwitchViewMenu")
{
foreach(MenuItem subItem in item.Items)
{
switch(subItem.Text)
{
case "Day View":
subItem.Text = "Tag";
break;
case "Work Week View":
subItem.Text = "Arbeitswoche";
break;
case "Week View":
subItem.Text = "Woche";
break;
case "Month View":
subItem.Text = "Monat";
break;
case "Timeline View":
subItem.Text = "Zeitstrahl";
break;
case "Agenda View":
subItem.Text = "Agenda";
break;
}
}
}
switch(item.Text)
{
case "Open":
item.Text = "Öffnen";
break;
case "Edit Series":
item.Text = "Serie bearbeiten";
break;
case "Restore Default State":
item.Text = "Serienelement wiederherstellen";
break;
case "Delete":
item.Text = "Löschen";
break;
case "New Appointment":
item.Text = "Neuer Termin";
break;
case "New Recurring Appointment":
item.Text = "Neuer Serientermin";
break;
case "Go to Today":
item.Text = "Heute";
break;
case "Go to Date...":
item.Text = "Gehe zu Datum...";
break;
case "Change View To":
item.Text = "Ansicht wechseln";
break;
case "60 Minutes":
item.Text = "60 Minuten";
break;
case "30 Minutes":
item.Text = "30 Minuten";
break;
case "15 Minutes":
item.Text = "15 Minuten";
break;
case "10 Minutes":
item.Text = "10 Minuten";
break;
case "6 Minutes":
item.Text = "6 Minuten";
break;
case "5 Minutes":
item.Text = "5 Minuten";
break;
}
}
}
void AllowAppointmentEdit(object o, AppointmentOperationEventArgs e)
{
var hasRightToViewAppointment = true;
var appointment = e.Appointment;
var isAbsenceTime = appointment.CustomFields["IsAbsenceTime"] is true;
if(isAbsenceTime)
{
e.Allow = false;
return;
}
var originator = appointment.CustomFields["Originator"] as CompactEmployeeDC;
var employeeList = appointment.CustomFields["Employees"] as List<Employee2SchedulerAppointmentDC>;
var isOriginator = originator?.EmployeeOid.Equals(Model.LoggedInUserOid) ?? false;
var isPrivate = appointment.CustomFields["IsPrivate"] is true;
if(false == isOriginator && isPrivate && false == (employeeList?.Any(e2A => Equals(e2A.Employee, Model.LoggedInCompactEmployee)) ?? false))
{
hasRightToViewAppointment = false;
}
e.Allow = hasRightToViewAppointment;
}
void AllowAppointmentCreate(object o, AppointmentOperationEventArgs e)
{
e.Allow = Model.HasRightKalenderAnsehen || Model.HasRightKalenderKlientenTermineAnlegen || Model.HasRightKalenderMitarbeiterTermineAnlegen;
}
}
@{
var scheduler = Html.DevExpress().Scheduler(
settings =>
{
settings.Name = "scheduler";
settings.OptionsAdaptivity.Enabled = true;
settings.CallbackRouteValues = new { Controller = "DevExpressScheduler", Action = "SchedulerPagePartial" };
settings.EditAppointmentRouteValues = new { Controller = "DevExpressScheduler", Action = "EditAppointment" };
settings.CustomActionRouteValues = new { Controller = "DevExpressScheduler", Action = "CustomCallBackAction" };
settings.ClientSideEvents.ToolTipDisplaying = "onToolTipDisplaying";
settings.OptionsToolTips.SetAppointmentToolTipTemplateContent(() =>
{
Html.RenderPartial("CustomAppointmentToolTipPartial");
});
settings.OptionsToolTips.SetAppointmentMobileToolTipTemplateContent(() => { Html.RenderPartial("CustomAppointmentToolTipPartial"); });
settings.OptionsToolTips.SetAppointmentDragToolTipTemplateContent(() =>
{
Html.RenderPartial("CustomAppointmentDragToolTip");
});
settings.OptionsCustomization.AllowInplaceEditor = UsedAppointmentType.None;
settings.OptionsCustomization.AllowDisplayAppointmentFlyout = false;
settings.ActiveViewType = Model.CurrentViewType;
settings.OptionsView.VerticalScrollBarMode = ScrollBarMode.Auto;
settings.OptionsToolTips.ShowSelectionToolTip = false;
settings.ClientSideEvents.ActiveViewChanging = "onActiveViewChanged";
settings.ClientSideEvents.MenuItemClicked = "onMenuItemClicked";
settings.OptionsCustomization.AllowAppointmentEdit = UsedAppointmentType.Custom;
settings.OptionsCustomization.AllowAppointmentCopy = UsedAppointmentType.Custom;
settings.OptionsCustomization.AllowAppointmentCreate = UsedAppointmentType.Custom;
settings.OptionsCustomization.AllowAppointmentResize = UsedAppointmentType.Custom;
settings.OptionsCustomization.AllowAppointmentDrag = UsedAppointmentType.Custom;
settings.OptionsCustomization.AllowAppointmentDelete = UsedAppointmentType.Custom;
settings.AllowAppointmentEdit = AllowAppointmentEdit;
settings.AllowAppointmentDrag = AllowAppointmentEdit;
settings.AllowAppointmentResize = AllowAppointmentEdit;
settings.AllowAppointmentCreate = AllowAppointmentCreate;
settings.InitClientAppointment = (send, evargs) =>
{
var isTask = evargs.Appointment.CustomFields["IsTask"] is true;
var isAbsenceTime = evargs.Appointment.CustomFields["IsAbsenceTime"] is true;
var canBeEdited = evargs.Appointment.CustomFields["CanBeEdited"] is true;
var canBeViewed = evargs.Appointment.CustomFields["CanBeViewed"] is true;
var canBeDeleted = evargs.Appointment.CustomFields["CanBeDeleted"] is true;
var customerList = (List<CompactCustomerDC>) evargs.Appointment.CustomFields["Customers"] ?? new List<CompactCustomerDC>();
var resourceList = (List<ResourceDC>) evargs.Appointment.CustomFields["Resources"] ?? new List<ResourceDC>();
evargs.Properties.Add("IsAbsenceTime", evargs.Appointment.CustomFields["IsAbsenceTime"]);
evargs.Properties.Add("IsTask", evargs.Appointment.CustomFields["IsTask"]);
evargs.Properties.Add("CanBeViewed", canBeViewed);
evargs.Properties.Add("CanBeEdited", canBeEdited);
evargs.Properties.Add("CanBeDeleted", canBeDeleted);
var oid = (long?) evargs.Appointment.Id;
var end = evargs.Appointment.End;
var originator = (CompactEmployeeDC) evargs.Appointment.CustomFields["Originator"];
var employeeList = (List<Employee2SchedulerAppointmentDC>) evargs.Appointment.CustomFields["Employees"] ?? new List<Employee2SchedulerAppointmentDC>();
evargs.Properties.Add("OriginatorName", originator.DetailDescription);
var participationInfos = new List<ParticipationInfoObject>();
var customerInfos = new List<CustomerInfoObject>();
var resourceInfos = new List<ResourceInfoObject>();
foreach(var employee2Appointment in employeeList)
{
if(employee2Appointment.SchedulerAppointmentOid is null || employee2Appointment.Employee2SchedulerAppointmentOid is null)
{
continue;
}
var parcitipationInfoObject =
new ParticipationInfoObject(
employee2Appointment.Employee.DetailDescription,
employee2Appointment.Employee2SchedulerAppointmentOid.Value,
(int) employee2Appointment.ParticipationAnswer,
employee2Appointment.SchedulerAppointmentOid.Value);
participationInfos.Add(parcitipationInfoObject);
}
foreach(var resource in resourceList)
{
var resourceInfoObject =
new ResourceInfoObject(
oid,
resource.Name,
resource.Color
);
resourceInfos.Add(resourceInfoObject);
}
foreach(var customer in customerList)
{
var customerInfoObject =
new CustomerInfoObject(
oid,
customer.DetailDescription
);
customerInfos.Add(customerInfoObject);
}
evargs.Properties.Add("ParticipationInfos", participationInfos);
evargs.Properties.Add("ResourceInfos", resourceInfos);
evargs.Properties.Add("CustomerInfos", customerInfos);
// originator ist bei einer Aufgabe null
var canConfirm = (false == isTask || false == isAbsenceTime) && end > DateTime.Now &&
false == (originator?.EmployeeOid.Equals(Model.LoggedInUserOid) ?? false) &&
employeeList.Any(employee2Appointment => employee2Appointment.Employee.EmployeeOid.Equals(Model.LoggedInUserOid));
evargs.Properties.Add("CanConfirm", canConfirm);
};
settings.PopupMenuShowing = PopupMenuShowing;
settings.Storage.Appointments.Assign(SchedulerHelper.DefaultAppointmentStorage);
settings.Storage.EnableReminders = false;
settings.OptionsBehavior.ClientTimeZoneId = "W. Europe Standard Time";
settings.Width = Unit.Percentage(100);
settings.Height = Unit.Percentage(100);
settings.Views.DayView.DayCount = 1;
settings.Start = BS.Shared.Extensions.DateTimeExtensions.GetDayOfWeek(DayOfWeek.Monday);
settings.OptionsForms.RecurrenceFormName = "appointmentRecurrenceForm";
settings.ClientSideEvents.EndCallback = "resizeSchedulerEditForm";
settings.ClientSideEvents.Init = "resizeSchedulerEditForm";
settings.AppointmentFormShowing = (sender, e) =>
{
if(sender is MVCxScheduler scheduler)
{
e.Container = new CustomAppointmentTemplateContainer(scheduler);
}
};
settings.Views.AgendaView.Enabled = false;
settings.Views.WeekView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.WeekView.SetHorizontalSameDayAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.FullWeekView.SetVerticalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("VerticalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo); });
settings.Views.FullWeekView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.MonthView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.MonthView.SetHorizontalSameDayAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.DayView.SetVerticalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("VerticalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo); });
settings.Views.DayView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.WorkWeekView.SetVerticalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("VerticalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo); });
settings.Views.WorkWeekView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.Views.TimelineView.SetHorizontalSameDayAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo); });
settings.Views.TimelineView.SetHorizontalAppointmentTemplateContent(appointmentTemplateContainer => { Html.RenderPartial("HorizontalAppointmentTemplatePartial", appointmentTemplateContainer.AppointmentViewInfo.Appointment); });
settings.OptionsForms.SetAppointmentFormTemplateContent(appointmentFormTemplateContainer =>
{
var container = (CustomAppointmentTemplateContainer) appointmentFormTemplateContainer;
var oid = (long?) container.Appointment.Id;
var employees2Appointment = container.Appointment.CustomFields["Employees"] as List<Employee2SchedulerAppointmentDC> ?? new List<Employee2SchedulerAppointmentDC>();
var customerList = container.Appointment.CustomFields["Customers"] as List<CompactCustomerDC> ?? new List<CompactCustomerDC>();
var resourceList = container.Appointment.CustomFields["Resources"] as List<ResourceDC> ?? new List<ResourceDC>();
var newModel = new AppointmentModel(Model.PossibleCustomers, Model.PossibleResources, Model.PossibleEmployees, Model.LoggedInUser, customerList, resourceList, employees2Appointment)
{
Oid = oid,
Subject = container.Appointment.Subject,
Location = container.Appointment.Location,
StartTime = container.Appointment.Start,
EndTime = container.Appointment.End,
AllDay = container.Appointment.AllDay,
Description = container.Appointment.Description,
EventType = (int?)container.Appointment.Type,
CompletedNotice = container.Appointment.CustomFields["CompletedNotice"]?.ToString(),
CompletedUser = container.Appointment.CustomFields["CompletedUser"]?.ToString(),
TaskDescription = container.Appointment.CustomFields["TaskDescription"]?.ToString(),
HasServiceRecordEntry = container.Appointment.CustomFields["HasServiceRecordEntry"] is true,
CanBeEdited = container.Appointment.CustomFields["CanBeEdited"] is true,
IsPrivate = container.Appointment.CustomFields["IsPrivate"] is true,
IsTask = container.Appointment.CustomFields["IsTask"] is true,
DueDate = container.Appointment.CustomFields["DueDate"] is DateTime dueDate ? dueDate : null,
CompletedDate = container.Appointment.CustomFields["CompletedDate"] is DateTime completedDate ? completedDate : null,
OriginatorOid = (container.Appointment.CustomFields["Originator"] as CompactEmployeeDC)?.EmployeeOid
};
var appointmentModel = ViewData["EditableAppointmentModel"] != null ? (AppointmentModel)ViewData["EditableAppointmentModel"] : newModel;
ViewBag.DeleteButtonEnabled = container.CanDeleteAppointment;
ViewBag.IsRecurring = container.Appointment.IsRecurring;
ViewBag.AppointmentRecurrenceFormSettings = CreateAppointmentRecurrenceFormSettings(container);
Html.RenderPartial("CustomAppointmentFormPartial", appointmentModel);
});
});
if(ViewData["SchedulerErrorText"] != null)
{
scheduler.SetErrorText((string)ViewData["SchedulerErrorText"]);
}
}
@scheduler.Bind(Model.Appointments,Model.Resources).GetHtml()
@* Mitarbeiterverfügbarkeitenpopup *@
@if(Model.EmployeeAvailabilityObject != null)
{
<script type="text/javascript">
$(document).ready(() => {
$("#employee-availability-popup").modal("show");
});
</script>
<div class="modal" data-backdrop="static" tabindex="-1" role="dialog" id="employee-availability-popup">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Verfügbarkeit vom <strong>@Model.EmployeeAvailabilityObject.IntervalStartStr</strong> bis <strong>@Model.EmployeeAvailabilityObject.IntervalEndStr</strong></h5>
<button type="button" class="close" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<div class="modal-body">
<table class="table table-sm table-striped service-record-table">
<thead>
<tr>
<th scope="col">Mitarbeiter</th>
<th scope="col" style="text-align: right;">Überstunden</th>
</tr>
</thead>
@foreach(var emp2Overtime in Model.EmployeeAvailabilityObject.Employee2Overtime)
{
<tr>
<td>
@emp2Overtime.Key.DetailDescription
</td>
<td style="text-align: right;">
@emp2Overtime.Value.ToString("0.00")
</td>
</tr>
}
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
}