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.
This commit is contained in:
2026-06-07 17:24:48 +02:00
parent 80690d3d54
commit c76ddb7123

View File

@@ -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??
};
},