Commit 442ebfa3 authored by tguillon's avatar tguillon
Browse files

Modification : renommage du checkbox concernant l'obligation d'un champ.

Ajout : mise en place du champ pour répéter x fois les champs pour la co-responsabilité et la sous-traitance
parent 1d8280b1
......@@ -470,6 +470,8 @@ class FormulairesController extends AppController {
$this->redirect($this->Referers->get());
}
debug($this->request->data);die;
$success = true;
$this->Formulaire->begin();
......@@ -583,9 +585,9 @@ class FormulairesController extends AppController {
}
}
if ($this->request->params['action'] === 'edit') {
// if ($this->request->params['action'] === 'edit') {
$this->getFields($id);
}
// }
$this->view = 'edit';
}
......@@ -702,6 +704,44 @@ class FormulairesController extends AppController {
}
}
// valeur par défault
if ($this->request->params['action'] == 'add' && empty($this->request->data)) {
$fields['coresponsable'] = [
[
'Champ' => [
'type' => 'input',
'ligne' => 1,
'colonne' => 1,
'details' => '{"name":"nom_responsable_conjoint","placeholder":"Nom et prénom","label":"Nom et prénom du responsable conjoint","default":"","obligatoire":true,"repeat":false}'
]
],
[
'Champ' => [
'type' => 'input',
'ligne' => 3,
'colonne' => 1,
'details' => '{"name":"structure_responsable_conjointe","placeholder":"Raison sociale","label":"Raison sociale de la structure conjointe","default":"","obligatoire":true,"repeat":false}'
]
],
[
'Champ' => [
'type' => 'input',
'ligne' => 1,
'colonne' => 2,
'details' => '{"name":"email_responsable_conjoint","placeholder":"Adresse e-mail","label":"Adresse mail du responsable conjoint","default":"","obligatoire":true,"repeat":false}'
]
],
[
'Champ' => [
'type' => 'textarea',
'ligne' => 3,
'colonne' => 2,
'details' => '{"name":"adresse_structure_responsable_conjointe","placeholder":"Adresse postale","label":"Adresse de la structure conjointe","default":"","obligatoire":false,"repeat":false}'
]
]
];
}
$this->set(compact('fields'));
}
......
......@@ -19,15 +19,21 @@ foreach ($champs as $key => $value) {
// Champ obligatoire ou non
if ($details['obligatoire'] == true) {
$champObligatoire = "checked";
$champObligatoire = "fieldRequired";
} else {
$champObligatoire = "unchecked";
$champObligatoire = "fieldNotRequired";
}
if ($details['repeat'] == true) {
$fieldRepeat = "fieldRepeat";
} else {
$fieldRepeat = "fieldNoRepeat";
}
switch ($value['Champ']['type']) {
// Petit champ texte
case 'input':
echo '<div class="draggable form-group col-md-6 small-text" style="top:' . $line . 'px; ' . $colonne . '" data="' . $champObligatoire . '">'
echo '<div class="draggable form-group col-md-6 small-text" style="top:' . $line . 'px; ' . $colonne . '" virtual-data-required="'.$champObligatoire.'" virtual-data-repeat="'.$fieldRepeat.'">'
. '<div class="col-md-4">'
. '<label>'
. '<span class="labeler">' . $details['label'] . '</span>'
......@@ -42,7 +48,7 @@ foreach ($champs as $key => $value) {
// Grand champ texte
case 'textarea':
echo '<div class="draggable form-group col-md-6 long-text" style="top:' . $line . 'px; ' . $colonne . '" data="' . $champObligatoire . '">'
echo '<div class="draggable form-group col-md-6 long-text" style="top:' . $line . 'px; ' . $colonne . '" virtual-data-required="'.$champObligatoire.'" virtual-data-repeat="'.$fieldRepeat.'">'
. '<div class="col-md-4">'
. '<label>'
. '<span class="labeler">' . $details['label'] . '</span>'
......@@ -57,7 +63,7 @@ foreach ($champs as $key => $value) {
// Champ date
case 'date':
echo '<div class="draggable form-group col-md-6 date" style="top:' . $line . 'px; ' . $colonne . '" data="' . $champObligatoire . '">'
echo '<div class="draggable form-group col-md-6 date" style="top:' . $line . 'px; ' . $colonne . '" virtual-data-required="'.$champObligatoire.'" virtual-data-repeat="'.$fieldRepeat.'">'
. '<div class="col-md-4">'
. '<label>'
. '<span class="labeler">' . $details['label'] . '</span>'
......@@ -118,7 +124,7 @@ foreach ($champs as $key => $value) {
// Choix unique
case 'radios':
echo '<div class="draggable form-group col-md-6 radios" style="top:' . $line . 'px; ' . $colonne . '" data="' . $champObligatoire . '">'
echo '<div class="draggable form-group col-md-6 radios" style="top:' . $line . 'px; ' . $colonne . '" virtual-data-required="'.$champObligatoire.'" virtual-data-repeat="'.$fieldRepeat.'">'
. '<div class="col-md-4">'
. '<label>'
. '<span class="labeler">' . $details['label'] . '</span>'
......@@ -141,7 +147,7 @@ foreach ($champs as $key => $value) {
// Menu déroulant
case 'deroulant':
echo '<div class="draggable form-group col-md-6 deroulant" style="top:' . $line . 'px; ' . $colonne . '" data="' . $champObligatoire . '">'
echo '<div class="draggable form-group col-md-6 deroulant" style="top:' . $line . 'px; ' . $colonne . '" virtual-data-required="'.$champObligatoire.'" virtual-data-repeat="'.$fieldRepeat.'">'
. '<div class="col-md-4">'
. '<label>'
. '<span class="labeler">' . $details['label'] . '</span>'
......
......@@ -18,7 +18,8 @@
<!-- Corps du formulaire -->
<div id="form-container-coresponsable" class="form-container col-md-12">
<?php
if ($this->request->params['action'] == 'edit' && !empty($fields['coresponsable'])) {
// if ($this->request->params['action'] == 'edit' && !empty($fields['coresponsable'])) {
if (!empty($fields['coresponsable'])) {
echo $this->element('Formulaires/champDuFormulaire', [
'champs' => $fields['coresponsable']
]);
......
......@@ -205,7 +205,7 @@ var createForm = function(typeCreateForm) {
case 'btn-radio-'+typeCreateForm:
newElement = jQuery(
'<div class="draggable form-group col-md-6 radios ui-selected" data="checked" style="left : 0px; top : ' + top + 'px;">' +
'<div class="draggable form-group col-md-6 radios ui-selected" virtual-data-required="fieldRequired" style="left : 0px; top : ' + top + 'px;">' +
'<div class="col-md-4">' +
'<label>' +
'<span class="labeler">' +
......@@ -360,14 +360,57 @@ var createForm = function(typeCreateForm) {
options = null,
check = null,
readonly = '',
findType = '';
findType = '',
fieldRepeat = '';
var btnGoupsTrashApplicable = '<div class="row">' +
'<div class="col-md-12 text-center">' +
'<div class="btn-group">' +
'<div class="'+idbtnGroup+' text-center">' +
'<button type="button" class="btn btn-default-danger btn-sm" id="'+idbtnCloser+'">' +
'<i class="fa fa-trash"></i>' +
'</button>' +
'<button type="button" class="btn btn-default-success btn-sm" id="'+idbtnApplicable+'">' +
'<i class="fa fa-check"></i> Appliquer' +
'</button>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
// @TODO
if ($(idContainer).find('.ui-selected').attr('data') === 'checked') {
// check = '<div class="checkbox"><label><input type="checkbox" name="checked" id="oblig-small-text" class="obligForm" checked="true" readonly="readonly" disabled="disabled"> Champ obligatoire</label></div>';
check = '<div class="checkbox"><label><input type="checkbox" name="checked" id="oblig-small-text" class="obligForm" checked="true"> Champ obligatoire</label></div>';
if ($(idContainer).find('.ui-selected').attr('virtual-data-required') === 'fieldRequired') {
check = '<div class="checkbox">' +
'<label>' +
'<input type="checkbox" id="checkboxFieldRequired" class="obligForm" checked="true">' +
'Champ obligatoire' +
'</label>' +
'</div>';
} else {
check = '<div class="checkbox"><label><input type="checkbox" name="checked" id="oblig-small-text" class="obligForm"> Champ obligatoire</label></div>';
check = '<div class="checkbox">' +
'<label>' +
'<input type="checkbox" id="checkboxFieldRequired" class="obligForm">' +
'Champ obligatoire' +
'</label>' +
'</div>';
}
if (!jQuery.inArray(typeCreateForm, ['coresponsable', 'soustraitant'])) {
if ($(idContainer).find('.ui-selected').attr('virtual-data-repeat') === 'fieldRepeat') {
fieldRepeat = '<div class="checkbox">' +
'<label>' +
'<input type="checkbox" id="checkboxFieldRepeat" class="fieldRepeat" checked="true">' +
'Répétition du champ X fois' +
'</label>' +
'</div>';
} else {
fieldRepeat = '<div class="checkbox">' +
'<label>' +
'<input type="checkbox" id="checkboxFieldRepeat" class="fieldRepeat">' +
'Répétition du champ X fois' +
'</label>' +
'</div>';
}
}
if ( (object.hasClass('small-text')) || (object.hasClass('long-text')) || (object.hasClass('date')) ) {
......@@ -418,7 +461,7 @@ var createForm = function(typeCreateForm) {
'<label for="'+champId+'">Nom de variable' +
'<span class="obligatoire"> *</span>' +
'</label>' +
'<input type="text" class="form-control nameForm"'+readonly+' name="name" id="'+champId+'" placeholder="Nom UNIQUE" value="'+attrNameNomDeVariable+'">' +
'<input type="text" class="form-control nameForm"'+readonly+' id="'+champId+'" placeholder="Nom UNIQUE" value="'+attrNameNomDeVariable+'">' +
'</div>' +
'</div>' +
'<div class="col-md-3">' +
......@@ -426,7 +469,7 @@ var createForm = function(typeCreateForm) {
'<label for="'+forLabelNomChamp+'">' +
'Nom du champ' +
'</label>' +
'<input type="text" class="form-control labelForm" name="name" id="'+forLabelNomChamp+'" placeholder="Label du champ" value="'+$(idContainer).find('.ui-selected').find('.labeler').html()+'">' +
'<input type="text" class="form-control labelForm" id="'+forLabelNomChamp+'" placeholder="Label du champ" value="'+$(idContainer).find('.ui-selected').find('.labeler').html()+'">' +
'</div>' +
'</div>' +
'<div class="col-md-3">' +
......@@ -434,19 +477,13 @@ var createForm = function(typeCreateForm) {
'<label for="'+forPlaceholderAideSaisie+'">' +
'Aide à la saisie' +
'</label>' +
'<input type="text" class="form-control placeholderForm"'+placeholderAideSaisieReadonly+' name="name" id="'+forPlaceholderAideSaisie+'" value="'+attrPlaceholderAideSaisie+'">' +
'<input type="text" class="form-control placeholderForm"'+placeholderAideSaisieReadonly+' id="'+forPlaceholderAideSaisie+'" value="'+attrPlaceholderAideSaisie+'">' +
'</div>' +
'</div>' +
check +
'<div class="'+idbtnGroup+' text-center">' +
'<button type="button" class="btn btn-default-danger btn-sm" id="'+idbtnCloser+'">' +
'<i class="fa fa-trash"></i>' +
'</button>' +
'<button type="button" class="btn btn-default-success btn-sm" id="'+idbtnApplicable+'">' +
'<i class="fa fa-check"></i> Appliquer' +
'</button>' +
'</div>' +
'</div>'
fieldRepeat +
'</div>' +
btnGoupsTrashApplicable
);
}
......@@ -481,6 +518,13 @@ var createForm = function(typeCreateForm) {
idListeDesValeurs = 'option-radios';
classListeValeur = 'radioForm';
check = '<div class="checkbox">' +
'<label>' +
'<input type="checkbox" id="checkboxFieldRequired" class="obligForm" checked="true" readonly="readonly" >' +
'Champ obligatoire' +
'</label>' +
'</div>';
}
}
......@@ -543,7 +587,7 @@ var createForm = function(typeCreateForm) {
'<div class="col-md-3">' +
'<div class="form-group">' +
'<label for="'+forLabelNomDuChamp+'">Nom du champ</label>' +
'<input type="text" class="form-control labelForm" name="name" id="'+forLabelNomDuChamp+'" placeholder="Label du champ" value="' + $(idContainer).find('.ui-selected').find('.labeler').html() + '">' +
'<input type="text" class="form-control labelForm" id="'+forLabelNomDuChamp+'" placeholder="Label du champ" value="' + $(idContainer).find('.ui-selected').find('.labeler').html() + '">' +
'</div>' +
'</div>' +
'<div class="col-md-3">' +
......@@ -555,15 +599,8 @@ var createForm = function(typeCreateForm) {
'</div>' +
'</div>' +
check +
'<div class="'+idbtnGroup+' text-center">' +
'<button type="button" class="btn btn-default-danger btn-sm" id="'+idbtnCloser+'">' +
'<i class="fa fa-trash"></i>' +
'</button>' +
'<button type="button" class="btn btn-default-success btn-sm" id="'+idbtnApplicable+'">' +
'<i class="fa fa-check"></i> Appliquer' +
'</button>' +
'</div>' +
'</div>'
'</div>' +
btnGoupsTrashApplicable
);
}
......@@ -593,15 +630,8 @@ var createForm = function(typeCreateForm) {
'</label>' +
'<input type="text" class="form-control '+classContenu+'" name="'+labelForContenu+'" id="'+labelForContenu+'" value="'+valueContenu+'">' +
'</div>' +
'<div class="'+idbtnGroup+' text-center">' +
'<button type="button" class="btn btn-default-danger btn-sm" id="'+idbtnCloser+'">' +
'<i class="fa fa-trash"></i>' +
'</button>' +
'<button type="button" class="btn btn-default-success btn-sm" id="'+idbtnApplicable+'">' +
'<i class="fa fa-check"></i> Appliquer' +
'</button>' +
'</div>' +
'</div>'
'</div>' +
btnGoupsTrashApplicable
);
}
......@@ -616,15 +646,8 @@ var createForm = function(typeCreateForm) {
'</label>' +
'<textarea class="form-control texteForm" name="content-texte" id="content-texte">' + $(idContainer).find('.ui-selected').find('h5').html() + '</textarea>' +
'</div>' +
'<div class="'+idbtnGroup+' text-center">' +
'<button type="button" class="btn btn-default-danger btn-sm" id="'+idbtnCloser+'">' +
'<i class="fa fa-trash"></i>' +
'</button>' +
'<button type="button" class="btn btn-default-success btn-sm" id="'+idbtnApplicable+'">' +
'<i class="fa fa-check"></i> Appliquer' +
'</button>' +
'</div>' +
'</div>'
'</div>' +
btnGoupsTrashApplicable
);
}
......@@ -678,10 +701,23 @@ var createForm = function(typeCreateForm) {
$('.labelForm').val() + '</span><span class="obligatoire"> *</span>'
);
$(idContainer).find('.ui-selected').attr('data', 'checked');
$(idContainer).find('.ui-selected').attr('virtual-data-required', 'fieldRequired');
} else {
$(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' + $('.labelForm').val() + '</span>');
$(idContainer).find('.ui-selected').attr('data', 'unchecked');
$(idContainer).find('.ui-selected').attr('virtual-data-required', 'fieldNotRequired');
}
}
if ($(this).hasClass('fieldRepeat')) {
if ($(this).prop('checked')) {
// $(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' +
// $('.labelForm').val() + '</span><span class="obligatoire"> *</span>'
// );
$(idContainer).find('.ui-selected').attr('virtual-data-repeat', 'fieldRepeat');
} else {
// $(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' + $('.labelForm').val() + '</span>');
$(idContainer).find('.ui-selected').attr('virtual-data-repeat', 'fieldNoRepeat');
}
}
});
......@@ -735,10 +771,23 @@ var createForm = function(typeCreateForm) {
$('.labelForm').val() + '</span><span class="obligatoire"> *</span>'
);
$(idContainer).find('.ui-selected').attr('data', 'checked');
$(idContainer).find('.ui-selected').attr('virtual-data-required', 'fieldRequired');
} else {
$(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' + $('.labelForm').val() + '</span>');
$(idContainer).find('.ui-selected').attr('data', 'unchecked');
$(idContainer).find('.ui-selected').attr('virtual-data-required', 'fieldNotRequired');
}
}
if ($(this).hasClass('fieldRepeat')) {
if ($(this).prop('checked')) {
// $(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' +
// $('.labelForm').val() + '</span><span class="obligatoire"> *</span>'
// );
$(idContainer).find('.ui-selected').attr('virtual-data-repeat', 'fieldRepeat');
} else {
// $(idContainer).find('.ui-selected').find('label').html('<span class="labeler">' + $('.labelForm').val() + '</span>');
$(idContainer).find('.ui-selected').attr('virtual-data-repeat', 'fieldNoRepeat');
}
}
});
......
$(document).ready(function () {
$('#container').on('submit', function(){
$('#container').on('submit', function() {
var success = true,
retour = [];
......@@ -15,8 +15,9 @@ $(document).ready(function () {
var contenu = {};
contenu['onglet'] = droppableId;
contenu['ligne'] = $(draggable).position().top / 35 + 1;
contenu['ligne'] = Math.round($(draggable).position().top / 35 + 1);
// @TODO
if ($(this).position().left < 10) {
contenu['colonne'] = 1;
} else {
......@@ -153,12 +154,18 @@ $(document).ready(function () {
contenu['default'] = valuesMultiSelectDefault;
}
if ($(draggable).attr('data') === 'checked') {
if ($(draggable).attr('virtual-data-required') === 'fieldRequired') {
contenu['obligatoire'] = true;
} else {
contenu['obligatoire'] = false;
}
if ($(draggable).attr('virtual-data-repeat') === 'fieldRepeat') {
contenu['repeat'] = true;
} else {
contenu['repeat'] = false;
}
retour.push(contenu);
});
});
......
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