Skip to content

Commit

Permalink
#1491 [RiskAssessmentDocument] add: riskassessmentdocument generation…
Browse files Browse the repository at this point in the history
… information modal
  • Loading branch information
theodaviddd committed Jun 8, 2024
1 parent 40db4f5 commit c2e6819
Show file tree
Hide file tree
Showing 7 changed files with 581 additions and 427 deletions.
2 changes: 1 addition & 1 deletion css/digiriskdolibarr.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/scss/modal/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "photo";
@import "evaluator";
@import "riskassessment";
@import "riskassessmentdocument-modal";

.wpeo-modal .modal-container {
ul, li {
Expand Down
27 changes: 27 additions & 0 deletions css/scss/modal/_riskassessmentdocument-modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#generationStatus li {
display: flex;
align-items: center;
margin-left: 15px;
}

#progressbar {
margin: 20px;
}

#progressbar .ui-progressbar-value {
background-color: #966ea2;
width: 0;
}

#generationStatus, .loader, .modal-container h2 {
margin-left: 15px;
}

.loader {
margin-right: 15px;
}

.new-document {
color: green;
}

2 changes: 1 addition & 1 deletion js/digiriskdolibarr.min.js

Large diffs are not rendered by default.

105 changes: 100 additions & 5 deletions js/modules/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ window.digiriskdolibarr.document.buttonSignature;
* @return {void}
*/
window.digiriskdolibarr.document.init = function() {
window.digiriskdolibarr.document.event();
window.digiriskdolibarr.document.event();
};

/**
Expand All @@ -44,11 +44,16 @@ window.digiriskdolibarr.document.init = function() {
* @return {void}
*/
window.digiriskdolibarr.document.event = function() {
$( document ).on( 'click', '#builddoc_generatebutton', window.digiriskdolibarr.document.displayLoader );
$( document ).on( 'click', '.pdf-generation', window.digiriskdolibarr.document.displayLoader );
$( document ).on( 'click', '.send-risk-assessment-document-by-mail', window.digiriskdolibarr.document.displayLoader );
$( document ).on( 'click', '#builddoc_generatebutton', window.digiriskdolibarr.document.displayLoader );
$( document ).on( 'click', '.riskassessmentdocument-generation #builddoc_generatebutton', window.digiriskdolibarr.document.showAdvancementModal );
$( document ).on( 'click', '.pdf-generation', window.digiriskdolibarr.document.displayLoader );
$( document ).on( 'click', '.send-risk-assessment-document-by-mail', window.digiriskdolibarr.document.displayLoader );
$("#progressbar").progressbar({
value: 0
});
};


/**
* Display loader on generation document.
*
Expand All @@ -58,5 +63,95 @@ window.digiriskdolibarr.document.event = function() {
* @return {void}
*/
window.digiriskdolibarr.document.displayLoader = function( ) {
window.saturne.loader.display($(this).closest('.div-table-responsive-no-min'));
window.saturne.loader.display($(this).closest('.div-table-responsive-no-min'));
};

window.digiriskdolibarr.document.generateDocument = async function (generationUrl) {
const token = window.saturne.toolbox.getToken()

return await $.ajax({
url : generationUrl,
type: 'POST',
data: {
token: token
}
}).done(function(data) {
$('.wpeo-loader').removeClass('wpeo-loader')
$('.loader').html('<i class="fas fa-check" style="color: green"></i>')
const digiriskElementText = $(data).find('.refid').text()
const digiriskElementRef = digiriskElementText.split("Description")[0].trim();
const documentName = $(data).find('#builddoc_form').find('.documentdownload').first().text();
const textToShow = 'Document généré : ' + digiriskElementRef + ' => ' + documentName
window.digiriskdolibarr.document.updateModal(textToShow)
return data
});
}

window.digiriskdolibarr.document.showAdvancementModal = async function () {
event.preventDefault()

const modal = $('#generationModal')
modal.addClass('modal-active')

$('.new-document').remove()

const groupmentUrl = $('#groupmentUrl').val()
const riskAssessmentDocumentUrl = $('#riskAssessmentDocumentUrl').val()

const digiriskElementIds = $('#digiriskElementIds').val()
const digiriskElementIdsArray = digiriskElementIds.split(',')

const totalElements = digiriskElementIdsArray.length + 1;
let completedElements = 0;

for (let i = 0; i<digiriskElementIdsArray.length; i++) {
const id = digiriskElementIdsArray[i]
if (id > 0) {
await window.digiriskdolibarr.document.generateDocument(groupmentUrl + '&id=' + id)
completedElements++;
const progress = Math.floor((completedElements / totalElements) * 100);
$("#progressbar .ui-progressbar-value").animate({ width: progress + "%" }, 500);

}
}

const riskassessmentdocumentPage = await window.digiriskdolibarr.document.generateDocument(riskAssessmentDocumentUrl)
completedElements++;
const progress = Math.floor((completedElements / totalElements) * 100);
$("#progressbar .ui-progressbar-value").animate({ width: progress + "%" }, 500);

setTimeout(() => {
$("#progressbar .ui-progressbar-value").animate({ width: "100%" }, 500);
$('.wpeo-loader').removeClass('wpeo-loader')
$('.loader').html('<i class="fas fa-check" style="color: green"></i>')
}, "1000")

setTimeout(() => {
modal.removeClass('modal-active');
modal.find('.modal-container ul').html('');
$("#progressbar .ui-progressbar-value").width(0);
}, "2000");

setTimeout(() => {
$('#builddoc_form').html($(riskassessmentdocumentPage).find('#builddoc_form'))

var elements = $('#builddoc_form').find('.oddeven .minwidth200 a');
const newDocumentDiv = '<span class="new-document">&nbsp;&nbsp;&nbsp;<i class="fas fa-bolt"></i> Nouveau !</span>'
elements.eq(0).append(newDocumentDiv);
elements.eq(1).append(newDocumentDiv);
}, "2000");



// afficher la notice
}

window.digiriskdolibarr.document.updateModal = function (text) {
var statusList = document.getElementById("generationStatus");
var newStatus = document.createElement("li");

newStatus.innerHTML = '<div class="loader"></div>' + text;
statusList.appendChild(newStatus);

window.saturne.loader.display($(newStatus).find('.loader').last());
}
2 changes: 1 addition & 1 deletion langs/fr_FR/digiriskdolibarr.lang
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ RiskAssessmentDocumentImportantNote = Notes importantes :<
GenerateZipArchiveWithDigiriskElementDocuments = Génération d'une archive ZIP avec le Document Unique
GenerateZipArchiveWithDigiriskElementDocumentsDescription = Génération automatique d'une archive ZIP contenant le Document Unique et toutes les fiches de poste lors de la génération du Document Unique
RiskAssessmentDocumentDescription = Plan d'action Document Unique

RiskAssessmentDocumentGeneration = Génération du Document Unique
# Boxes - Widget
LastGenerateDate = DU généré le
NextGenerateDate = Prochain DU le
Expand Down
Loading

0 comments on commit c2e6819

Please sign in to comment.