Skip to content

Commit e9a7d11

Browse files
committed
Evarisk#1680 [Control] add: control answers & lock
1 parent 847658c commit e9a7d11

File tree

7 files changed

+113
-26
lines changed

7 files changed

+113
-26
lines changed

core/tpl/digiquali_mass_control_list.tpl.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
}
3737
print '</div>';
3838

39+
$mainControlId = $object->id;
3940
// Check if there are any mass controls and print them
4041
if (is_array($massControlList) && !empty($massControlList)) {
4142
foreach ($massControlList as $massControl) {
43+
$object = $massControl;
44+
$massControl->fetch_optionals();
45+
$massControl->fetchLines();
4246
// Fetch the public note if it exists
4347

4448
print '<div class="table-row sub-control-'. $massControl->id .'">';
@@ -62,28 +66,55 @@
6266
print '<div class="table-cell center"><textarea type="text" class="note-public">' . $massControl->note_public . '</textarea></div>';
6367

6468
print '<div class="table-cell center">';
65-
print '<button class="butAction answerSubControl" data-control-id="'. $massControl->id .'">Répondre</button>';
69+
$questionCounter = 0;
70+
if (!empty($questionIds)) {
71+
$questionCounter = count($questionIds);
72+
}
73+
74+
$answerCounter = 0;
75+
if (is_array($massControl->lines) && !empty($massControl->lines)) {
76+
foreach ($massControl->lines as $massControlLine) {
77+
if (dol_strlen($massControlLine->answer) > 0) {
78+
$answerCounter++;
79+
}
80+
}
81+
}
82+
//affiche le nombre de questions répondues
83+
print '<span class="answerCounter">' . $answerCounter . '/' . $questionCounter . '</span>';
84+
print '<button class="butAction answerSubControl modal-open" data-control-id="'. $massControl->id .'">';
85+
print $langs->trans('Answers');
86+
print '<input type="hidden" class="modal-options" data-modal-to-open="modalSubControl'. $massControl->id .'">';
87+
print '</button>';
6688
print '</div>';
6789

6890
// Additional cells for QRCode, Document, and Action can be filled in as needed
6991
print '<div class="table-cell center">'. saturne_show_medias_linked('digiquali', $conf->digiquali->multidir_output[$conf->entity] . '/control/' . $massControl->ref . '/qrcode/', 'small', 1, 0, 0, 0, 80, 80, 0, 0, 0, 'control/' . $massControl->ref . '/qrcode/', $massControl, '', 0, 0) . '</div>';
7092
print '<div class="table-cell center">';
7193
print '</div>';
7294
print '<div class="table-cell center">';
73-
$displayButton = $onPhone ? '<i class="fas fa-check fa-2x"></i>' : '<i class="fas fa-check"></i>' . ' ' . $langs->trans('Save');
74-
print '<span class="saveSubControl butAction" id="actionButtonSaveSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $object->id .'">' . $displayButton . '</span>';
75-
print '</div>';
95+
if ($massControl->verdict > 0 && $answerCounter == $questionCounter) {
96+
$displayButton = $onPhone ? '<i class="fas fa-lock fa-2x"></i>' : '<i class="fas fa-lock"></i>' . ' ' . $langs->trans('Lock');
97+
print '<span class="lockSubControl butAction" id="actionButtonLockSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $mainControlId .'">' . $displayButton . '</span>';
98+
} else {
99+
$displayButton = $onPhone ? '<i class="fas fa-check fa-2x"></i>' : '<i class="fas fa-check"></i>' . ' ' . $langs->trans('Save');
100+
print '<span class="saveSubControl butAction" id="actionButtonSaveSubControl" data-control-id="'. $massControl->id .'" data-mass-control-id="'. $mainControlId .'">' . $displayButton . '</span>';
101+
}
102+
76103
print '</div>';
77104

78105
print '<div class="wpeo-modal" id="modalSubControl'. $massControl->id .'">';
79106
print '<div class="modal-container">';
80107
print '<div class="modal-content">';
81-
print load_fiche_titre($langs->trans('LinkedQuestionsList'), '', '');
108+
print load_fiche_titre($langs->trans('LinkedQuestionsList') . ' - ' . $massControl->getNomUrl(1), '', '');
109+
$conf->global->DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION = 0;
82110
print '<div id="tablelines" class="question-answer-container noborder noshadow">';
83111
require __DIR__ . '/../../core/tpl/digiquali_answers.tpl.php';
84112
print '</div>';
85113
print '</div>';
86114
print '</div>';
115+
print '</div>';
116+
print '</div>';
117+
87118

88119
}
89120
} else {
@@ -92,6 +123,7 @@
92123
print '<div class="table-cell" colspan="6">' . $langs->trans('NoMassControlFound') . '</div>';
93124
print '</div>';
94125
}
126+
$object->fetch($id);
95127
print '</div>'; // End of table
96128
print '</div>'; // End of responsive container
97129
?>

