common_button_ok
This commit is contained in:
parent
169dbf9cae
commit
6300aaba79
@ -12,6 +12,7 @@ declare global {
|
||||
closeModal: typeof closeModal;
|
||||
submitDocumentRequest: typeof submitDocumentRequest;
|
||||
submitNewDocument: typeof submitNewDocument;
|
||||
submitCommonDocument: typeof submitCommonDocument;
|
||||
}
|
||||
}
|
||||
|
||||
@ -918,7 +919,10 @@ function newRequest(params: RequestParams) {
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="cancel-btn" onclick="closeModal(this)">Cancel</button>
|
||||
<button class="confirm-btn" onclick="submitNewDocument(event)">Request</button>
|
||||
${params.roleName === 'common'
|
||||
? '<button class="confirm-btn" onclick="submitCommonDocument(event)">Request</button>'
|
||||
: '<button class="confirm-btn" onclick="submitNewDocument(event)">Request</button>'
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1103,6 +1107,69 @@ function submitNewDocument(event: Event) {
|
||||
|
||||
window.submitNewDocument = submitNewDocument;
|
||||
|
||||
function submitCommonDocument(event: Event) {
|
||||
event.preventDefault();
|
||||
|
||||
const form = document.getElementById('newDocumentForm') as HTMLFormElement;
|
||||
if (!form) {
|
||||
showAlert('Formulaire non trouvé');
|
||||
return;
|
||||
}
|
||||
|
||||
const processId = Number((form.querySelector('#processId') as HTMLInputElement)?.value);
|
||||
const documentId = Number((form.querySelector('#documentId') as HTMLInputElement)?.value);
|
||||
const documentName = (form.querySelector('#documentName') as HTMLInputElement)?.value?.trim();
|
||||
const description = (form.querySelector('#description') as HTMLTextAreaElement)?.value?.trim();
|
||||
const deadline = (form.querySelector('#deadline') as HTMLInputElement)?.value;
|
||||
const visibility = (form.querySelector('#visibility') as HTMLSelectElement)?.value;
|
||||
|
||||
if (!documentName || !description || !deadline) {
|
||||
showAlert('Veuillez remplir tous les champs obligatoires');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const groups = JSON.parse(localStorage.getItem('groups') || JSON.stringify(groupsMock));
|
||||
const group = groups.find((g: Group) => g.id === processId);
|
||||
|
||||
if (!group) {
|
||||
showAlert('Processus non trouvé');
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedDocument = {
|
||||
id: documentId,
|
||||
name: documentName,
|
||||
description: description,
|
||||
createdAt: new Date().toISOString(),
|
||||
deadline: deadline,
|
||||
visibility: visibility,
|
||||
status: "pending"
|
||||
};
|
||||
|
||||
// Mettre à jour le document commun
|
||||
const documentIndex = group.commonDocuments.findIndex((d: { id: number }) => d.id === documentId);
|
||||
if (documentIndex !== -1) {
|
||||
group.commonDocuments[documentIndex] = updatedDocument;
|
||||
}
|
||||
|
||||
localStorage.setItem('groups', JSON.stringify(groups));
|
||||
|
||||
if (event.target instanceof HTMLElement) {
|
||||
closeModal(event.target);
|
||||
}
|
||||
|
||||
showProcessDetails(group, group.id);
|
||||
showAlert('Document commun mis à jour avec succès!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de la sauvegarde:', error);
|
||||
showAlert('Une erreur est survenue lors de la sauvegarde');
|
||||
}
|
||||
}
|
||||
|
||||
window.submitCommonDocument = submitCommonDocument;
|
||||
|
||||
|
||||
function submitRequest() {
|
||||
|
||||
@ -1273,8 +1340,3 @@ export function initSignature() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user