Commit d202dfd8 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Modification : renommer nom + id des champs

Correction : suppression des options et affichage des champs en fonction de la réponse précédente
Ajout : des champs "transfertHorsUe" et "donneesSensible" (permanent) afin de pouvoir crée des conditions etant à l'origine. dans ce cas la condition est ajouter un champ cible
parent 2ac71299
......@@ -256,14 +256,17 @@ msgstr "Avez-vous déposer dans l'onglet annexe l'analyse d'impact (AIPD) ?"
###############################################################################
msgid "formulaire.champIfTheLadelField"
msgid "formulaire.champIfTheField"
msgstr "Si le champ"
msgid "formulaire.champHasAsValue"
msgid "formulaire.champHasValue"
msgstr "a comme valeur"
msgid "formulaire.champThenTheField"
msgstr "alors le champ"
msgid "formulaire.champMustBe"
msgstr "doit être"
\ No newline at end of file
msgstr "doit être"
msgid "formulaire.champIfNot"
msgstr "sinon il sera"
\ No newline at end of file
......@@ -22,9 +22,12 @@
<div class="row form-group">
<?php
echo $this->WebcilForm->input('ifTheLadelField', [
'id' => 'ifTheLadelField',
'options' => [],
echo $this->WebcilForm->input('ifTheField', [
'id' => 'ifTheField',
'options' => [
'transfertHorsUe' => 'Les données du traitement, font l\'objet d\'un transfert hors l\'UE ?',
'donneesSensible' => 'Les données traitées sont qualifiées de \'données sensibles\' ?'
],
'empty' => true,
'class' => 'transformSelect form-control',
'placeholder' => false,
......@@ -36,8 +39,8 @@
<div class="row form-group">
<?php
echo $this->WebcilForm->input('hasAsValue', [
'id' => 'hasAsValue',
echo $this->WebcilForm->input('hasValue', [
'id' => 'hasValue',
'options' => [],
'empty' => true,
'class' => 'transformSelect form-control',
......@@ -67,13 +70,32 @@
echo $this->WebcilForm->input('mustBe', [
'id' => 'mustBe',
'options' => [
'show' => "afficher",
'hide' => "cacher"
'shown' => "afficher",
'hidden' => "cacher"
],
'empty' => true,
'class' => 'transformSelect form-control',
'placeholder' => false,
'required' => true,
'data-placeholder' => ' '
]);
?>
</div>
<div class="row form-group">
<?php
echo $this->WebcilForm->input('ifNot', [
'id' => 'ifNot',
'options' => [
'shown' => "afficher",
'hidden' => "cacher"
],
'empty' => true,
'class' => 'transformSelect form-control',
'placeholder' => false,
'required' => true,
'readonly' => true,
'disabled' => true,
'data-placeholder' => ' '
]);
?>
......@@ -110,12 +132,16 @@
$('#btn-condition').click(function () {
hideAllFields();
$('#ifTheField option').slice(3).remove();
idContainer = '#' + $('.form-container').attr('id');
if (!idContainer) {
return false;
}
$(idContainer).find('.ui-selected').removeClass('ui-selected');
$('.field-options >div').remove();
var allFields = $(idContainer).find('.draggable').filter('.checkboxes, .radios, .deroulant, .multi-select');
if (!allFields) {
return false;
......@@ -125,34 +151,54 @@
var name = $(field).find('input, option').attr('name');
var label = $(field).find('.labeler').html();
$('#ifTheLadelField').append('<option value="'+name+'">'+label+'</option>');
if (name && label) {
$('#ifTheField').append('<option value="' + name + '">' + label + '</option>');
}
});
});
$('#ifTheLadelField').change(function () {
$('#ifTheField').change(function () {
hideAllFields();
idFieldConditionCreated = $(this).val();
if (!idFieldConditionCreated) {
hideAllFields();
} else {
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$(idContainer).find('input[name ="'+idFieldConditionCreated+'"], option[name ="'+idFieldConditionCreated+'"]').each(function () {
var option = $(this).attr('value');
if (option) {
$('#hasAsValue').append('<option value="' + option + '">' + option + '</option>');
}
});
var options = null;
if (jQuery.inArray(idFieldConditionCreated, ['transfertHorsUe', 'donneesSensible']) !== -1){
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$('#'+idFieldConditionCreated).find('option').each(function () {
var option = $(this).attr('value');
var label = $(this).text();
if (option && label) {
$('#hasValue').append('<option value="' + option + '">' + label + '</option>');
}
});
} else {
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$(idContainer).find('input[name ="'+idFieldConditionCreated+'"], option[name ="'+idFieldConditionCreated+'"]').each(function () {
var option = $(this).attr('value');
if (option) {
$('#hasValue').append('<option value="' + option + '">' + option + '</option>');
}
});
}
$('#hasAsValue').parent().parent().show();
$('#hasValue').parent().parent().show();
}
});
$('#hasAsValue').change(function () {
$('#hasValue').change(function () {
var valueSelected = $(this).val();
if (!valueSelected) {
$('#thenTheField').parent().parent().hide();
$('#thenTheField option').not(':first').remove();
$('#mustBe').parent().parent().hide();
} else {
var fieldsContainer = $(idContainer).find('.draggable');
......@@ -178,27 +224,50 @@
if (!val) {
$('#mustBe').parent().parent().hide();
$('#mustBe').val('');
$('#ifNot').parent().parent().hide();
$('#ifNot').val('');
} else {
$('#mustBe').parent().parent().show();
}
});
$('#mustBe').change(function () {
var mustBeValue = $(this).val();
if (!mustBeValue) {
$('#ifNot').parent().parent().hide();
$('#ifNot').val('');
} else {
if (mustBeValue == 'shown') {
$('#ifNot').val('hidden');
}
if (mustBeValue == 'hidden') {
$('#ifNot').val('shown');
}
$('#ifNot').parent().parent().show();
}
});
$('#saveCondition').click(function () {
$('div.error-message').remove();
var ifTheNameField = $('#ifTheLadelField').val();
var hasAsValue = $('#hasAsValue').val();
var ifTheField = $('#ifTheField').val();
var hasValue = $('#hasValue').val();
var thenTheField = $('#thenTheField').val();
var mustBe = $('#mustBe').val();
var success = true;
if (!ifTheNameField) {
$('#ifTheLadelField').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
if (!ifTheField) {
$('#ifTheField').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
success = false;
}
if (!hasAsValue) {
$('#hasAsValue').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
if (!hasValue) {
$('#hasValue').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
success = false;
}
......@@ -217,8 +286,8 @@
}
objCondition = {
'ifTheNameField' : ifTheNameField,
'hasAsValue' : hasAsValue,
'ifTheField' : ifTheField,
'hasValue' : hasValue,
'thenTheField' : thenTheField,
'mustBe' : mustBe
};
......@@ -228,7 +297,13 @@
var idContainer = '#' + $('.form-container').attr('id');
var fieldChoose = $(idContainer).find('input[name ="'+idFieldConditionCreated+'"], option[name ="'+idFieldConditionCreated+'"]').closest('.draggable');
var fieldChoose = null;
if (jQuery.inArray(idFieldConditionCreated, ['transfertHorsUe', 'donneesSensible']) !== -1){
fieldChoose = $(idContainer).find('input[name ="' + thenTheField + '"], option[name ="' + thenTheField + '"]').closest('.draggable');
} else {
fieldChoose = $(idContainer).find('input[name ="' + idFieldConditionCreated + '"], option[name ="' + idFieldConditionCreated + '"]').closest('.draggable');
}
var otherConditions = $(fieldChoose).attr('data-virtual-conditions');
if (otherConditions) {
$.each(JSON.parse(otherConditions), function (key, value) {
......@@ -240,22 +315,29 @@
$('#modalAddCondtion').modal('toggle');
});
$('#modalAddCondtion').on('hidden.bs.modal', function () {
hideAllFields();
$('#ifTheField option').slice(3).remove();
})
});
function hideAllFields()
{
$('#hasAsValue').parent().parent().hide();
$('#hasValue').parent().parent().hide();
$('#thenTheField').parent().parent().hide();
$('#mustBe').parent().parent().hide();
$('#ifNot').parent().parent().hide();
removeValuesAllFields();
}
function removeValuesAllFields()
{
$('#ifTheLadelField').not(':first').remove();
$('#hasAsValue option').not(':first').remove();
$('#hasValue option').not(':first').remove();
$('#thenTheField option').not(':first').remove();
$('#mustBe').val('');
$('#ifNot').val('');
}
function uuidv4() {
......
......@@ -82,6 +82,7 @@
'readonly' => true
],
'Fiche.transfertHorsUe' => [
'id' => 'transfertHorsUe',
'options' => [
true => 'Oui',
false => 'Non'
......@@ -94,6 +95,7 @@
'data-placeholder' => ' '
],
'Fiche.donneesSensible' => [
'id' => 'donneesSensible',
'options' => [
true => 'Oui',
false => 'Non'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment