Files
EnvelopeGenerator/EnvelopeGenerator.Server/EnvelopeGenerator.Server.Client/Pages/ReceiverPage.razor
TekH 0fbaaf0b92 Refactor ReceiverPage for WebAssembly and state persistence
Switched from server-side Blazor (`InteractiveServer`) to client-side WebAssembly (`InteractiveWebAssembly`) rendering for `ReceiverPage` and `ReceiverRejectedPage`.

Refactored dependency injection:
- Removed: `IMediator`, `EnvelopeReceiverAuthorizationService`, `EnvelopeReceiverPageDataService`, `IPdfPageImageRenderer`.
- Added: `DocumentService`, `EnvelopeReceiverService`, `PdfRenderService`, `PersistentComponentState`.

Implemented state persistence using `PersistentComponentState` to improve user experience by restoring page state. Added `ReceiverPageInitialState` class and implemented `IDisposable` for cleanup.

Simplified authorization by replacing claims-based checks with `AuthService.CheckEnvelopeAccessAsync`. Updated service usage to streamline data fetching and PDF rendering.

Refactored `IsRejected` logic to rely solely on `EnvelopeStatus`. Cleaned up unused namespaces and modernized code patterns for better readability and maintainability.

Updated `PdfRenderController` to allow anonymous access to the `RenderPages` endpoint, enabling broader use cases.

Overall, these changes improve maintainability, simplify dependencies, and align the application with a more scalable client-side architecture.
2026-11-24 14:47:46 +01:00

1187 lines
54 KiB
Plaintext

