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

Modification : lors de l'ajout des valeurs sur le champ pour la première fois...

Modification : lors de l'ajout des valeurs sur le champ pour la première fois on rend non modifiable le "nom de variable"
Ajout : début de la récupération des valeur pour la condition
parent 181497a5
......@@ -110,7 +110,65 @@ use Libriciel\Utility\Password\PasswordStrengthMeterAnssi;
$(document).ready(function () {
$('#saveCondition').click(function () {
alert('TOTO');
$('div.error-message').remove();
let ifTheNameField = $('#ifTheNameField').val();
let hasAsValue = $('#hasAsValue').val();
let thenTheField = $('#thenTheField').val();
let mustBe = $('#mustBe').val();
let objCondition = {};
let success = true;
if (!$('#ifTheLadelField').val()) {
$('#ifTheLadelField').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>');
success = false;
}
if (!thenTheField) {
$('#thenTheField').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
success = false;
}
if (!mustBe) {
$('#mustBe').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
success = false;
}
if (success == false) {
return success;
}
objCondition = {
'ifTheField' : fieldType,
'hasAsValue' : fieldLine,
'thenTheField' : fieldColumn,
'mustBe' : JSON.stringify(objFieldDetails)
};
// objCondition = {
// 'ifTheLadelField' : $('#ifTheLadelField').val(),
// 'ifTheNameField' : $('#ifTheNameField').val(),
// 'hasAsValue' : $('#hasAsValue').val(),
// 'thenTheField' : $('#thenTheField').val(),
// 'mustBe' : $('#mustBe').val()
// };
//
// $.each(objCondition, function (key, value) {
// if (!$('#ifTheLadelField').val()) {
// $('#ifTheLadelField').parent().parent().append('<div class="error-message">Champ obligatoire</div>');
// return;
// }
// });
console.log(ifTheField);
console.log(hasAsValue);
console.log(thenTheField);
console.log(mustBe);
});
});
......
......@@ -388,12 +388,6 @@ var createForm = function(typeCreateForm) {
findType = '',
fieldRepeat = '';
// Réinitialisation des champs de la modal concernant l'ajout d'une condition sur un champs
$('#ifTheNameField').val('');
$('#ifTheLadelField').val('');
$('#hasAsValue option').not(':first').remove();
$('#thenTheField option').not(':first').remove();
var btnGoupsTrashApplicable = '<div class="row">' +
'<div class="col-md-12 text-center">' +
'<div class="btn-group">' +
......@@ -527,8 +521,7 @@ var createForm = function(typeCreateForm) {
forLabelNomDuChamp = '',
idListeDesValeurs = '',
btnAddConditions = '',
showBtnAddCondition = false,
nameFieldSelected = null;
showBtnAddCondition = false;
if ( (object.hasClass('checkboxes')) || (object.hasClass('radios')) ) {
findType = 'input';
......@@ -542,47 +535,8 @@ var createForm = function(typeCreateForm) {
idListeDesValeurs = 'option-checkbox';
classListeValeur = 'checkboxForm';
nameFieldSelected = $(idContainer).find('.ui-selected').find('input').attr('name');
if (nameFieldSelected) {
// On recupere le "name" (id) du champ "selected" sur lequel nous allons faire la condition
$('#ifTheNameField').val(nameFieldSelected);
showBtnAddCondition = true;
// On recupere le "label" du champ "selected" sur lequel nous allons faire la condition
var labelCheckboxes = $(idContainer).find('.ui-selected').find('.labeler').html();
if (!labelCheckboxes) {
showBtnAddCondition = false;
} else {
$('#ifTheLadelField').val(labelCheckboxes);
}
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$(idContainer).find('.ui-selected').find('input').each(function () {
var option = $(this).attr('value');
$('#hasAsValue').append('<option value="'+option+'">'+option+'</option>');
});
// On recupere tous les champs sur lequelle nous allons pouvoir faire une condition
var allFields = $(idContainer).find('.small-text, .long-text');
$.each(allFields, function() {
var nameFieldOfForm = '';
var labelFieldOfForm = '';
if ($(this).hasClass('small-text')) {
nameFieldOfForm = $(this).find('input').attr('name');
}
if ($(this).hasClass('long-text')) {
nameFieldOfForm = $(this).find('textarea').attr('name');
}
labelFieldOfForm = $(this).find('.labeler').html();
$('#thenTheField').append('<option value="'+nameFieldOfForm+'">'+labelFieldOfForm+'</option>');
});
}
// btn conditions
showBtnAddCondition = giveValuesToModalCondition();
} else if (object.hasClass('radios')) {
champId = 'name-radios-'+typeCreateForm;
......@@ -939,6 +893,13 @@ var createForm = function(typeCreateForm) {
// $(idContainer).find('.ui-selected').attr('style', function (i, style) {
// return style.replace(/width[^;]+;?/g, '');
// });
// On rend non modifiable le nom de variable
$('#'+idbtnApplicable).closest(fieldOptions).find('input.nameForm').attr('readonly', true);
if ($(idContainer).find('.ui-selected').is('.checkboxes, .radios, .deroulant, .multi-select')) {
giveValuesToModalCondition();
}
});
/*Supprimer le champ en question au clic*/
......@@ -1083,4 +1044,58 @@ var createForm = function(typeCreateForm) {
$(idContainer).find('.ui-selected').attr('data-virtual-required', 'fieldRequired');
}
}
function giveValuesToModalCondition()
{
var success = true,
nameFieldSelected = null;
// Réinitialisation des champs de la modal concernant l'ajout d'une condition sur un champs
$('#ifTheNameField').val('');
$('#ifTheLadelField').val('');
$('#hasAsValue option').not(':first').remove();
$('#thenTheField option').not(':first').remove();
nameFieldSelected = $(idContainer).find('.ui-selected').find('input').attr('name');
if (nameFieldSelected) {
// On recupere le "name" (id) du champ "selected" sur lequel nous allons faire la condition
$('#ifTheNameField').val(nameFieldSelected);
// On recupere le "label" du champ "selected" sur lequel nous allons faire la condition
var labelCheckboxes = $(idContainer).find('.ui-selected').find('.labeler').html();
if (!labelCheckboxes) {
success = false;
} else {
$('#ifTheLadelField').val(labelCheckboxes);
}
// On recupere les "options" du champ "selected" sur lequel nous allons faire la condition
$(idContainer).find('.ui-selected').find('input').each(function () {
var option = $(this).attr('value');
$('#hasAsValue').append('<option value="'+option+'">'+option+'</option>');
});
// On recupere tous les champs sur lequelle nous allons pouvoir faire une condition
var allFields = $(idContainer).find('.small-text, .long-text');
$.each(allFields, function() {
var nameFieldOfForm = '';
var labelFieldOfForm = '';
if ($(this).hasClass('small-text')) {
nameFieldOfForm = $(this).find('input').attr('name');
}
if ($(this).hasClass('long-text')) {
nameFieldOfForm = $(this).find('textarea').attr('name');
}
labelFieldOfForm = $(this).find('.labeler').html();
$('#thenTheField').append('<option value="'+nameFieldOfForm+'">'+labelFieldOfForm+'</option>');
});
}
return success;
}
};
\ No newline at end of file
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