diff --git a/public/style/signature.css b/public/style/signature.css index 6e3d5ce..702f7a0 100755 --- a/public/style/signature.css +++ b/public/style/signature.css @@ -1518,4 +1518,103 @@ input[type="file"] { .sign-button:disabled { background-color: #cccccc; cursor: not-allowed; +} + +.modal-document { + background: white; + border-radius: 8px; + max-width: 800px; + width: 90%; + max-height: 75vh; + overflow-y: auto; + position: relative; +} + +.document-details { + padding: 20px; +} + +.info-section { + margin: 20px 0; + background: #f8f9fa; + padding: 15px; + border-radius: 6px; +} + +.info-row { + display: flex; + justify-content: space-between; + margin-bottom: 10px; +} + +.label { + font-weight: bold; + color: #666; +} + +.description-section { + margin: 20px 0; +} + +.signatures-section { + margin: 20px 0; +} + +.signature-item { + display: flex; + justify-content: space-between; + padding: 8px; + border-bottom: 1px solid #eee; +} + +.signature-item.signed { + background-color: #e8f5e9; +} + +.signature-item.pending { + background-color: #fff3e0; +} + +.files-section { + margin: 20px 0; +} + +.file-item { + display: flex; + align-items: center; + padding: 8px; + background: #f8f9fa; + margin-bottom: 5px; + border-radius: 4px; +} + +.file-icon { + margin-right: 10px; +} + +.download-link { + margin-left: auto; +} + +.confirmation-section { + margin-top: 30px; + text-align: center; +} + +.warning-text { + color: #f44336; + margin-bottom: 15px; +} + +.sign-confirm-btn { + background-color: #4CAF50; + color: white; + padding: 10px 20px; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.sign-confirm-btn:hover { + background-color: #45a049; } \ No newline at end of file diff --git a/src/pages/signature/signature.ts b/src/pages/signature/signature.ts index 7fc6e14..70d76cc 100755 --- a/src/pages/signature/signature.ts +++ b/src/pages/signature/signature.ts @@ -14,6 +14,7 @@ declare global { submitNewDocument: typeof submitNewDocument; submitCommonDocument: typeof submitCommonDocument; signDocument: typeof signDocument; + confirmSignature: typeof confirmSignature; } } @@ -586,9 +587,9 @@ function showProcessDetails(group: Group, groupId: number) {
${sig.member.name} - ${sig.signed ? - `✓ Signed on ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'Unknown date'}` : - '⌛ Pending'} + ${sig.signed ? + `✓ Signé le ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'date inconnue'}` : + '⌛ En attente'}
`).join('')} @@ -657,8 +658,8 @@ function showProcessDetails(group: Group, groupId: number) { ${sig.member.name} ${sig.signed ? - `✓ Signed on ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'Unknown date'}` : - ' Pending'} + `✓ Signé le ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'date inconnue'}` : + '⌛ En attente'} `).join('')} @@ -819,8 +820,8 @@ function showRoleDocuments(role: { ${sig.member.name} ${sig.signed ? - `✓ Signed on ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'Unknown date'}` : - '⌛ Pending'} + `✓ Signé le ${sig.signedAt ? new Date(sig.signedAt).toLocaleDateString() : 'date inconnue'}` : + '⌛ En attente'} `).join('')} @@ -1462,6 +1463,122 @@ interface SignatureResponse { // Ajouter cette fonction pour signer un document function signDocument(documentId: number, processId: number, isCommonDocument: boolean = false) { + if (typeof window === 'undefined' || typeof document === 'undefined') { + console.error('Cette fonction ne peut être exécutée que dans un navigateur'); + return; + } + + try { + const groups = JSON.parse(localStorage.getItem('groups') || JSON.stringify(groupsMock)); + const group = groups.find((g: Group) => g.id === processId); + + if (!group) { + throw new Error('Processus non trouvé'); + } + + let targetDoc; + if (isCommonDocument) { + targetDoc = group.commonDocuments.find((d: any) => d.id === documentId); + } else { + for (const role of group.roles) { + if (role.documents) { + targetDoc = role.documents.find((d: any) => d.id === documentId); + if (targetDoc) break; + } + } + } + + if (!targetDoc) { + throw new Error('Document non trouvé'); + } + + // Créer et insérer la modal directement dans le body + const modalHtml = ` + `; + + document.body.insertAdjacentHTML('beforeend', modalHtml); + + } catch (error) { + console.error('Erreur lors de l\'affichage de la modal:', error); + showAlert(error instanceof Error ? error.message : 'Erreur lors de l\'affichage de la modal'); + } +} + +// Nouvelle fonction pour confirmer la signature +function confirmSignature(documentId: number, processId: number, isCommonDocument: boolean) { try { const groups = JSON.parse(localStorage.getItem('groups') || JSON.stringify(groupsMock)); const group = groups.find((g: Group) => g.id === processId); @@ -1471,20 +1588,13 @@ function signDocument(documentId: number, processId: number, isCommonDocument: b } let document; - let documentList; - if (isCommonDocument) { - documentList = group.commonDocuments; document = group.commonDocuments.find((d: any) => d.id === documentId); } else { - // Chercher dans les documents des rôles for (const role of group.roles) { if (role.documents) { document = role.documents.find((d: any) => d.id === documentId); - if (document) { - documentList = role.documents; - break; - } + if (document) break; } } } @@ -1493,7 +1603,6 @@ function signDocument(documentId: number, processId: number, isCommonDocument: b throw new Error('Document non trouvé'); } - // Trouver la signature correspondant à l'utilisateur courant const userSignature = document.signatures.find((sig: DocumentSignature) => sig.member.name === currentUser.name ); @@ -1502,18 +1611,13 @@ function signDocument(documentId: number, processId: number, isCommonDocument: b throw new Error('Signature non trouvée pour cet utilisateur'); } - if (userSignature.signed) { - throw new Error('Document déjà signé par cet utilisateur'); - } - - // Mettre à jour la signature userSignature.signed = true; userSignature.signedAt = new Date().toISOString(); - // Sauvegarder les modifications localStorage.setItem('groups', JSON.stringify(groups)); - // Rafraîchir l'affichage + closeModal(document.querySelector('.close-btn')); + if (isCommonDocument) { showProcessDetails(group, processId); } else { @@ -1524,48 +1628,18 @@ function signDocument(documentId: number, processId: number, isCommonDocument: b } showAlert('Document signé avec succès!'); - return { - success: true, - message: 'Document signé avec succès', - documentId, - memberId: currentUser.id, - signedAt: userSignature.signedAt - }; } catch (error) { console.error('Erreur lors de la signature:', error); showAlert(error instanceof Error ? error.message : 'Erreur lors de la signature'); - return { - success: false, - message: error instanceof Error ? error.message : 'Erreur lors de la signature', - documentId, - memberId: currentUser.id, - signedAt: '' - }; } } -// Modifier la fonction qui génère les cartes de documents pour ajouter le bouton de signature -function generateDocumentCard(document: any, isCommonDocument: boolean = false) { - // ... code existant de la carte ... - - // Ajouter le bouton de signature si l'utilisateur n'a pas encore signé - const userSignature = document.signatures?.find((sig: DocumentSignature) => - sig.member?.name === currentUser?.name - ); - - const signatureButton = !userSignature?.signed ? ` - - ` : ''; - return ` -
- // ... reste du code de la carte ... - ${signatureButton} -
- `; -} - -// Ajouter la fonction au scope global +window.confirmSignature = confirmSignature; window.signDocument = signDocument; + +// S'assurer que la fonction est disponible globalement +if (typeof window !== 'undefined') { + (window as any).signDocument = signDocument; + (window as any).confirmSignature = confirmSignature; +}