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

Modification : du retour pour correspondre à l'envoie des données du serveur

parent a54c4905
......@@ -18,9 +18,9 @@
<!-- Corps du formulaire -->
<div id="form-container-coresponsable" class="form-container col-md-12">
<?php
if (!empty($this->request->data['Formulaire']['formulaire'])) {
if (!empty($this->request->data['Formulaire']['form-container-coresponsable'])) {
echo $this->element('Formulaires/champDuFormulaire', [
'champs' => $this->request->data['Formulaire']['coresponsable']
'champs' => $this->request->data['Formulaire']['form-container-coresponsable']
]);
}
?>
......
......@@ -17,9 +17,9 @@
<!-- Corps du formulaire -->
<div id="form-container-formulaire" class="form-container col-md-12">
<?php
if (!empty($this->request->data['Formulaire']['formulaire'])) {
if (!empty($this->request->data['Formulaire']['form-container-formulaire'])) {
echo $this->element('Formulaires/champDuFormulaire', [
'champs' => $this->request->data['Formulaire']['formulaire']
'champs' => $this->request->data['Formulaire']['form-container-formulaire']
]);
}
?>
......
......@@ -19,9 +19,9 @@
<!-- Corps du formulaire -->
<div id="form-container-soustraitant" class="form-container col-md-12">
<?php
if (!empty($this->request->data['Formulaire']['formulaire'])) {
if (!empty($this->request->data['Formulaire']['form-container-soustraitant'])) {
echo $this->element('Formulaires/champDuFormulaire', [
'champs' => $this->request->data['Formulaire']['soustraitant']
'champs' => $this->request->data['Formulaire']['form-container-soustraitant']
]);
}
?>
......
......@@ -135,7 +135,7 @@ echo $this->WebcilForm->create('Formulaire', [
<div class="row">
<?php
echo $this->WebcilForm->hidden('json', ['id' => 'hiddenForm']);
echo $this->WebcilForm->hidden('', ['id' => 'hiddenForm']);
?>
<!-- Groupe bouton -->
......
......@@ -2,9 +2,8 @@ $(document).ready(function () {
$('#container').on('submit', function() {
var success = true,
retour = [],
testRETOUR = {};
loulou = {};
tabRetour = {};
retour = {};
$('.ui-droppable').each(function(idxDroppable, droppable) {
var droppableId = $(droppable).attr('id'),
......@@ -14,38 +13,24 @@ $(document).ready(function () {
$(idTab).addClass('active');
$(droppable).find('.draggable').each(function (idxDraggable, draggable) {
var contenu = {};
var fieldLine = null,
fieldColumn = null,
fieldType = null,
fieldName = null,
fieldPlaceholder = null,
fieldLabel = null,
fieldDefault = null;
// console.log(contenu);
//
// contenu['ligne'] = 10;
//
// console.log(contenu);
//
//
// total.push({droppableId: contenu});
//
// console.log(total);
// contenu['onglet'] = droppableId;
// contenu['ligne'] = Math.round($(draggable).position().top / 35 + 1);
fieldDefault = null,
fieldContent = null
fieldOptions = null,
fieldObligatoire = null,
fieldRepeat = null;
fieldLine = Math.round($(draggable).position().top / 35 + 1);
// @TODO
if ($(this).position().left < 10) {
// contenu['colonne'] = 1;
fieldColumn = 1;
} else {
// contenu['colonne'] = 2;
fieldColumn = 2;
}
......@@ -56,12 +41,6 @@ $(document).ready(function () {
return;
}
// contenu['type'] = 'input';
// contenu['name'] = $(draggable).find('input').attr('name');
// contenu['placeholder'] = $(draggable).find('input').attr('placeholder');
// contenu['label'] = $(draggable).find('.labeler').html();
// contenu['default'] = $(draggable).find('input').val();
fieldType = 'input';
fieldName = $(draggable).find('input').attr('name');
fieldPlaceholder = $(draggable).find('input').attr('placeholder');
......@@ -74,78 +53,88 @@ $(document).ready(function () {
success = false;
return;
}
contenu['type'] = 'textarea';
contenu['name'] = $(draggable).find('textarea').attr('name');
contenu['placeholder'] = $(draggable).find('textarea').attr('placeholder');
contenu['label'] = $(draggable).find('.labeler').html();
contenu['default'] = $(draggable).find('textarea').val();
fieldType = 'textarea';
fieldName = $(draggable).find('textarea').attr('name');
fieldPlaceholder = $(draggable).find('textarea').attr('placeholder');
fieldLabel = $(draggable).find('.labeler').html();
fieldDefault = $(draggable).find('textarea').val();
} else if ($(draggable).hasClass('date')) {
if (typeof $(draggable).find('input').attr('name') === '' || typeof $(draggable).find('input').attr('name') === 'undefined') {
alert('Le nom de variable du champ date est incorrect');
success = false;
return;
}
contenu['type'] = 'date';
contenu['name'] = $(draggable).find('input').attr('name');
contenu['placeholder'] = $(draggable).find('input').attr('placeholder');
contenu['label'] = $(draggable).find('.labeler').html();
contenu['default'] = $(draggable).find('input').val();
fieldType = 'date';
fieldName = $(draggable).find('input').attr('name');
fieldPlaceholder = $(draggable).find('input').attr('placeholder');
fieldLabel = $(draggable).find('.labeler').html();
fieldDefault = $(draggable).find('input').val();
} else if ($(draggable).hasClass('title')) {
contenu['type'] = 'title';
contenu['content'] = $(draggable).find('h1').html();
fieldType = 'title';
fieldContent = $(draggable).find('h1').html();
} else if ($(draggable).hasClass('texte')) {
contenu['type'] = 'texte';
contenu['content'] = $(draggable).find('h5').html();
fieldType = 'texte';
fieldContent = $(draggable).find('h5').html();
} else if ($(draggable).hasClass('help')) {
contenu['type'] = 'help';
contenu['content'] = $(draggable).find('.messager').html();
fieldType = 'help';
fieldContent = $(draggable).find('.messager').html();
} else if ($(draggable).hasClass('checkboxes')) {
if (typeof $(draggable).find('input').attr('name') === '' || typeof $(draggable).find('input').attr('name') === 'undefined') {
alert('Le nom de variable des cases à cocher est incorrect');
success = false;
return;
}
contenu['type'] = 'checkboxes';
contenu['name'] = $(draggable).find('input').attr('name');
contenu['label'] = $(draggable).find('.labeler').html();
var option = [];
fieldType = 'checkboxes';
fieldName = $(draggable).find('input').attr('name');
fieldLabel = $(draggable).find('.labeler').html();
var options = [];
$(draggable).find('input').each(function () {
option.push($(this).attr('value'));
options.push($(this).attr('value'));
});
contenu['options'] = option;
fieldOptions = options;
var valuesCheckboxesDefault = [];
$('input[name="'+contenu["name"]+'"]:checked').each(function() {
valuesCheckboxesDefault.push(this.id);
});
contenu['default'] = valuesCheckboxesDefault;
fieldDefault = valuesCheckboxesDefault;
} else if ($(draggable).hasClass('radios')) {
if (typeof $(draggable).find('input').attr('name') === '' || typeof $(draggable).find('input').attr('name') === 'undefined') {
alert('Le nom de variable du choix unique est incorrect');
success = false;
return;
}
contenu['type'] = 'radios';
contenu['name'] = $(draggable).find('input').attr('name');
contenu['label'] = $(draggable).find('.labeler').html();
contenu['default'] = $(draggable).find('input[name="'+contenu["name"]+'"]:checked').val();
var option = [];
fieldType = 'radios';
fieldName = $(draggable).find('input').attr('name');
fieldLabel = $(draggable).find('.labeler').html();
fieldDefault = $(draggable).find('input[name="'+contenu["name"]+'"]:checked').val();
var options = [];
$(draggable).find('input').each(function () {
option.push($(this).attr('value'));
options.push($(this).attr('value'));
});
contenu['options'] = option;
fieldOptions = options;
} else if ($(draggable).hasClass('deroulant')) {
if (typeof $(draggable).find('option').attr('name') === '' || typeof $(draggable).find('option').attr('name') === 'undefined') {
alert('Le nom de variable du menu déroulant est incorrect');
success = false;
return;
}
contenu['type'] = 'deroulant';
contenu['name'] = $(draggable).find('option').attr('name');
contenu['label'] = $(draggable).find('.labeler').html();
fieldType = 'deroulant';
fieldName = $(draggable).find('option').attr('name');
fieldLabel = $(draggable).find('.labeler').html();
var options = [];
$(draggable).find('option').each(function () {
......@@ -153,7 +142,7 @@ $(document).ready(function () {
options.push(this.value);
}
});
contenu['options'] = options;
fieldOptions = options;
var valuesDeroulantDefault = '';
$('option[name="'+contenu["name"]+'"]:checked').each(function() {
......@@ -161,7 +150,7 @@ $(document).ready(function () {
valuesDeroulantDefault = this.id;
}
});
contenu['default'] = valuesDeroulantDefault;
fieldDefault = valuesDeroulantDefault;
} else if ($(draggable).hasClass('multi-select')) {
if (typeof $(draggable).find('option').attr('name') === '' || typeof $(draggable).find('option').attr('name') === 'undefined') {
......@@ -169,65 +158,67 @@ $(document).ready(function () {
success = false;
return;
}
contenu['type'] = 'multi-select';
contenu['name'] = $(draggable).find('option').attr('name');
contenu['label'] = $(draggable).find('.labeler').html();
var option = [];
fieldType = 'multi-select';
fieldName = $(draggable).find('option').attr('name');
fieldLabel = $(draggable).find('.labeler').html();
var options = [];
$(draggable).find('option').each(function () {
option.push($(this).attr('value'));
options.push($(this).attr('value'));
});
contenu['options'] = option;
fieldOptions = options;
var valuesMultiSelectDefault = [];
$('option[name="'+contenu["name"]+'"]:checked').each(function() {
valuesMultiSelectDefault.push(this.index);
});
contenu['default'] = valuesMultiSelectDefault;
fieldDefault = valuesMultiSelectDefault;
}
if ($(draggable).attr('data-virtual-required') === 'fieldRequired') {
contenu['obligatoire'] = true;
fieldObligatoire = true;
} else {
contenu['obligatoire'] = false;
fieldObligatoire = false;
}
if ($(draggable).attr('virtual-data-repeat') === 'fieldRepeat') {
contenu['repeat'] = true;
fieldRepeat = true;
} else {
contenu['repeat'] = false;
fieldRepeat = false;
}
var fieldDetails = {
'name': fieldName,
'placeholder': fieldPlaceholder,
'label': fieldLabel,
'default': fieldDefault
'default': fieldDefault,
'content' : fieldContent,
'options' : fieldOptions,
'obligatoire' : fieldObligatoire,
'repeat' : fieldRepeat
};
var fieldValues = {
'type' : fieldType,
'ligne' : fieldLine,
'colonne' : fieldColumn,
'type' : fieldType,
'details' : JSON.stringify(fieldDetails)
};
// console.log(fieldValues);
var tmpArray = {};
tmpArray['Champ'] = fieldValues;
testRETOUR[idxDraggable] = fieldValues;
loulou[droppableId] = testRETOUR;
// retour.push(contenu);
tabRetour[idxDraggable] = tmpArray;
retour[droppableId] = tabRetour;
});
});
$('.active').removeClass('active');
$('#info_complementaire').addClass('active');
$('#onglet_info_complementaire').addClass('active');
// var ret = JSON.stringify(retour, null, '\t');
var ret = JSON.stringify(loulou, null, '\t');
var ret = JSON.stringify(retour, null, '\t');
if (success) {
$('#hiddenForm').attr('value', ret);
......
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