From c76ddb71230e360a858a3ad0515e6042400c9f10 Mon Sep 17 00:00:00 2001 From: TekH Date: Sun, 7 Jun 2026 17:24:48 +0200 Subject: [PATCH] Refactor `getSignatureNavState` for robustness Updated `getSignatureNavState` to handle cases where the global signature list (`_allSignatures`) is unavailable or empty by introducing an early return with a default state. Revised the logic to calculate `total`, `signed`, and `unsigned` using the global signature list, simplifying the `currentIndex` calculation to use the `signed` count. Updated `canGoPrev` and `canGoNext` to reflect the presence of signed or unsigned signatures. Removed outdated logic relying on `signatureButtons` and added Turkish comments to clarify the new implementation. --- .../wwwroot/js/pdf-viewer.js | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/EnvelopeGenerator.ReceiverUI/wwwroot/js/pdf-viewer.js b/EnvelopeGenerator.ReceiverUI/wwwroot/js/pdf-viewer.js index cc5267d5..33beb6f1 100644 --- a/EnvelopeGenerator.ReceiverUI/wwwroot/js/pdf-viewer.js +++ b/EnvelopeGenerator.ReceiverUI/wwwroot/js/pdf-viewer.js @@ -462,23 +462,30 @@ window.pdfViewer = { * @returns {object} { total, signed, unsigned, currentIndex, canGoPrev, canGoNext } */ getSignatureNavState() { - const total = this.signatureButtons.length + this.appliedSignatures.length; - const signed = this.appliedSignatures.length; - const unsigned = this.signatureButtons.length; - - // Find index of first unsigned signature button (if any) - let currentIndex = -1; - if (unsigned > 0) { - currentIndex = signed; // 0-based index of next signature to sign + // Global imza listesi yoksa bo? state dön + if (!this._allSignatures || this._allSignatures.length === 0) { + return { + total: 0, + signed: 0, + unsigned: 0, + currentIndex: -1, + canGoPrev: false, + canGoNext: false + }; } + // TÜM sayfalardaki imzalar? say (database'den gelen global liste) + const total = this._allSignatures.length; // Global: Toplam imza say?s? + const signed = this.appliedSignatures.length; // ?mzalananlar + const unsigned = total - signed; // Hesaplanan: ?mzalanmayanlar + return { total: total, signed: signed, unsigned: unsigned, - currentIndex: currentIndex, - canGoPrev: signed > 0, // Can go to previous applied signature - canGoNext: unsigned > 0 // Can go to next unsigned signature + currentIndex: signed, // Sonraki imzan?n index'i + canGoPrev: signed > 0, // En az 1 imza uygulanm?? m?? + canGoNext: unsigned > 0 // Hala imzalanmam?? var m?? }; },