Skip to content

Commit

Permalink
Evarisk#1540 [Control] add: auto save action question answer
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Sep 13, 2023
1 parent 32a1d6d commit 68a7cee
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 21 deletions.
16 changes: 14 additions & 2 deletions admin/control.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,18 @@
print '</td>';
print '</tr>';

// Auto-save action on question answer
print '<tr><td>';
print $langs->trans('AutoSaveActionQuestionAnswer');
print '</td><td>';
print $langs->trans('AutoSaveActionQuestionAnswerDescription');
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION');
print '</td>';
print '</tr>';

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update_public_survey_title">';
Expand All @@ -417,7 +429,7 @@
print '</td>';

print '<td class="center">';
print ajax_constantonoff('SHOW_QC_FREQUENCY_PUBLIC_INTERFACE');
print ajax_constantonoff('DIGIQUALI_ENABLE_PUBLIC_CONTROL_HISTORY');
print '</td>';
print '</tr>';

Expand All @@ -428,7 +440,7 @@
print '</td>';

print '<td class="center">';
print ajax_constantonoff('DIGIQUALI_ENABLE_PUBLIC_CONTROL_HISTORY');
print ajax_constantonoff('DIGIQUALI_SHOW_QC_FREQUENCY_PUBLIC_INTERFACE');
print '</td>';
print '</tr>';

Expand Down
3 changes: 3 additions & 0 deletions core/modules/modDigiQuali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public function __construct($db)

// CONST CONTROL LINE
$i++ => ['DIGIQUALI_CONTROLDET_ADDON', 'chaine', 'mod_controldet_standard', '', 0, 'current'],
$i++ => ['DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION', 'integer', 1, '', 0, 'current'],

// CONST CONTROL EQUIPMENT
$i++ => ['DIGIQUALI_CONTROL_EQUIPMENT_ADDON', 'chaine', 'mod_control_equipment_standard', '', 0, 'current'],