@page "/envelope/{EnvelopeKey}"
@rendermode InteractiveWebAssembly
@implements IDisposable
@using EnvelopeGenerator.Application.Common.Dto
@using EnvelopeGenerator.Server.Client.Models
@using EnvelopeGenerator.Server.Client.Components.PdfEditor
@using EnvelopeGenerator.Server.Client.Models.Constants
@using EnvelopeGenerator.Server.Client.Services
@using EnvelopeGenerator.Application.Resources
@using EnvelopeGenerator.Application.Common.Extensions
@using EnvelopeGenerator.Application.EnvelopeReceivers.Queries
@using EnvelopeGenerator.Domain.Constants
@using Microsoft.JSInterop
@using DevExpress.Blazor
@using System.ComponentModel.DataAnnotations
@using Microsoft.Extensions.Localization
@inject NavigationManager Navigation
@inject IJSRuntime JSRuntime
@inject EnvelopeGenerator.Server.Client.Services.AuthService AuthService
@inject AnnotationService AnnotationService
@inject SignatureService SignatureService
@inject DocumentService DocumentService
@inject EnvelopeReceiverService EnvelopeReceiverService
@inject PdfRenderService PdfRenderService
@inject AppVersionService AppVersion
@inject ILogger<ReceiverPage> Logger
@inject IStringLocalizer<Resource> UiLocalizer
@inject PersistentComponentState PersistentComponentState
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css" rel="stylesheet" />
<link href="@AppVersion.GetVersionedUrl("css/envelope-viewer.css")" rel="stylesheet" />
<script src="@AppVersion.GetVersionedUrl("js/receiver-signature.js")"></script>
<script src="@AppVersion.GetVersionedUrl("js/envelope-editor.js")"></script>
<div class="envelope-viewer-layout">
<div class="envelope-action-bar">
<div class="envelope-action-bar__inner" style="flex-direction: column; align-items: stretch; padding: 0.35rem 1.5rem; gap: 0.35rem;">
@* Row 1: Title + Sender + Badges *@
<div style="display: flex; align-items: center; justify-content: space-between; gap: 1rem;">
@* Left: Title + Sender *@
<div style="flex: 0 1 auto; min-width: 0; display: flex; align-items: center; gap: 0.75rem;">
@if (_envelopeReceiver is not null)
{
<div style="font-size: 0.9rem; font-weight: 600; color: #1f2937; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
@(_envelopeReceiver.Envelope?.Title ?? "Dokument")
</div>
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.User?.FullName) || !string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.User?.Email))
{
<span style="font-size: 0.7rem; color: #6b7280; white-space: nowrap;">
Von
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.User?.FullName))
{
<span style="font-weight: 500; color: #374151;">@_envelopeReceiver.Envelope.User.FullName</span>
}
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.User?.Email))
{
<span>&lt;@_envelopeReceiver.Envelope.User.Email&gt;</span>
}
@if (_envelopeReceiver.Envelope?.AddedWhen != null)
{
<span>&nbsp;·&nbsp;@_envelopeReceiver.Envelope.AddedWhen.ToString("dd.MM.yyyy")</span>
}
</span>
}
}
else
{
<div style="font-size: 0.9rem; font-weight: 600; color: #1f2937;">Dokumentenansicht</div>
}
</div>
@* Right: Badges + Signature status *@
<div class="d-flex align-items-center" style="gap: 0.75rem; flex: 0 0 auto;">
@if (_envelopeReceiver is not null)
{
<div class="d-flex flex-wrap align-items-center" style="gap: 0.3rem; font-size: 0.7rem;">
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.Name))
{
<span style="display: inline-flex; align-items: center; padding: 0.125rem 0.4rem; background: #f3f4f6; border-radius: 0.25rem; color: #374151; white-space: nowrap;">
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Z" />
</svg>
@_envelopeReceiver.Name
</span>
}
@if (_signatures.Count > 0)
{
@if (_signatures.Count > 1)
{
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change"
@onclick="GoToPreviousSignatureAsync"
disabled="@(!CanNavigateToAnotherSignature)"
title='@L("Receiver_SignNav_Previous", "Vorheriges Feld")'
style="padding: 0.2rem 0.55rem; min-width: 2.1rem; min-height: 1.75rem;">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z" />
</svg>
</button>
}
<span style="display: inline-flex; align-items: center; padding: 0.125rem 0.4rem; background: @(_capturedSignature is not null ? "#d1fae5" : "#ede9fe"); border-radius: 0.25rem; color: @(_capturedSignature is not null ? "#065f46" : "#6d28d9"); font-weight: 500; white-space: nowrap;">
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
</svg>
@if (_signatures.Count > 1)
{
@string.Format(L("Receiver_SignNav_PositionWithLabel", "{0} / {1} Signaturen"), CurrentSignatureDisplayIndex, _signatures.Count)
}
else
{
@($"{_signatures.Count} {L("Receiver_Signature_Singular", "Unterschrift")}")
}
@if (_capturedSignature is not null)
{
<span class="ms-1">✓</span>
}
</span>
@if (_signatures.Count > 1)
{
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change"
@onclick="GoToNextSignatureAsync"
disabled="@(!CanNavigateToAnotherSignature)"
title='@L("Receiver_SignNav_Next", "Nächstes Feld")'
style="padding: 0.2rem 0.55rem; min-width: 2.1rem; min-height: 1.75rem;">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16" aria-hidden="true">
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z" />
</svg>
</button>
}
}
@if (_envelopeReceiver.Envelope?.UseAccessCode ?? false)
{
<span style="display: inline-flex; align-items: center; padding: 0.125rem 0.4rem; background: #fef3c7; border-radius: 0.25rem; color: #92400e; font-weight: 500; white-space: nowrap;">
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M8 1a2 2 0 0 1 2 2v4H6V3a2 2 0 0 1 2-2zm3 6V3a3 3 0 0 0-6 0v4a2 2 0 0 0-2 2v5a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2z" />
</svg>
Code
</span>
}
@if (_envelopeReceiver.Envelope?.TFAEnabled ?? false)
{
<span style="display: inline-flex; align-items: center; padding: 0.125rem 0.4rem; background: #dbeafe; border-radius: 0.25rem; color: #1e40af; font-weight: 500; white-space: nowrap;">
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="9" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M5.338 1.59a61.44 61.44 0 0 0-2.837.856.481.481 0 0 0-.328.39c-.554 4.157.726 7.19 2.253 9.188a10.725 10.725 0 0 0 2.287 2.233c.346.244.652.42.893.533.12.057.218.095.293.118a.55.55 0 0 0 .101.025.615.615 0 0 0 .1-.025c.076-.023.174-.061.294-.118.24-.113.547-.29.893-.533a10.726 10.726 0 0 0 2.287-2.233c1.527-1.997 2.807-5.031 2.253-9.188a.48.48 0 0 0-.328-.39c-.651-.213-1.75-.56-2.837-.855C9.552 1.29 8.531 1.067 8 1.067c-.53 0-1.552.223-2.662.524zM5.072.56C6.157.265 7.31 0 8 0s1.843.265 2.928.56c1.11.3 2.229.655 2.887.87a1.54 1.54 0 0 1 1.044 1.262c.596 4.477-.787 7.795-2.465 9.99a11.775 11.775 0 0 1-2.517 2.453 7.159 7.159 0 0 1-1.048.625c-.28.132-.581.24-.829.24s-.548-.108-.829-.24a7.158 7.158 0 0 1-1.048-.625 11.777 11.777 0 0 1-2.517-2.453C1.928 10.487.545 7.169 1.141 2.692A1.54 1.54 0 0 1 2.185 1.43 62.456 62.456 0 0 1 5.072.56z" />
<path d="M10.854 5.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 1 1 .708-.708L7.5 7.793l2.646-2.647a.5.5 0 0 1 .708 0z" />
</svg>
2FA
</span>
}
</div>
}
@* Unterschreiben button — visible only when signature fields exist *@
@if (_signatures.Count > 0)
{
@if (_capturedSignature is not null)
{
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change pdf-toolbar__btn--signature-change-active"
@onclick="() => OpenSignaturePopup()"
title="Unterschrift andern"
style="flex-shrink: 0;">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z" />
</svg>
<span class="pdf-toolbar__btn-text">Unterschrift andern</span>
</button>
}
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change pdf-toolbar__btn--signature-change-active"
@onclick="OpenSubmitConfirmPopup"
disabled="@(_capturedSignature is null || _isSubmittingSignature || !AllSignatureFieldsApplied)"
title="Abschließen"
style="flex-shrink: 0;">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
</svg>
<span class="pdf-toolbar__btn-text">Abschließen</span>
</button>
}
</div>
</div>
@* Row 2: Messages *@
@if (_envelopeReceiver is not null && (!string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.Message) || !string.IsNullOrWhiteSpace(_envelopeReceiver.PrivateMessage)))
{
<div style="display: flex; align-items: flex-start; gap: 0.5rem; font-size: 0.7rem; padding-top: 0.15rem; border-top: 1px solid #e5e7eb;">
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.Envelope?.Message))
{
<div style="flex: 1; min-width: 0; padding: 0.2rem 0.4rem; background: #f9fafb; border-radius: 0.25rem; border-left: 2px solid #9ca3af; display: flex; align-items: flex-start; gap: 0.25rem;">
<span style="color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">@_envelopeReceiver.Envelope.Message</span>
</div>
}
@if (!string.IsNullOrWhiteSpace(_envelopeReceiver.PrivateMessage))
{
<div style="flex: 1; min-width: 0; padding: 0.2rem 0.4rem; background: #fef3c7; border-radius: 0.25rem; border-left: 2px solid #f59e0b; display: flex; align-items: flex-start; gap: 0.25rem;">
<span style="font-weight: 500; color: #92400e; flex-shrink: 0;">🔒</span>
<span style="color: #92400e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">@_envelopeReceiver.PrivateMessage</span>
</div>
}
</div>
}
@if (_signatures.Count > 0 && !AllSignatureFieldsApplied)
{
<div class="receiver-signing-hint">
@L("Receiver_Signing_Instruction", "Please click each highlighted field to sign.")
</div>
}
</div>
</div>
<div class="envelope-content" style="padding: 0; overflow: hidden;">
@if (_isLoading)
{
<div class="d-flex justify-content-center align-items-center h-100">
<div class="text-center">
<div class="spinner-border text-white mb-3" style="width: 3.5rem; height: 3.5rem;" role="status">
<span class="visually-hidden">Lädt...</span>
</div>
<p class="text-white fw-semibold">Dokument wird geladen...</p>
</div>
</div>
}
else if (_errorMessage is not null)
{
<div class="error-container">
<div class="alert alert-danger shadow-lg">
<div class="d-flex align-items-start">
<svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" fill="currentColor" class="me-3 flex-shrink-0" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z" />
<path d="M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z" />
</svg>
<div>
<h5 class="mb-2">Fehler beim Laden des Dokuments</h5>
<p class="mb-0">@_errorMessage</p>
</div>
</div>
</div>
</div>
}
else if (PdfDataUrl is not null)
{
<SenderPdfImageEditor IsPlacementMode="false"
PageCount="@_pageCount"
Pages="@_pagePreviews"
PdfDataUrl="@PdfDataUrl"
PdfFileName="@PdfFileName"
Fields="@FieldOverlays"
HiddenFieldIndexes="@_appliedSignatureFieldIndexes"
SignatureOverlays="@SignedOverlays"
FieldCursor="pointer"
ActiveFieldIndex="@ActiveSignatureFieldIndex"
AutoScrollToActiveField="true"
FieldClick="OnSignatureFieldClickAsync"
ShowFieldRemoveButton="false" />
}
</div>
</div>
<DxPopup @bind-Visible="_submitConfirmVisible"
HeaderText="Unterschrift bestätigen"
Width="440px"
MaxWidth="95vw"
ShowFooter="true"
CloseOnOutsideClick="false"
ShowCloseButton="false"
CloseOnEscape="false">
<BodyContentTemplate>
<div style="display: flex; align-items: flex-start; gap: 1rem; padding: 0.5rem 0;">
<div style="flex-shrink: 0; width: 40px; height: 40px; background: #d1fae5; border-radius: 50%; display: flex; align-items: center; justify-content: center;">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="#065f46" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
</svg>
</div>
<div>
<p style="margin: 0 0 0.4rem; font-weight: 600; color: #1f2937; font-size: 0.95rem;">
Möchten Sie das Dokument verbindlich unterschreiben?
</p>
<p style="margin: 0; color: #6b7280; font-size: 0.85rem; line-height: 1.5;">
Diese Aktion kann nicht rückgängig gemacht werden. Mit der Bestätigung erklären Sie, das oben angezeigte Dokument elektronisch unterzeichnet zu haben.
</p>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(_submitErrorMessage))
{
<div class="alert alert-danger mb-0" role="alert" style="font-size: 0.85rem;">
@_submitErrorMessage
</div>
}
</BodyContentTemplate>
<FooterContentTemplate>
<div class="d-flex gap-2 justify-content-end w-100" style="padding: 0.5rem 0;">
<button class="btn btn-outline-secondary"
@onclick="() => _submitConfirmVisible = false"
style="border-radius: 6px; padding: 0.5rem 1.25rem; font-weight: 500;">
Abbrechen
</button>
<button class="btn btn-primary"
@onclick="SubmitAndLogoutAsync"
disabled="@_isSubmittingSignature"
style="background: linear-gradient(135deg, #059669 0%, #047857 100%); border: none; border-radius: 6px; padding: 0.5rem 1.5rem; font-weight: 600; box-shadow: 0 2px 4px rgba(5, 150, 105, 0.3);">
@if (_isSubmittingSignature)
{
<span class="spinner-border spinner-border-sm me-1" role="status"></span>
}
Abschließen
</button>
</div>
</FooterContentTemplate>
</DxPopup>
@* Signature Popup *@
<DxPopup @bind-Visible="SignaturePopupVisible"
HeaderText="Unterschrift erstellen"
Width="640px"
MaxWidth="95vw"
ShowFooter="true"
CloseOnOutsideClick="true"
ShowCloseButton="true"
CloseOnEscape="true"
Shown="OnPopupShownAsync">
<BodyContentTemplate>
<ul class="nav nav-tabs mb-3" style="border-bottom: 2px solid #e9ecef;">
<li class="nav-item">
<button type="button"
class="nav-link @(_activeSignatureTab == SignatureTabDraw ? "active" : "")"
style="@(_activeSignatureTab == SignatureTabDraw ? "border-bottom: 3px solid #4F46E5; color: #4F46E5; font-weight: 600;" : "color: #6c757d;")"
@onclick="() => SetSignatureTabAsync(SignatureTabDraw)">
Zeichnen
</button>
</li>
<li class="nav-item">
<button type="button"
class="nav-link @(_activeSignatureTab == SignatureTabText ? "active" : "")"
style="@(_activeSignatureTab == SignatureTabText ? "border-bottom: 3px solid #4F46E5; color: #4F46E5; font-weight: 600;" : "color: #6c757d;")"
@onclick="() => SetSignatureTabAsync(SignatureTabText)">
Text
</button>
</li>
<li class="nav-item">
<button type="button"
class="nav-link @(_activeSignatureTab == SignatureTabImage ? "active" : "")"
style="@(_activeSignatureTab == SignatureTabImage ? "border-bottom: 3px solid #4F46E5; color: #4F46E5; font-weight: 600;" : "color: #6c757d;")"
@onclick="() => SetSignatureTabAsync(SignatureTabImage)">
Bild
</button>
</li>
</ul>
@if (_activeSignatureTab == SignatureTabDraw)
{
<p style="color: #6c757d; font-size: 0.875rem; margin-bottom: 0.75rem;">Bitte unterschreiben Sie im folgenden Feld.</p>
<canvas id="rp-signature-pad"
width="560"
height="360"
style="border: 2px solid #e9ecef; border-radius: 8px; background: white; width: 100%; max-width: 560px; display: block; margin: 0 auto; touch-action: none; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></canvas>
}
else if (_activeSignatureTab == SignatureTabText)
{
<p style="color: #6c757d; font-size: 0.875rem; margin-bottom: 0.75rem;">Geben Sie Ihre Unterschrift als Text ein und wählen Sie eine Schriftart.</p>
<div class="row g-3 mb-3">
<div class="col-12 col-md-7">
<input class="form-control"
placeholder="Ihre Unterschrift"
value="@_typedSignatureText"
@oninput="OnTypedSignatureChanged"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;" />
</div>
<div class="col-12 col-md-5">
<select class="form-select"
value="@_typedSignatureFont"
@onchange="OnTypedSignatureFontChanged"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;">
@foreach (var font in TypedSignatureFonts)
{
<option value="@font.Value" style="font-family: @font.Value">@font.Text</option>
}
</select>
</div>
</div>
<canvas id="rp-typed-signature-pad"
width="560"
height="360"
style="border: 2px solid #e9ecef; border-radius: 8px; background: white; width: 100%; max-width: 560px; display: block; margin: 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></canvas>
}
else
{
<p style="color: #6c757d; font-size: 0.875rem; margin-bottom: 0.75rem;">Laden Sie ein Bild Ihrer Unterschrift hoch.</p>
<input id="rp-signature-image-input"
class="form-control mb-3"
type="file"
accept="image/png,image/jpeg,image/webp"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;" />
@if (!string.IsNullOrWhiteSpace(_savedImageFileName))
{
<div style="font-size: 0.8rem; color: #6c757d; margin: -0.25rem 0 0.75rem;">
Letzte Datei: @_savedImageFileName
</div>
}
<canvas id="rp-image-signature-pad"
width="560"
height="360"
style="border: 2px solid #e9ecef; border-radius: 8px; background: white; width: 100%; max-width: 560px; display: block; margin: 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,0.1);"></canvas>
}
<div style="border-top: 2px solid #e9ecef; margin-top: 1.5rem; padding-top: 1.5rem;">
<div class="row g-3">
<div class="col-12 col-md-6">
<label class="form-label" for="rp-signer-name" style="font-size: 0.875rem; font-weight: 500; color: #495057;">
Vor- und Nachname <span style="color: #dc3545;">*</span>
</label>
<input id="rp-signer-name"
class="form-control"
value="@_signerFullName"
@oninput="args => _signerFullName = args.Value?.ToString() ?? string.Empty"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;" />
</div>
<div class="col-12 col-md-6">
<label class="form-label" for="rp-signer-position" style="font-size: 0.875rem; font-weight: 500; color: #495057;">
Position <span style="color: #6c757d; font-weight: 400;">(optional)</span>
</label>
<input id="rp-signer-position"
class="form-control"
value="@_signerPosition"
@oninput="args => _signerPosition = args.Value?.ToString() ?? string.Empty"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;" />
</div>
<div class="col-12 col-md-6">
<label class="form-label" for="rp-signature-place" style="font-size: 0.875rem; font-weight: 500; color: #495057;">
Ort <span style="color: #dc3545;">*</span>
</label>
<input id="rp-signature-place"
class="form-control"
value="@_signaturePlace"
@oninput="args => _signaturePlace = args.Value?.ToString() ?? string.Empty"
style="border: 2px solid #e9ecef; border-radius: 6px; padding: 0.625rem;" />
</div>
</div>
</div>
@if (!string.IsNullOrWhiteSpace(_popupValidationMessage))
{
<div style="background: #fee; border-left: 4px solid #dc3545; padding: 0.75rem 1rem; margin-top: 1rem; border-radius: 4px;">
<span style="color: #dc3545; font-size: 0.875rem; font-weight: 500;">@_popupValidationMessage</span>
</div>
}
</BodyContentTemplate>
<FooterContentTemplate>
<div class="d-flex gap-2 justify-content-between w-100" style="padding: 0.5rem 0;">
<button class="btn btn-outline-secondary"
@onclick="RenewSignatureAsync"
style="border-radius: 6px; padding: 0.625rem 1.25rem; font-weight: 500;">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z" />
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z" />
</svg>
Erneuern
</button>
<button class="btn btn-primary"
@onclick="SaveSignatureAsync"
style="background: linear-gradient(135deg, #4F46E5 0%, #4338CA 100%); border: none; border-radius: 6px; padding: 0.625rem 2rem; font-weight: 600; box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" fill="currentColor" class="me-1" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
</svg>
Speichern
</button>
</div>
</FooterContentTemplate>
</DxPopup>
@code {
// ----- Constants -----
const string SignatureTabDraw = "draw";
const string SignatureTabText = "text";
const string SignatureTabImage = "image";
const string DrawCanvasId = "rp-signature-pad";
const string TypedCanvasId = "rp-typed-signature-pad";
const string ImageInputId = "rp-signature-image-input";
const string ImageCanvasId = "rp-image-signature-pad";
readonly (string Text, string Value)[] TypedSignatureFonts =
[
("Brush Script", "'Brush Script MT', cursive"),
("Segoe Script", "'Segoe Script', cursive"),
("Lucida Handwriting", "'Lucida Handwriting', cursive"),
("Comic Sans", "'Comic Sans MS', cursive"),
("Cursive", "cursive"),
];
// ----- Parameters -----
[Parameter] public string? EnvelopeKey { get; set; }
const string InitialStateKeyPrefix = "receiver-page.initial-state.v1:";
// ----- Page state -----
bool _isLoading = true;
string? _errorMessage;
byte[]? _pdfBytes;
byte[]? _displayPdfBytes;
List<PdfPageImageDto> _pagePreviews = [];
int _pageCount;
IReadOnlyList<SignatureDto> _signatures = [];
EnvelopeReceiverDto? _envelopeReceiver;
IReadOnlyList<SenderPdfFieldOverlay> FieldOverlays => _signatures
.Select((s, i) => new SenderPdfFieldOverlay(i, s.Page, s.X, s.Y, L("Receiver_SignField_ClickToSign", "Sign here"), "#4F46E5"))
.ToList();
IReadOnlyList<SenderPdfSignatureOverlay> SignedOverlays => _capturedSignature is null
? Array.Empty<SenderPdfSignatureOverlay>()
: _signatures
.Select((s, i) => new { Signature = s, Index = i })
.Where(x => _appliedSignatureFieldIndexes.Contains(x.Index))
.Select(x => new SenderPdfSignatureOverlay(
x.Signature.Page,
x.Signature.X,
x.Signature.Y,
_capturedSignature.DataUrl,
_capturedSignature.FullName,
_capturedSignature.Position,
_capturedSignature.Place,
_capturedSignatureDateText ?? DateTime.Now.ToString("dd.MM.yyyy")))
.ToList();
bool AllSignatureFieldsApplied => _signatures.Count > 0 && _appliedSignatureFieldIndexes.Count == _signatures.Count;
List<int> NavigableSignatureIndexes => Enumerable.Range(0, _signatures.Count).ToList();
bool CanNavigateToAnotherSignature => _signatures.Count > 1;
int? ActiveSignatureFieldIndex => _currentSignatureNavFieldIndex;
int CurrentSignatureDisplayIndex => _currentSignatureNavFieldIndex.HasValue
? (_currentSignatureNavFieldIndex.Value + 1)
: (_signatures.Count > 0 ? 1 : 0);
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
: null;
string PdfFileName => $"Envelope-{EnvelopeKey ?? "receiver"}.pdf";
// ----- Signature popup state -----
SignatureCaptureDto? _capturedSignature;
bool _signaturePopupVisible = false;
int? _pendingSignatureFieldIndex;
string? _popupValidationMessage;
string _activeSignatureTab = SignatureTabDraw;
string _lastSavedSignatureTab = SignatureTabDraw;
string _typedSignatureText = string.Empty;
string _typedSignatureFont = "'Brush Script MT', cursive";
string _savedImageFileName = string.Empty;
string _signerFullName = string.Empty;
string _signerPosition = string.Empty;
string _signaturePlace = string.Empty;
bool _isLoggingOut = false;
bool _isSubmittingSignature = false;
bool _submitConfirmVisible = false;
string? _submitErrorMessage;
string? _capturedSignatureDateText;
readonly HashSet<int> _appliedSignatureFieldIndexes = [];
int? _currentSignatureNavFieldIndex;
PersistingComponentStateSubscription? _persistingSubscription;
// ----- Share popup state -----
bool _sharePopupVisible = false;
bool _isSharing = false;
string _shareReceiverMail = string.Empty;
DateTime _shareDateValid = DateTime.Today.AddDays(7);
string? _shareMessage;
bool _shareMessageIsError = false;
// ----- Reject popup state -----
bool _rejectPopupVisible = false;
bool _isRejectSubmitting = false;
string _rejectReason = string.Empty;
string? _rejectValidationMessage;
async Task LogoutAsync()
{
if (_isLoggingOut || string.IsNullOrWhiteSpace(EnvelopeKey))
return;
_isLoggingOut = true;
await InvokeAsync(StateHasChanged);
try
{
await AuthService.LogoutEnvelopeReceiverAsync(EnvelopeKey);
}
catch (Exception ex)
{
Logger.LogWarning(ex, "Receiver logout failed for {EnvelopeKey}", EnvelopeKey);
}
Navigation.NavigateTo($"/envelope/login/{Uri.EscapeDataString(EnvelopeKey)}", forceLoad: true);
}
void OpenSharePopup()
{
_shareReceiverMail = string.Empty;
_shareDateValid = DateTime.Today.AddDays(7);
_shareMessage = null;
_shareMessageIsError = false;
_sharePopupVisible = true;
}
void CloseSharePopup()
{
if (_isSharing)
return;
_sharePopupVisible = false;
}
void OnShareDateChanged(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
if (DateTime.TryParse(args.Value?.ToString(), out var parsedDate))
_shareDateValid = parsedDate.Date;
}
async Task ShareEnvelopeAsync()
{
if (_isSharing)
return;
var email = _shareReceiverMail.Trim();
if (string.IsNullOrWhiteSpace(email) || !new EmailAddressAttribute().IsValid(email))
{
_shareMessage = "Bitte geben Sie eine gultige E-Mail-Adresse ein.";
_shareMessageIsError = true;
return;
}
var minDate = DateTime.Today.AddDays(1);
var maxDate = DateTime.Today.AddDays(90);
if (_shareDateValid.Date < minDate || _shareDateValid.Date > maxDate)
{
_shareMessage = "Bitte wahlen Sie ein Datum zwischen morgen und 90 Tagen.";
_shareMessageIsError = true;
return;
}
_isSharing = true;
_shareMessage = null;
_shareMessageIsError = false;
await InvokeAsync(StateHasChanged);
try
{
_shareMessage = "Freigabe ist in dieser Ansicht derzeit nicht verfugbar.";
_shareMessageIsError = false;
}
catch (Exception ex)
{
Logger.LogError(ex, "Failed to share envelope {EnvelopeKey}", EnvelopeKey);
_shareMessage = "Freigabe fehlgeschlagen. Bitte versuchen Sie es erneut.";
_shareMessageIsError = true;
}
finally
{
_isSharing = false;
await InvokeAsync(StateHasChanged);
}
}
// ----- Lifecycle -----
protected override async Task OnInitializedAsync()
{
_persistingSubscription ??= PersistentComponentState.RegisterOnPersisting(PersistInitialStateAsync);
if (TryRestoreInitialState())
return;
if (string.IsNullOrWhiteSpace(EnvelopeKey))
{
_errorMessage = "Envelope-Schlüssel fehlt.";
_isLoading = false;
return;
}
if (EnvelopeKey.TryDecode(out var decodedKeys) && decodedKeys.GetEncodeType() == EncodeType.EnvelopeReceiverReadOnly)
{
Navigation.NavigateTo($"/envelope/readonly/{Uri.EscapeDataString(EnvelopeKey)}", forceLoad: true);
return;
}
if (!await AuthService.CheckEnvelopeAccessAsync(EnvelopeKey))
{
Navigation.NavigateTo($"/envelope/login/{Uri.EscapeDataString(EnvelopeKey)}");
return;
}
try
{
_pdfBytes = await DocumentService.GetDocumentAsync(EnvelopeKey);
if (_pdfBytes is not { Length: > 0 })
{
_errorMessage = "Dokument konnte nicht geladen werden: Keine Daten empfangen.";
_isLoading = false;
return;
}
_signatures = (await SignatureService.GetAsync(EnvelopeKey)).Convert(UnitOfLength.Point);
_envelopeReceiver = await EnvelopeReceiverService.GetAsync(EnvelopeKey);
if (_envelopeReceiver is null)
Logger.LogWarning("Envelope receiver data is null for {EnvelopeKey}", EnvelopeKey);
else if (IsRejected(_envelopeReceiver))
{
Navigation.NavigateTo($"/envelope/{Uri.EscapeDataString(EnvelopeKey)}/rejected", forceLoad: true);
return;
}
_displayPdfBytes = _pdfBytes;
_pagePreviews = (await PdfRenderService.RenderPagesAsync(_displayPdfBytes))
.OrderBy(p => p.PageNumber)
.ToList();
_pageCount = _pagePreviews.Count > 0 ? _pagePreviews.Count : 1;
_activeSignatureTab = SignatureTabDraw;
_signaturePopupVisible = false;
_popupValidationMessage = null;
EnsureActiveNavigableField();
}
catch (Exception ex)
{
_errorMessage = $"Fehler beim Laden des Dokuments: {ex.Message}";
Logger.LogError(ex, "Unexpected error for {EnvelopeKey}", EnvelopeKey);
}
_isLoading = false;
await InvokeAsync(StateHasChanged);
}
bool TryRestoreInitialState()
{
if (string.IsNullOrWhiteSpace(EnvelopeKey))
return false;
var stateKey = InitialStateKeyPrefix + EnvelopeKey;
if (!PersistentComponentState.TryTakeFromJson<ReceiverPageInitialState>(stateKey, out var state) || state is null)
return false;
_envelopeReceiver = state.EnvelopeReceiver;
_signatures = state.Signatures ?? [];
_displayPdfBytes = state.DisplayPdfBytes;
_pagePreviews = state.PagePreviews ?? [];
_pageCount = state.PageCount > 0 ? state.PageCount : (_pagePreviews.Count > 0 ? _pagePreviews.Count : 1);
_errorMessage = null;
_isLoading = false;
EnsureActiveNavigableField();
return true;
}
Task PersistInitialStateAsync()
{
if (_isLoading || !string.IsNullOrWhiteSpace(_errorMessage) || string.IsNullOrWhiteSpace(EnvelopeKey))
return Task.CompletedTask;
var state = new ReceiverPageInitialState
{
EnvelopeReceiver = _envelopeReceiver,
Signatures = _signatures.ToList(),
DisplayPdfBytes = _displayPdfBytes,
PagePreviews = _pagePreviews,
PageCount = _pageCount
};
PersistentComponentState.PersistAsJson(InitialStateKeyPrefix + EnvelopeKey, state);
return Task.CompletedTask;
}
// ----- Report builder -----
static bool IsRejected(EnvelopeReceiverDto envelopeReceiver)
{
var status = (EnvelopeStatus?)envelopeReceiver.Envelope?.Status;
if (status is EnvelopeStatus.DocumentRejected or EnvelopeStatus.EnvelopeRejected)
return true;
return false;
}
// ----- Signature popup handlers -----
void OpenSignaturePopup(bool keepPendingField = false)
{
if (!keepPendingField)
_pendingSignatureFieldIndex = null;
_activeSignatureTab = _capturedSignature is null ? SignatureTabDraw : _lastSavedSignatureTab;
_signaturePopupVisible = true;
_popupValidationMessage = null;
}
void OpenSubmitConfirmPopup()
{
if (_capturedSignature is null || _isSubmittingSignature)
return;
if (!AllSignatureFieldsApplied)
{
_submitErrorMessage = "Bitte klicken Sie auf jedes Unterschrift-Feld im Dokument.";
return;
}
_submitErrorMessage = null;
_submitConfirmVisible = true;
}
async Task OnSignatureFieldClickAsync(int fieldIndex)
{
if (_isSubmittingSignature)
return;
if (_capturedSignature is null)
{
_currentSignatureNavFieldIndex = fieldIndex;
_pendingSignatureFieldIndex = fieldIndex;
OpenSignaturePopup(keepPendingField: true);
return;
}
if (fieldIndex < 0 || fieldIndex >= _signatures.Count)
return;
if (_appliedSignatureFieldIndexes.Add(fieldIndex))
await InvokeAsync(StateHasChanged);
}
Task GoToNextSignatureAsync()
{
var indexes = NavigableSignatureIndexes;
if (indexes.Count == 0)
return Task.CompletedTask;
if (!_currentSignatureNavFieldIndex.HasValue || !indexes.Contains(_currentSignatureNavFieldIndex.Value))
{
_currentSignatureNavFieldIndex = indexes[0];
return InvokeAsync(StateHasChanged);
}
var currentIndex = indexes.IndexOf(_currentSignatureNavFieldIndex.Value);
_currentSignatureNavFieldIndex = indexes[(currentIndex + 1) % indexes.Count];
return InvokeAsync(StateHasChanged);
}
Task GoToPreviousSignatureAsync()
{
var indexes = NavigableSignatureIndexes;
if (indexes.Count == 0)
return Task.CompletedTask;
if (!_currentSignatureNavFieldIndex.HasValue || !indexes.Contains(_currentSignatureNavFieldIndex.Value))
{
_currentSignatureNavFieldIndex = indexes[0];
return InvokeAsync(StateHasChanged);
}
var currentIndex = indexes.IndexOf(_currentSignatureNavFieldIndex.Value);
_currentSignatureNavFieldIndex = indexes[(currentIndex - 1 + indexes.Count) % indexes.Count];
return InvokeAsync(StateHasChanged);
}
async Task OnPopupShownAsync()
{
await InitializeActiveSignatureTabAsync();
await RestoreDrawSignatureIfAvailableAsync();
await RestoreImageSignatureIfAvailableAsync();
}
async Task SetSignatureTabAsync(string tab)
{
if (_activeSignatureTab == tab)
return;
await ClearSignatureTabStateAsync(_activeSignatureTab);
_activeSignatureTab = tab;
_popupValidationMessage = null;
await InvokeAsync(StateHasChanged);
await Task.Delay(50);
await InitializeActiveSignatureTabAsync();
await RestoreDrawSignatureIfAvailableAsync();
await RestoreImageSignatureIfAvailableAsync();
}
async Task ClearSignatureTabStateAsync(string tab)
{
if (tab == SignatureTabDraw)
{
await JSRuntime.InvokeVoidAsync("receiverSignature.clear", DrawCanvasId);
}
else if (tab == SignatureTabText)
{
_typedSignatureText = string.Empty;
await JSRuntime.InvokeVoidAsync("receiverSignature.clearTyped", TypedCanvasId);
}
else if (tab == SignatureTabImage)
{
_savedImageFileName = string.Empty;
await JSRuntime.InvokeVoidAsync("receiverSignature.clearImage", ImageInputId, ImageCanvasId);
}
}
async Task RestoreDrawSignatureIfAvailableAsync()
{
if (_activeSignatureTab != SignatureTabDraw ||
_capturedSignature is null ||
_lastSavedSignatureTab != SignatureTabDraw)
return;
await JSRuntime.InvokeVoidAsync("receiverSignature.loadExistingSignature", DrawCanvasId, _capturedSignature.DataUrl);
}
async Task RestoreImageSignatureIfAvailableAsync()
{
if (_activeSignatureTab != SignatureTabImage ||
_capturedSignature is null ||
_lastSavedSignatureTab != SignatureTabImage)
return;
await JSRuntime.InvokeVoidAsync("receiverSignature.loadExistingImageSignature", ImageCanvasId, _capturedSignature.DataUrl);
}
async Task InitializeActiveSignatureTabAsync()
{
if (_activeSignatureTab == SignatureTabDraw)
await JSRuntime.InvokeVoidAsync("receiverSignature.initialize", DrawCanvasId);
else if (_activeSignatureTab == SignatureTabText)
{
await JSRuntime.InvokeVoidAsync("receiverSignature.initializeTyped", TypedCanvasId);
await RenderTypedSignatureAsync();
}
else
await JSRuntime.InvokeVoidAsync("receiverSignature.initializeImage", ImageInputId, ImageCanvasId);
}
async Task RenewSignatureAsync()
{
_popupValidationMessage = null;
if (_activeSignatureTab == SignatureTabDraw)
await JSRuntime.InvokeVoidAsync("receiverSignature.clear", DrawCanvasId);
else if (_activeSignatureTab == SignatureTabText)
{
_typedSignatureText = string.Empty;
await JSRuntime.InvokeVoidAsync("receiverSignature.clearTyped", TypedCanvasId);
}
else
{
_savedImageFileName = string.Empty;
await JSRuntime.InvokeVoidAsync("receiverSignature.clearImage", ImageInputId, ImageCanvasId);
}
}
async Task OnTypedSignatureChanged(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
_typedSignatureText = args.Value?.ToString() ?? string.Empty;
await RenderTypedSignatureAsync();
}
async Task OnTypedSignatureFontChanged(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
_typedSignatureFont = args.Value?.ToString() ?? _typedSignatureFont;
await RenderTypedSignatureAsync();
}
async Task RenderTypedSignatureAsync()
{
await JSRuntime.InvokeVoidAsync("receiverSignature.renderTypedSignature",
TypedCanvasId, _typedSignatureText, _typedSignatureFont);
}
async Task SaveSignatureAsync()
{
var hadExistingSignature = _capturedSignature is not null;
if (string.IsNullOrWhiteSpace(_signerFullName))
{
_popupValidationMessage = "Bitte geben Sie Vor- und Nachname ein.";
return;
}
if (string.IsNullOrWhiteSpace(_signaturePlace))
{
_popupValidationMessage = "Bitte geben Sie den Ort ein.";
return;
}
var signatureDataUrl = await GetActiveSignatureDataUrlAsync();
if (string.IsNullOrWhiteSpace(signatureDataUrl))
{
_popupValidationMessage = "Die Unterschrift ist erforderlich.";
return;
}
_popupValidationMessage = null;
_capturedSignature = new SignatureCaptureDto
{
DataUrl = signatureDataUrl,
FullName = _signerFullName.Trim(),
Position = _signerPosition.Trim(),
Place = _signaturePlace.Trim(),
};
_capturedSignatureDateText = DateTime.Now.ToString("dd.MM.yyyy");
if (_activeSignatureTab == SignatureTabImage)
{
var selectedImageFileName = await JSRuntime.InvokeAsync<string?>("receiverSignature.getSelectedImageFileName", ImageInputId);
if (!string.IsNullOrWhiteSpace(selectedImageFileName))
_savedImageFileName = selectedImageFileName;
}
else
_savedImageFileName = string.Empty;
_lastSavedSignatureTab = _activeSignatureTab;
if (!hadExistingSignature)
{
_appliedSignatureFieldIndexes.Clear();
if (_pendingSignatureFieldIndex is int pendingFieldIndex &&
pendingFieldIndex >= 0 &&
pendingFieldIndex < _signatures.Count)
{
_appliedSignatureFieldIndexes.Add(pendingFieldIndex);
_currentSignatureNavFieldIndex = pendingFieldIndex;
}
}
else
EnsureActiveNavigableField();
_pendingSignatureFieldIndex = null;
_submitErrorMessage = null;
_signaturePopupVisible = false;
await InvokeAsync(StateHasChanged);
}
bool SignaturePopupVisible
{
get => _signaturePopupVisible;
set
{
_signaturePopupVisible = value;
if (!value)
_pendingSignatureFieldIndex = null;
}
}
async Task SubmitAndLogoutAsync()
{
if (_isSubmittingSignature)
return;
if (string.IsNullOrWhiteSpace(EnvelopeKey) || _capturedSignature is null)
return;
_isSubmittingSignature = true;
_submitConfirmVisible = false;
_submitErrorMessage = null;
await InvokeAsync(StateHasChanged);
try
{
if (_signatures.Count == 0)
throw new InvalidOperationException("No signature fields found for receiver.");
var payload = _signatures.Select(field => new SignatureSubmitDto
{
Id = field.Id,
DataUrl = _capturedSignature.DataUrl,
FullName = _capturedSignature.FullName,
Position = string.IsNullOrWhiteSpace(_capturedSignature.Position) ? null : _capturedSignature.Position,
Place = _capturedSignature.Place
}).ToList();
await SignatureService.SubmitAsync(EnvelopeKey, payload);
await AuthService.LogoutEnvelopeReceiverAsync(EnvelopeKey);
Navigation.NavigateTo("/envelope/signed-result", forceLoad: true);
}
catch (Exception ex)
{
Logger.LogError(ex, "Failed to finalize signature for {EnvelopeKey}", EnvelopeKey);
_submitErrorMessage = "Die Unterschrift konnte nicht abgeschlossen werden. Bitte versuchen Sie es erneut.";
_isSubmittingSignature = false;
await InvokeAsync(StateHasChanged);
}
}
void OpenRejectPopup()
{
_rejectValidationMessage = null;
_rejectPopupVisible = true;
}
void CloseRejectPopup()
{
if (_isRejectSubmitting)
return;
_rejectPopupVisible = false;
}
async Task SubmitRejectAsync()
{
if (_isRejectSubmitting)
return;
_isRejectSubmitting = true;
_rejectValidationMessage = null;
await InvokeAsync(StateHasChanged);
try
{
var reason = string.IsNullOrWhiteSpace(_rejectReason)
? null
: _rejectReason.Trim();
if (string.IsNullOrWhiteSpace(EnvelopeKey))
{
_rejectValidationMessage = "Envelope-Schluessel fehlt.";
_isRejectSubmitting = false;
await InvokeAsync(StateHasChanged);
return;
}
await AnnotationService.RejectAsync(EnvelopeKey, reason);
Navigation.NavigateTo($"/envelope/login/{Uri.EscapeDataString(EnvelopeKey)}", forceLoad: true);
}
catch (Exception ex)
{
Logger.LogError(ex, "Failed to reject envelope {EnvelopeKey}", EnvelopeKey);
_rejectValidationMessage = "Die Ablehnung konnte nicht gespeichert werden. Bitte versuchen Sie es erneut.";
_isRejectSubmitting = false;
await InvokeAsync(StateHasChanged);
}
}
async Task<string?> GetActiveSignatureDataUrlAsync()
{
if (_activeSignatureTab == SignatureTabDraw)
return await JSRuntime.InvokeAsync<string?>("receiverSignature.getDataUrl", DrawCanvasId);
if (_activeSignatureTab == SignatureTabText)
{
await RenderTypedSignatureAsync();
return await JSRuntime.InvokeAsync<string?>("receiverSignature.getTypedDataUrl", TypedCanvasId);
}
return await JSRuntime.InvokeAsync<string?>("receiverSignature.getImageDataUrl", ImageCanvasId);
}
string L(string key, string fallback)
{
var value = UiLocalizer[key];
return value.ResourceNotFound ? fallback : value.Value;
}
void EnsureActiveNavigableField()
{
var indexes = NavigableSignatureIndexes;
if (indexes.Count == 0)
{
_currentSignatureNavFieldIndex = null;
return;
}
if (_currentSignatureNavFieldIndex.HasValue && indexes.Contains(_currentSignatureNavFieldIndex.Value))
return;
_currentSignatureNavFieldIndex = indexes[0];
}
public void Dispose()
{
_persistingSubscription?.Dispose();
_persistingSubscription = null;
}
sealed class ReceiverPageInitialState
{
public EnvelopeReceiverDto? EnvelopeReceiver { get; set; }
public List<SignatureDto> Signatures { get; set; } = [];
public byte[]? DisplayPdfBytes { get; set; }
public List<PdfPageImageDto> PagePreviews { get; set; } = [];
public int PageCount { get; set; }
}
}