core/triggers/interface_99_modDigiQuali_DigiQualiTriggers.class.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,20 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
133133
require_once __DIR__ . '/../../class/sheet.class.php';
134134
require_once __DIR__ . '/../../class/control.class.php';
135135

136+
// Load Saturne libraries.
137+
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';
138+
136139
$sheet = new Sheet($this->db);
140+
$signatory = new SaturneSignature($this->db, 'digiquali');
137141

138142
$sheet->fetch($object->fk_sheet);
139143
if ($sheet->success_rate > 0) {
140144
$object->success_rate = $sheet->success_rate;
141145
$object->setValueFrom('success_rate', $object->success_rate, '', '', 'text', '', $user);
142146
}
143147

148+
$isMassControl = $object->mass_control;
149+
144150
$elementArray = [];
145151

146152
if ($object->context != 'createfromclone') {
@@ -150,19 +156,22 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
150156
foreach ($elementArray as $linkableElementType => $linkableElement) {
151157
$post = GETPOST('multi_' . $linkableElement['post_name'], 'array');
152158
if (!empty($post) && $post > 0) {
159+
153160
foreach($post as $postElement) {
154-
if ($object->mass_control) {
161+
if ($isMassControl) {
155162
$control = new Control($this->db);
156163

157164
$control->status = $control::STATUS_DRAFT;
158165
$control->label = $object->label;
159166
$control->fk_sheet = $object->fk_sheet;
160167
$control->fk_user_controller = $object->fk_user_controller;
161168
$control->fk_control = $object->id;
162-
$control->create($user);
169+
$controlId = $control->create($user, true);
163170

171+
$control->fetch($controlId);
164172
$control->add_object_linked($linkableElement['link_name'], $postElement);
165173

174+
$signatory->setSignatory($control->id, $control->element, 'user', [$control->fk_user_controller], 'Controller', 1);
166175
} else {
167176
$object->add_object_linked($linkableElement['link_name'], $postElement);
168177
}
@@ -171,8 +180,6 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
171180
}
172181
}
173182

174-
// Load Saturne libraries.
175-
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';
176183

177184
$signatory = new SaturneSignature($this->db, 'digiquali');
178185
$signatory->setSignatory($object->id, $object->element, 'user', [$object->fk_user_controller], 'Controller', 1);

js/digiquali.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/modules/control.js

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ window.digiquali.control.event = function() {
3838
$(document).on('click', '.photo-sheet-sub-category', window.digiquali.control.getSheetSubCategoryID);
3939
$(document).on('click', '.photo-sheet', window.digiquali.control.getSheetID);
4040
$(document).on('click', '.saveSubControl', window.digiquali.control.saveSubControl);
41-
$(document).on('click', '.answerSubControl', window.digiquali.control.openAnswerModal);
41+
$(document).on('click', '.lockSubControl', window.digiquali.control.lockSubControl);
4242

4343
};
4444

@@ -328,23 +328,36 @@ window.digiquali.control.saveSubControl = function() {
328328
let massControlId = $(this).attr('data-mass-control-id');
329329
let notePublic = $(this).closest('.table-row').find('.note-public').val();
330330
// get input checked
331+
let questionIds = [];
332+
$(this).closest('.table-row').find('.select-answer').each(function() {
333+
let questionId = $(this).attr('data-questionid');
331334

332-
let verdict = $(this).closest('.table-row').find('.verdict-option input[type="radio"]:checked').val();
335+
let answer = $(this).find('.question-answer').val();
336+
let comment = $(this).closest('.wpeo-table').find('.question-comment').val();
333337

334-
let token = window.saturne.toolbox.getToken();
335-
let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL);
338+
questionIds[questionId] = {
339+
'answer': answer,
340+
'comment': comment
341+
};
342+
});
343+
344+
let verdict = $(this).closest('.table-row').find('.verdict-option input[type="radio"]:checked').val();
345+
let token = window.saturne.toolbox.getToken();
336346

337347
window.saturne.loader.display($(this).closest('.table-row'));
338-
//replace current id with subControl Id
339-
//
340348
let url = document.URL.replace(/id=\d+/, 'id=' + subControlID);
341349
$.ajax({
342350
url: url + '&token=' + token + '&action=confirm_setVerdict&verdict=' + verdict + '&noteControl=' + notePublic,
343351
type: 'POST',
344352
processData: false,
345353
contentType: false,
346354
data: [],
347-
success: function(resp) {
355+
success: async function(resp) {
356+
for (const [questionId, answer] of Object.entries(questionIds)) {
357+
let url = document.URL.replace(/id=\d+/, 'id=' + subControlID);
358+
await window.digiquali.object.saveAnswer(questionId, answer.answer, answer.comment, url + '&action=save&token=' + token);
359+
}
360+
348361
let url = document.URL.replace(/id=\d+/, 'id=' + massControlId);
349362
$.ajax({
350363
url: url,
@@ -362,15 +375,41 @@ window.digiquali.control.saveSubControl = function() {
362375
}
363376

364377
/**
365-
* Open answer modal
378+
* Lock sub control
366379
*
367380
* @since 1.10.0
368381
* @version 1.10.0
369382
*
370383
* @return {void}
371384
*/
372-
window.digiquali.control.openAnswerModal = function() {
385+
window.digiquali.control.lockSubControl = function() {
373386
let subControlID = $(this).attr('data-control-id');
374-
$('#modalSubControl' + subControlID).addClass('modal-active');
387+
let massControlId = $(this).attr('data-mass-control-id');
388+
let token = window.saturne.toolbox.getToken();
375389

376-
};
390+
window.saturne.loader.display($(this).closest('.table-row'));
391+
392+
let url = document.URL.replace(/id=\d+/, 'id=' + subControlID);
393+
$.ajax({
394+
url: url + '&token=' + token + '&action=confirm_lock',
395+
type: 'POST',
396+
processData: false,
397+
contentType: false,
398+
data: [],
399+
success: function (resp) {
400+
let url = document.URL.replace(/id=\d+/, 'id=' + massControlId);
401+
$.ajax({
402+
url: url,
403+
type: 'GET',
404+
processData: false,
405+
contentType: false,
406+
data: [],
407+
success: function (resp) {
408+
$('.sub-control-' + subControlID).replaceWith($(resp).find('.sub-control-' + subControlID));
409+
}
410+
});
411+
},
412+
error: function () {
413+
}
414+
});
415+
}

js/modules/object.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ window.digiquali.object.updateButtonsStatus = function() {
179179
* @param {int} questionId Question ID
180180
* @param {string} answer Answer value
181181
* @param {string} comment Comment value
182+
* @param {string} customUrl URL to save answer
182183
* @return {void}
183184
*/
184-
window.digiquali.object.saveAnswer = function(questionId, answer, comment) {
185+
window.digiquali.object.saveAnswer = function(questionId, answer, comment, customUrl = '') {
185186
let token = window.saturne.toolbox.getToken();
186187
let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL);
188+
let url = customUrl ? customUrl : document.URL + querySeparator + 'action=save&token=' + token
187189
window.saturne.loader.display($('.table-id-' + questionId));
188190

189191
$.ajax({
190-
url: document.URL + querySeparator + 'action=save&token=' + token,
192+
url: url,
191193
type: 'POST',
192194
data: JSON.stringify({
193195
autoSave: true,
@@ -198,7 +200,9 @@ window.digiquali.object.saveAnswer = function(questionId, answer, comment) {
198200
processData: false,
199201
contentType: false,
200202
success: function(resp) {
201-
$('.fiche').replaceWith($(resp).find('.fiche'));
203+
if (customUrl.length < 1) {
204+
$('.fiche').replaceWith($(resp).find('.fiche'));
205+
}
202206
},
203207
error: function() {}
204208
});

langs/fr_FR/digiquali.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ ShowQcFrequencyPublicInterface = Afficher la période de validé
345345
ShowQcFrequencyPublicInterfaceDescription = Option permettant l'affichage la période de validé (en jours) sur l'interface publique de contrôle
346346
GenerateSheetTags = Vous n'avez pas généré de catégories principales, veuillez cliquer ici pour vous rendre sur la page de configuration
347347
MassControl = Contrôle en masse
348+
LinkedControlList = Liste des contrôles liés
349+
NewMassControl = Nouveau contrôle en masse
348350

349351

350352
#
@@ -359,6 +361,7 @@ AnswerPhoto = Photo
359361
AutoSaveActionQuestionAnswer = Sauvegarde automatique des réponses aux questions
360362
AutoSaveActionQuestionAnswerDescription = Sauvegarde automatiquement les réponses aux questions lors du choix de la réponse
361363
NoObjectLineAnswersPhoto = Pas de photos sur les réponses du %s
364+
Answers = Réponses
362365

363366
#
364367
# ControlDocument - Fiche de Contrôle

view/sheet/sheet_card.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,11 @@
624624
if (empty($reshook) && $permissiontoadd) {
625625
// Create object depending on sheet type
626626
if ($object->status == $object::STATUS_LOCKED) {
627-
print '<a class="butAction" href="' . dol_buildpath('/custom/digiquali/view/' . $object->type . '/' . $object->type . '_card.php?action=create&fk_sheet=' . $object->id, 1) . '"><i class="fas fa-plus-circle"></i> ' . $langs->trans('New' . ucfirst($object->type)) . '</a>';
627+
print '<a class="butAction" href="' . dol_buildpath('/custom/digiquali/view/' . $object->type . '/' . $object->type . '_card.php?action=create&fk_sheet=' . $object->id, 1) . '&mass_control=1"><i class="fas fa-plus-circle"></i> ' . $langs->trans('NewMass' . ucfirst($object->type)) . '</a>';
628+
print '<a class="butAction" href="' . dol_buildpath('/custom/digiquali/view/' . $object->type . '/' . $object->type . '_card.php?action=create&fk_sheet=' . $object->id, 1) . '"><i class="fas fa-plus-circle"></i> ' . $langs->trans('New' . ucfirst($object->type)) . '</a>';
628629
} else {
629-
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeLocked', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-plus-circle"></i> ' . $langs->trans('New' . ucfirst($object->type)) . '</span>';
630+
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeLocked', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-plus-circle"></i> ' . $langs->trans('NewMass' . ucfirst($object->type)) . '</span>';
631+
print '<span class="butActionRefused classfortooltip" title="' . dol_escape_htmltag($langs->trans('ObjectMustBeLocked', ucfirst($langs->transnoentities('The' . ucfirst($object->element))))) . '"><i class="fas fa-plus-circle"></i> ' . $langs->trans('New' . ucfirst($object->type)) . '</span>';
630632
}
631633

632634
// Modify

0 commit comments

Comments
 (0)