Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1491 [RiskAssessmentDocument] add: riskassessmentdocument generation information modal #3962

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

113 changes: 107 additions & 6 deletions js/modules/document.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* Initialise l'objet "signature" ainsi que la méthode "init" obligatoire pour la bibliothèque DigiriskDolibarr.
* Initialise l'objet "document" ainsi que la méthode "init" obligatoire pour la bibliothèque DigiriskDolibarr.
*
* @since 1.1.0
* @version 1.1.0
Expand Down 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,101 @@ 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'));
};

// Fonction pour faire défiler vers le bas
window.digiriskdolibarr.document.scrollToBottom = function( ) {
const modalContent = $('.modal-content');
modalContent.animate({ scrollTop: modalContent.prop("scrollHeight") }, 100);
}

// Appeler la fonction de défilement
window.digiriskdolibarr.document.generateDocument = async function (generationUrl, documentGeneratedText) {
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|Projet/)[0].trim()
const documentName = $(data).find('#builddoc_form').find('.documentdownload').first().text()
const textToShow = documentGeneratedText + ' : ' + digiriskElementRef + ' => ' + documentName
window.digiriskdolibarr.document.scrollToBottom()
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 documentGeneratedText = $('#documentGeneratedText').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, documentGeneratedText)
completedElements++;
const progress = Math.floor((completedElements / totalElements) * 100);
$("#progressbar .ui-progressbar-value").animate({ width: progress + "%" }, 500);

}
}

const riskassessmentdocumentPage = await window.digiriskdolibarr.document.generateDocument(riskAssessmentDocumentUrl, documentGeneratedText)
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");
}

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());
}
1 change: 1 addition & 0 deletions langs/fr_FR/digiriskdolibarr.lang
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +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
DocumentGenerated = Document généré

# Boxes - Widget
LastGenerateDate = DU généré le
Expand Down
Loading