Enhance signature field handling in PDF editor
Added a `FieldClick` parameter to `SenderPdfImageEditor` to handle field click events. Introduced `OnFieldClickAsync` to invoke the `FieldClick` callback. Updated `ReceiverPage.razor` to bind `FieldClick` to `OnSignatureFieldClickAsync`. Enhanced signature application workflow by tracking applied fields with `_appliedSignatureFieldIndexes` and managing pending fields with `_pendingSignatureFieldIndex`. Added `AllSignatureFieldsApplied` to validate submission readiness. Updated `VisibleFieldOverlays` and `SignedOverlays` to reflect applied fields. Refactored signature popup logic with `SignaturePopupVisible` for better state management. Improved submission validation to ensure all fields are signed before allowing submission. Various minor adjustments to improve user experience and state handling.
This commit is contained in:
@@ -122,19 +122,22 @@
|
||||
@* Unterschreiben button — visible only when signature fields exist *@
|
||||
@if (_signatures.Count > 0)
|
||||
{
|
||||
<button class="pdf-toolbar__btn pdf-toolbar__btn--signature-change pdf-toolbar__btn--signature-change-active"
|
||||
@onclick="OpenSignaturePopup"
|
||||
title="@(_capturedSignature is null ? "Unterschreiben" : "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">@(_capturedSignature is null ? "Unterschreiben" : "Unterschrift andern")</span>
|
||||
</button>
|
||||
@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)"
|
||||
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">
|
||||
@@ -207,6 +210,7 @@
|
||||
PdfFileName="@PdfFileName"
|
||||
Fields="@VisibleFieldOverlays"
|
||||
SignatureOverlays="@SignedOverlays"
|
||||
FieldClick="OnSignatureFieldClickAsync"
|
||||
ShowFieldRemoveButton="false" />
|
||||
}
|
||||
</div>
|
||||
@@ -265,7 +269,7 @@
|
||||
</DxPopup>
|
||||
|
||||
@* Signature Popup *@
|
||||
<DxPopup @bind-Visible="_signaturePopupVisible"
|
||||
<DxPopup @bind-Visible="SignaturePopupVisible"
|
||||
HeaderText="Unterschrift erstellen"
|
||||
Width="640px"
|
||||
MaxWidth="95vw"
|
||||
@@ -460,16 +464,19 @@
|
||||
.Select((s, i) => new SenderPdfFieldOverlay(i, s.Page, s.X, s.Y, "UNTERSCHRIFT", "#4F46E5"))
|
||||
.ToList();
|
||||
|
||||
IReadOnlyList<SenderPdfFieldOverlay> VisibleFieldOverlays => _capturedSignature is null
|
||||
? FieldOverlays
|
||||
: Array.Empty<SenderPdfFieldOverlay>();
|
||||
IReadOnlyList<SenderPdfFieldOverlay> VisibleFieldOverlays => FieldOverlays
|
||||
.Where(field => !_appliedSignatureFieldIndexes.Contains(field.Index))
|
||||
.ToList();
|
||||
|
||||
IReadOnlyList<SenderPdfSignatureOverlay> SignedOverlays => _capturedSignature is null
|
||||
? Array.Empty<SenderPdfSignatureOverlay>()
|
||||
: _signatures.Select(s => new SenderPdfSignatureOverlay(
|
||||
s.Page,
|
||||
s.X,
|
||||
s.Y,
|
||||
: _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,
|
||||
@@ -477,6 +484,8 @@
|
||||
_capturedSignatureDateText ?? DateTime.Now.ToString("dd.MM.yyyy")))
|
||||
.ToList();
|
||||
|
||||
bool AllSignatureFieldsApplied => _signatures.Count > 0 && _appliedSignatureFieldIndexes.Count == _signatures.Count;
|
||||
|
||||
string? PdfDataUrl => _displayPdfBytes is { Length: > 0 }
|
||||
? $"data:application/pdf;base64,{Convert.ToBase64String(_displayPdfBytes)}"
|
||||
: null;
|
||||
@@ -486,6 +495,7 @@
|
||||
// ----- Signature popup state -----
|
||||
SignatureCaptureDto? _capturedSignature;
|
||||
bool _signaturePopupVisible = false;
|
||||
int? _pendingSignatureFieldIndex;
|
||||
string? _popupValidationMessage;
|
||||
string _activeSignatureTab = SignatureTabDraw;
|
||||
string _lastSavedSignatureTab = SignatureTabDraw;
|
||||
@@ -500,6 +510,7 @@
|
||||
bool _submitConfirmVisible = false;
|
||||
string? _submitErrorMessage;
|
||||
string? _capturedSignatureDateText;
|
||||
readonly HashSet<int> _appliedSignatureFieldIndexes = [];
|
||||
|
||||
// ----- Share popup state -----
|
||||
bool _sharePopupVisible = false;
|
||||
@@ -690,8 +701,11 @@
|
||||
}
|
||||
|
||||
// ----- Signature popup handlers -----
|
||||
void OpenSignaturePopup()
|
||||
void OpenSignaturePopup(bool keepPendingField = false)
|
||||
{
|
||||
if (!keepPendingField)
|
||||
_pendingSignatureFieldIndex = null;
|
||||
|
||||
_activeSignatureTab = _capturedSignature is null ? SignatureTabDraw : _lastSavedSignatureTab;
|
||||
_signaturePopupVisible = true;
|
||||
_popupValidationMessage = null;
|
||||
@@ -702,10 +716,35 @@
|
||||
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)
|
||||
{
|
||||
_pendingSignatureFieldIndex = fieldIndex;
|
||||
OpenSignaturePopup(keepPendingField: true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fieldIndex < 0 || fieldIndex >= _signatures.Count)
|
||||
return;
|
||||
|
||||
if (_appliedSignatureFieldIndexes.Add(fieldIndex))
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
async Task OnPopupShownAsync()
|
||||
{
|
||||
await InitializeActiveSignatureTabAsync();
|
||||
@@ -817,6 +856,8 @@
|
||||
|
||||
async Task SaveSignatureAsync()
|
||||
{
|
||||
var hadExistingSignature = _capturedSignature is not null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_signerFullName))
|
||||
{
|
||||
_popupValidationMessage = "Bitte geben Sie Vor- und Nachname ein.";
|
||||
@@ -855,10 +896,34 @@
|
||||
_savedImageFileName = string.Empty;
|
||||
|
||||
_lastSavedSignatureTab = _activeSignatureTab;
|
||||
if (!hadExistingSignature)
|
||||
{
|
||||
_appliedSignatureFieldIndexes.Clear();
|
||||
if (_pendingSignatureFieldIndex is int pendingFieldIndex &&
|
||||
pendingFieldIndex >= 0 &&
|
||||
pendingFieldIndex < _signatures.Count)
|
||||
{
|
||||
_appliedSignatureFieldIndexes.Add(pendingFieldIndex);
|
||||
}
|
||||
}
|
||||
|
||||
_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)
|
||||
|
||||
Reference in New Issue
Block a user