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

Correction : gestion js de l'ajout d'une condition

Correction : var par let
parent 827cd88d
......@@ -142,8 +142,8 @@
<script type="text/javascript">
$(document).ready(function () {
var idContainer = null;
var idFieldConditionCreated = null;
let idContainer = null;
let idFieldConditionCreated = null;
// $('#btn-condition').click(function () {
$('#btn-condition-formulaire, #btn-condition-coresponsable, #btn-condition-soustraitant').click(function () {
......@@ -165,8 +165,8 @@
}
$(idContainer).find('.draggable').filter('.checkboxes, .radios, .deroulant, .multi-select').each(function (key, field) {
var name = $(field).find('input, option').attr('name');
var label = $(field).find('.labeler').html();
let name = $(field).find('input, option').attr('name');
let label = $(field).find('.labeler').html();
if (name && label) {
$('#ifTheField').append('<option value="' + name + '">' + label + '</option>');
......@@ -182,13 +182,11 @@
if (!idFieldConditionCreated) {
hideAllFields();
} else {
var options = null;
if (jQuery.inArray(idFieldConditionCreated, ['transfert_hors_ue', 'donnees_sensibles']) !== -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();
let option = $(this).attr('value');
let label = $(this).text();
if (option && label) {
$('#hasValue').append('<option value="' + option + '">' + label + '</option>');
......@@ -198,8 +196,8 @@
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
if ($('#'+idFieldConditionCreated).is("select")) {
$(idContainer).find('input[name ="'+idFieldConditionCreated+'"],option[name ="'+idFieldConditionCreated+'"]').each(function () {
var value = $(this).attr('value');
var labelValue = $(this).text();
let value = $(this).attr('value');
let labelValue = $(this).text();
if (value && labelValue) {
$('#hasValue').append('<option value="' + value + '">' + labelValue + '</option>');
......@@ -207,16 +205,19 @@
});
} else {
$(idContainer).find('input[name ="'+idFieldConditionCreated+'"], option[name ="'+idFieldConditionCreated+'"]').each(function () {
let option = null;
let id = null;
if ($(this).attr('type') == 'checkbox') {
var option = $(this).next('label').text();
option = $(this).next('label').text();
} else {
var option = $(this).attr('value');
option = $(this).attr('value');
}
if ($(this).attr('type') == 'radio') {
var id = $(this).attr('value');
id = $(this).attr('value');
} else {
var id = $(this).attr('id');
id = $(this).attr('id');
}
if (option && id) {
......@@ -228,26 +229,29 @@
$('#hasValue').parent().parent().show();
}
});
$('#hasValue').change(function () {
var valueSelected = $(this).val();
let valueSelected = $(this).val();
if (!valueSelected) {
$('#thenTheField').parent().parent().hide();
$('#thenTheField option').not(':first').remove();
$('#thenTheField').parent().parent().hide();
$('#thenTheField option').not(':first').remove();
$('#mustBe').parent().parent().hide();
} else {
var fieldsContainer = $(idContainer).find('.draggable');
$('#mustBe').parent().parent().hide();
$('#mustBe').val('');
$('#ifNot').parent().parent().hide();
$('#ifNot').val('');
if (valueSelected) {
let fieldsContainer = $(idContainer).find('.draggable');
if (!fieldsContainer) {
return false;
}
$.each(fieldsContainer, function (key, field) {
var name = $(field).find('input, textarea, option').attr('name');
var label = $(field).find('.labeler').html();
let name = $(field).find('input, textarea, option').attr('name');
let label = $(field).find('.labeler').html();
if (name && label) {
if (name != idFieldConditionCreated) {
......@@ -261,7 +265,7 @@
});
$('#thenTheField').change(function () {
var val = $(this).val();
let val = $(this).val();
if (!val) {
$('#mustBe').parent().parent().hide();
......@@ -275,7 +279,7 @@
});
$('#mustBe').change(function () {
var mustBeValue = $(this).val();
let mustBeValue = $(this).val();
if (!mustBeValue) {
$('#ifNot').parent().parent().hide();
......@@ -296,12 +300,12 @@
$('#saveCondition').click(function () {
$('div.error-message').remove();
var ifTheField = $('#ifTheField').val();
var hasValue = $('#hasValue').val();
var thenTheField = $('#thenTheField').val();
var mustBe = $('#mustBe').val();
var ifNot = $('#ifNot').val();
var success = true;
let ifTheField = $('#ifTheField').val();
let hasValue = $('#hasValue').val();
let thenTheField = $('#thenTheField').val();
let mustBe = $('#mustBe').val();
let ifNot = $('#ifNot').val();
let success = true;
if (!ifTheField) {
$('#ifTheField').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
......@@ -340,15 +344,15 @@
'ifNot' : ifNot
};
var conditions = {};
let conditions = {};
conditions[uuidv4()] = objCondition;
var idContainer = '#' + $('.form-container').attr('id');
let idContainer = '#' + $('.form-container').attr('id');
// On selectionne le champs qui va recevoir la condition
var fieldChoose = $(idContainer).find('input[name ="' + thenTheField + '"], textarea[name ="' + thenTheField + '"], option[name ="' + thenTheField + '"]').closest('.draggable');
let fieldChoose = $(idContainer).find('input[name ="' + thenTheField + '"], textarea[name ="' + thenTheField + '"], option[name ="' + thenTheField + '"]').closest('.draggable');
var otherConditions = $(fieldChoose).attr('data-virtual-conditions');
let otherConditions = $(fieldChoose).attr('data-virtual-conditions');
if (otherConditions) {
$.each(JSON.parse(otherConditions), function (key, value) {
conditions[key] = value
......
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