// CONST MODULE
Expand Down
10 changes: 5 additions & 5 deletions core/tpl/digiquali_control_answers.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$item = $question;
$item->fetch($questionId);
?>
<div class="wpeo-table table-flex table-3 table-id-<?php echo $item->id ?>">
<div class="wpeo-table table-flex table-3 table-id-<?php echo $item->id ?>" data-publicInterface="<?php echo $publicInterface; ?>" data-autoSave="<?php echo getDolGlobalInt('DIGIQUALI_CONTROLDET_AUTO_SAVE_ACTION'); ?>">
<div class="table-row">
<!-- Contenu et commentaire -->
<div class="table-cell table-full">
Expand Down Expand Up @@ -88,7 +88,7 @@
<?php if ($item->type == 'MultipleChoices') :
$answerList = $answer->fetchAll('ASC', 'position', 0, 0, ['customsql' => 't.status > ' . Answer::STATUS_DELETED . ' AND t.fk_question = ' . $item->id]);
?>
<div class="table-cell table-end select-answer answer-cell" <?php echo ($object->status > 0) ? ' style="pointer-events: none"' : '' ?>>
<div class="table-cell table-end select-answer answer-cell" <?php echo ($object->status > 0) ? ' style="pointer-events: none"' : '' ?> data-questionId="<?php echo $item->id; ?>">
<?php
if (preg_match('/,/', $questionAnswer)) {
$questionAnswers = preg_split('/,/', $questionAnswer);
Expand All @@ -114,7 +114,7 @@
<?php elseif ($item->type == 'UniqueChoice' || $item->type == 'OkKo' || $item->type == 'OkKoToFixNonApplicable') :
$answerList = $answer->fetchAll('ASC', 'position', 0, 0, ['customsql' => 't.status > ' . Answer::STATUS_DELETED . ' AND t.fk_question = ' . $item->id]);
?>
<div class="table-cell table-end select-answer answer-cell <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>">
<div class="table-cell table-end select-answer answer-cell <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>" data-questionId="<?php echo $item->id; ?>">
<?php
print '<input type="hidden" class="question-answer" name="answer'. $item->id .'" id="answer'. $item->id .'" value="0">';
if (is_array($answerList) && !empty($answerList)) {
Expand All @@ -132,7 +132,7 @@
?>
</div>
<?php elseif ($item->type == 'Percentage') : ?>
<div class="table-cell table-end answer-cell table-flex <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>">
<div class="table-cell table-end answer-cell table-flex <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>" data-questionId="<?php echo $item->id; ?>">
<?php
print '<span class="table-cell" value="">';
print $langs->transnoentities('Answer') . ' : ';
Expand All @@ -143,7 +143,7 @@
?>
</div>
<?php elseif ($item->type == 'Range') : ?>
<div class="table-cell table-end answer-cell table-flex <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>">
<div class="table-cell table-end answer-cell table-flex <?php echo ($object->status > 0) ? 'style="pointer-events: none"' : '' ?>" data-questionId="<?php echo $item->id; ?>">
<?php
print '<span class="table-cell" value="">';
print $langs->transnoentities('Answer') . ' : ';
Expand Down
27 changes: 23 additions & 4 deletions core/tpl/digiquali_control_answers_save_action.tpl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

if ($action == 'save') {
$data = json_decode(file_get_contents('php://input'), true);

$controldet = new ControlLine($db);
$sheet->fetch($object->fk_sheet);
$object->fetchObjectLinked($sheet->id, 'digiquali_sheet', '', '', 'OR', 1, 'sourcetype', 0);
Expand All @@ -14,14 +16,22 @@
if ($result > 0 && is_array($result)) {
$controldettmp = array_shift($result);
//sauvegarder réponse
$questionAnswer = GETPOST('answer'.$questionId);
if ($data['autoSave'] && $questionId == $data['questionId']) {
$questionAnswer = $data['answer'];
} else {
$questionAnswer = GETPOST('answer' . $questionId);
}

if (!empty($questionAnswer)) {
$controldettmp->answer = $questionAnswer;
}

//sauvegarder commentaire
$comment = GETPOST('comment'.$questionId);
if ($data['autoSave'] && $questionId == $data['questionId']) {
$comment = $data['comment'];
} else {
$comment = GETPOST('comment' . $questionId);
}

if (dol_strlen($comment) > 0) {
$controldettmp->comment = $comment;
Expand All @@ -38,7 +48,11 @@
$controldettmp->fk_question = $questionId;

//sauvegarder réponse
$questionAnswer = GETPOST('answer'.$questionId);
if ($data['autoSave'] && $questionId == $data['questionId']) {
$questionAnswer = $data['answer'];
} else {
$questionAnswer = GETPOST('answer' . $questionId);
}

if (!empty($questionAnswer)) {
$controldettmp->answer = $questionAnswer;
Expand All @@ -47,7 +61,12 @@
}

//sauvegarder commentaire
$comment = GETPOST('comment'.$questionId);
if ($data['autoSave'] && $questionId == $data['questionId']) {
$comment = $data['comment'];
} else {
$comment = GETPOST('comment' . $questionId);
}

if (dol_strlen($comment) > 0) {
$controldettmp->comment = $comment;
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/tpl/digiquali_public_control.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<table class="centpercent" style="background: rgba(0,0,0,.05); padding: 10px;">
<tr><td class="tdoverflowmax200" style="min-width: 125px;">
<?php print img_picto('', $linkableObject['picto'], 'class="pictofixedwidth"') . $objectName . '<br><i class="far fa-check-circle pictofixedwidth"></i>' . $langs->trans('VerdictObject'); ?>
<?php if ($linkedObject->array_options['options_qc_frequency'] > 0 && getDolGlobalInt('SHOW_QC_FREQUENCY_PUBLIC_INTERFACE')) {
<?php if ($linkedObject->array_options['options_qc_frequency'] > 0 && getDolGlobalInt('DIGIQUALI_SHOW_QC_FREQUENCY_PUBLIC_INTERFACE')) {
print '<br>' . $langs->transnoentities('QcFrequency') . ' : ' . $linkedObject->array_options['options_qc_frequency'];
} ?>
</td>
Expand Down
2 changes: 1 addition & 1 deletion js/digiquali.min.js

Large diffs are not rendered by default.

50 changes: 46 additions & 4 deletions js/modules/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ window.digiquali.control.event = function() {
* @return {void}
*/
window.digiquali.control.selectAnswer = function ( event ) {
let answerValue = $(this).hasClass('answer') ? $(this).attr('value') : $(this).val()
let answer = '';
let questionElement = $(this).closest('.select-answer.answer-cell')
let questionElement = $(this).closest('.select-answer.answer-cell');
let questionId = questionElement.attr('data-questionId');
let publicInterface = $(this).closest('.table-id-' + questionId).attr('data-publicInterface');
let autoSave = $(this).closest('.table-id-' + questionId).attr('data-autoSave');
let answer = '';
let answerValue = $(this).hasClass('answer') ? $(this).attr('value') : $(this).val();
let comment = $(this).closest('.table-id-' + questionId).find('#comment' + questionId).val();
if ($(this).closest('.table-cell').hasClass('select-answer')) {
if ($(this).hasClass('multiple-answers')) {
$(this).closest('span').toggleClass( 'active' );
Expand All @@ -78,7 +82,11 @@ window.digiquali.control.selectAnswer = function ( event ) {
$(this).closest('.answer-cell').find('.question-answer').val(answer)
}

window.digiquali.control.updateButtonsStatus()
if (!publicInterface && autoSave == 1 && !$(this).hasClass('multiple-answers')) {
window.digiquali.control.saveAnswer(questionId, answer, comment);
} else {
window.digiquali.control.updateButtonsStatus()
}
};

/**
Expand Down Expand Up @@ -347,3 +355,37 @@ window.digiquali.control.showOnlyQuestionsWithNoAnswer = function() {
error: function() {}
});
};

/**
* Save answer after click event
*
* @since 1.9.0
* @version 1.9.0
*
* @param {int} questionId Question ID
* @param {string} answer Answer value
* @param {string} comment Comment value
* @return {void}
*/
window.digiquali.control.saveAnswer = function(questionId, answer, comment) {
let token = window.saturne.toolbox.getToken();
let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL);
window.saturne.loader.display($('.table-id-' + questionId));

$.ajax({
url: document.URL + querySeparator + 'action=save&token=' + token,
type: "POST",
data: JSON.stringify({
autoSave: true,
questionId: questionId,
answer: answer,
comment: comment
}),
processData: false,
contentType: false,
success: function(resp) {
$('.table-id-' + questionId).replaceWith($(resp).find('.table-id-' + questionId));
},
error: function() {}
});
};
10 changes: 6 additions & 4 deletions langs/fr_FR/digiquali.lang
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ ShowQcFrequencyPublicInterfaceDescription = Option permettant l'affichage l
#

# Data - Donnée
AnswerSaved = Les réponses ont été sauvegardées
Repair = SAV
NotApplicable = NA
AnswerPhoto = Photo
AnswerSaved = Les réponses ont été sauvegardées
Repair = SAV
NotApplicable = NA
AnswerPhoto = Photo
AutoSaveActionQuestionAnswer = Sauvegarde automatique des réponses aux questions
AutoSaveActionQuestionAnswerDescription = Sauvegarde automatiquement les réponses aux questions lors du choix de la réponse

#
# ControlDocument - Fiche de Contrôle
Expand Down

0 comments on commit 68a7cee

Please sign in to comment.