44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Platform.Storage;
|
|
using LehrerApp.Desktop.ViewModels.Students;
|
|
|
|
namespace LehrerApp.Desktop.Views.Students;
|
|
|
|
public partial class CreateLetterDialog : Window
|
|
{
|
|
public CreateLetterDialog() => InitializeComponent();
|
|
|
|
private async void OnGenerate(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is not CreateLetterDialogViewModel vm) return;
|
|
if (vm.UsesAttendanceCalendar && !vm.AttendanceCalendarConfigured &&
|
|
!await ConfigureAttendanceCalendar(vm)) return;
|
|
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
|
{
|
|
Title = "PDF-Brief speichern",
|
|
SuggestedFileName = vm.SuggestedFileName,
|
|
DefaultExtension = "pdf",
|
|
FileTypeChoices = [new FilePickerFileType("PDF-Dateien") { Patterns = ["*.pdf"] }],
|
|
});
|
|
if (file is null || !vm.Generate(file.Path.LocalPath)) return;
|
|
Close(file.Path.LocalPath);
|
|
}
|
|
|
|
private async void OnConfigureAttendanceCalendar(object? sender, RoutedEventArgs e)
|
|
{
|
|
if (DataContext is CreateLetterDialogViewModel vm) await ConfigureAttendanceCalendar(vm);
|
|
}
|
|
|
|
private async Task<bool> ConfigureAttendanceCalendar(CreateLetterDialogViewModel vm)
|
|
{
|
|
var configVm = new AttendanceCalendarConfigurationViewModel(vm.GetAttendanceCalendarOptions());
|
|
var dialog = new AttendanceCalendarConfigurationDialog { DataContext = configVm };
|
|
if (!await dialog.ShowDialog<bool>(this)) return false;
|
|
vm.SetAttendanceCalendarOptions(configVm.BuildResult());
|
|
return true;
|
|
}
|
|
|
|
private void OnCancel(object? sender, RoutedEventArgs e) => Close(null);
|
|
}
|