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

Ajout : de l'attribut "for" et "id" sur les champs généré au click

Ajout : de l'écriture textuelle des condtions dans le carré d'option à la selection d'un champ
Ajout : envoie des conditions avec les autres paramètres au controller
parent 590be7d4
......@@ -470,8 +470,6 @@ class FormulairesController extends AppController {
$this->redirect($this->Referers->get());
}
// debug($this->request->data);die;
$success = true;
$this->Formulaire->begin();
......@@ -582,6 +580,21 @@ class FormulairesController extends AppController {
}
break;
case 'conditions':
debug($val);
$conditions = (array)json_decode($val);
debug($conditions);
foreach ($conditions as $key => $condition) {
debug($condition);
$conditionValues = (array)json_decode($condition);
debug($conditionValues);
}
die;
break;
default:
$sortie[$clef] = $val;
break;
......
......@@ -386,7 +386,9 @@ var createForm = function(typeCreateForm) {
check = null,
readonly = '',
findType = '',
fieldRepeat = '';
fieldRepeat = '',
displayConditions = '',
conditions = '';
var btnGoupsTrashApplicable = '<div class="row">' +
'<div class="col-md-12 text-center">' +
......@@ -482,6 +484,11 @@ var createForm = function(typeCreateForm) {
readonly = "readonly='readonly'";
}
conditions = $(idContainer).find('.ui-selected').attr('data-virtual-conditions');
if (conditions) {
displayConditions = writeConditionsInOption(conditions);
}
options = jQuery('' +
'<div class="col-md-12">' +
'<div class="col-md-3">' +
......@@ -512,6 +519,7 @@ var createForm = function(typeCreateForm) {
check +
// fieldRepeat +
'</div>' +
displayConditions +
btnGoupsTrashApplicable
);
}
......@@ -760,12 +768,18 @@ var createForm = function(typeCreateForm) {
// give to field the "label"
$(idContainer).find('.ui-selected').find('div').find('label').find('span.labeler').text(newLabelField);
// add attribut "for" to "label"
$(idContainer).find('.ui-selected').find('label').attr('for', newNameField);
// give to field if required
giveToFieldIfRequired(newRequiredField);
}
// Attribution les valeurs aux champs "Petit champ texte" et "Champ date"
if ($(this).is('.small-text, .date')) {
// add attribute "id"
$(idContainer).find('.ui-selected').find('input').attr('id', newNameField);
// give to field the "name"
$(idContainer).find('.ui-selected').find('input').attr('name', newNameField);
......@@ -788,6 +802,9 @@ var createForm = function(typeCreateForm) {
// Attribution les valeurs au champ "Grand champ texte"
if ($(this).hasClass('long-text')) {
// add attribute "id"
$(idContainer).find('.ui-selected').find('textarea').attr('id', newNameField);
// give to field the "name"
$(idContainer).find('.ui-selected').find('textarea').attr('name', newNameField);
......@@ -831,6 +848,9 @@ var createForm = function(typeCreateForm) {
'</option>';
});
// add attribute "id"
$(idContainer).find('.ui-selected').find('select').attr('id', newNameField);
// give to field the options
$(idContainer).find('.ui-selected').find('.contentDeroulant').html(jQuery(objet));
}
......@@ -1018,4 +1038,67 @@ var createForm = function(typeCreateForm) {
}
}
/**
* Ecrit textuellement les différentes conditions du champs pour les afficher
*
* @created 01/04/2020
* @version V1.2.0
* @author Théo GUILLON <theo.guillon@libriciel.coop>
*/
function writeConditionsInOption(conditions) {
var writeConditions = '';
$.each(JSON.parse(conditions), function (key, value) {
var ifTheField = $('#'+value['ifTheField']).labels().text();
var hasValue = $('#'+value['ifTheField']).find('option[value="'+value['hasValue']+'"]').text();
var thenTheField = $('label[for="'+value['thenTheField']+'"]').text();
var mustBe = '';
var ifNot = '';
if (value['mustBe'] == 'shown') {
mustBe = 'afficher';
} else {
mustBe = 'cacher';
}
if (value['ifNot'] == 'shown') {
ifNot = 'afficher';
} else {
ifNot = 'cacher';
}
writeConditions = writeConditions + '<p>' +
'Si le champ' +
'<strong>'+
' "'+ifTheField+'" '+
'</strong>' +
'a comme valeur'+
'<strong>'+
' "'+hasValue+'" '+
'</strong>' +
'alors le champ' +
'<strong>'+
' "'+thenTheField+'" '+
'</strong>' +
'doit être' +
'<strong>'+
' "'+mustBe+'" '+
'</strong>' +
'sinon il sera' +
'<strong>'+
' "'+ifNot+'" '+
'</strong>' +
'<a id="'+key+'" href="#" class="removeCondition">' +
'<span class="fa fa-trash fa-lg fa-danger"></span>' +
'</a>'
'</p>';
});
writeConditions = '<div class="col-md-12">' +
writeConditions+
'</div>';
return writeConditions;
}
};
\ No newline at end of file
......@@ -199,12 +199,19 @@ $(document).ready(function () {
objFieldDetails['obligatoire'] = false;
}
if ($(draggable).attr('virtual-data-repeat') === 'fieldRepeat') {
if ($(draggable).attr('data-virtual-repeat') === 'fieldRepeat') {
objFieldDetails['repeat'] = true;
} else {
objFieldDetails['repeat'] = false;
}
var dataVirtualConditions = $(draggable).attr('data-virtual-conditions');
if (dataVirtualConditions) {
objFieldDetails['conditions'] = dataVirtualConditions
} else {
objFieldDetails['conditions'] = ''
}
objFieldValues = {
'type' : fieldType,
'ligne' : fieldLine,
......
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