Commit 5b482b2e authored by THEO GUILLON's avatar THEO GUILLON
Browse files

Merge branch '309-definir-des-valeurs-par-default-lors-de-la-creation-de-formulaire' into '1.2.0'

Resolve "Définir des valeurs par défault lors de la création de formulaire"

See merge request web-DPO/web-DPO!284
parents 23dc44f7 8e58ec04
......@@ -25,6 +25,8 @@ Le format est basé sur le modèle [Keep a Changelog](http://keepachangelog.com/
- Mise en place de l'initialisation d'un traitement par le DPO
- Ajout pour le DPO de visualiser tous les traitements au sein de sa collectivité.
- Mise en place de la duplication d'un traitement dans une ou plusieurs collectivité(s) en tant que DPO.
- Mise en place de valeur par défaut lors de la création d'un traitement. Ces valeurs par défaut sont ajouté lors de
la création d'un traitement.
### Evolutions
- Affichage de l'onglet "Information de l'entité" lors de la visualisation d'un traitement au registre
......
......@@ -371,6 +371,15 @@ class FichesController extends AppController
$this->request->data['Fiche']['declarantpersonneemail'] = $userLog['User']['email'];
$this->request->data['Fiche']['declarantpersonnefix'] = $userLog['User']['telephonefixe'];
$this->request->data['Fiche']['declarantpersonneportable'] = $userLog['User']['telephoneportable'];
$details = Hash::extract($champs, '{n}.Champ.details');
foreach ($details as $detail) {
$detail = (array)json_decode($detail);
if (!empty($detail['default'])) {
$this->request->data['Fiche'][$detail['name']] = $detail['default'];
}
}
}
$this->set(compact('champs', 'options_normes', 'descriptions_normes', 'soustraitance', 'soustraitants', 'responsables'));
......
......@@ -368,6 +368,19 @@ class FormulairesController extends AppController {
$sortie[$clef] = $options;
break;
case 'default':
if (!is_array($valeur)) {
$sortie[$clef] = trim($valeur);
} else {
$options = [];
foreach ($valeur as $key => $option) {
$options[$key] = trim($option);
}
$sortie[$clef] = $options;
}
break;
default:
$sortie[$clef] = $valeur;
break;
......@@ -517,6 +530,7 @@ class FormulairesController extends AppController {
if ($success == true) {
$array = json_decode($this->request->data['Formulaire']['json'], true);
foreach ($array as $key => $value) {
$sortie = [];
foreach ($value as $clef => $valeur) {
......@@ -546,6 +560,20 @@ class FormulairesController extends AppController {
$sortie[$clef] = $options;
break;
case 'default':
debug($valeur);
if (!is_array($valeur)) {
$sortie[$clef] = trim($valeur);
} else {
$options = [];
foreach ($valeur as $key => $option) {
$options[$key] = trim($option);
}
$sortie[$clef] = $options;
}
break;
default:
$sortie[$clef] = $valeur;
break;
......@@ -630,6 +658,17 @@ class FormulairesController extends AppController {
'formulaires_id' => $id
]
]);
if (empty($this->request->data)) {
$details = Hash::extract($champs, '{n}.Champ.details');
foreach ($details as $detail) {
$detail = (array)json_decode($detail);
if (!empty($detail['default'])) {
$this->request->data['Formulaire'][$detail['name']] = $detail['default'];
}
}
}
$this->set(compact(['id', 'organisation', 'champs', 'userDPO', 'formulaire']));
}
......@@ -705,6 +744,17 @@ class FormulairesController extends AppController {
'telephoneportable'
]
]);
if (empty($this->request->data)) {
$details = Hash::extract($champs, '{n}.Champ.details');
foreach ($details as $detail) {
$detail = (array)json_decode($detail);
if (!empty($detail['default'])) {
$this->request->data['Formulaire'][$detail['name']] = $detail['default'];
}
}
}
$this->set(compact(['champs', 'formulaire', 'organisation', 'userDPO']));
} else {
......
......@@ -831,7 +831,7 @@ $(document).ready(function () {
contenu['name'] = $(this).find('input').attr('name');
contenu['placeholder'] = $(this).find('input').attr('placeholder');
contenu['label'] = $(this).find('.labeler').html();
contenu['default'] = $(this).find('input').val();
} else if ($(this).hasClass('long-text')) {
if (typeof $(this).find('textarea').attr('name') === '' || typeof $(this).find('textarea').attr('name') === 'undefined') {
alert('Le nom de variable du grand champ texte est incorrect');
......@@ -842,6 +842,7 @@ $(document).ready(function () {
contenu['name'] = $(this).find('textarea').attr('name');
contenu['placeholder'] = $(this).find('textarea').attr('placeholder');
contenu['label'] = $(this).find('.labeler').html();
contenu['default'] = $(this).find('textarea').val();
} else if ($(this).hasClass('date')) {
if (typeof $(this).find('input').attr('name') === '' || typeof $(this).find('input').attr('name') === 'undefined') {
alert('Le nom de variable du champ date est incorrect');
......@@ -852,6 +853,7 @@ $(document).ready(function () {
contenu['name'] = $(this).find('input').attr('name');
contenu['placeholder'] = $(this).find('input').attr('placeholder');
contenu['label'] = $(this).find('.labeler').html();
contenu['default'] = $(this).find('input').val();
} else if ($(this).hasClass('title')) {
contenu['type'] = 'title';
contenu['content'] = $(this).find('h1').html();
......@@ -872,11 +874,16 @@ $(document).ready(function () {
contenu['label'] = $(this).find('.labeler').html();
var option = [];
$(this).find('input').each(function () {
option.push($(this).attr('value'));
});
contenu['options'] = option;
var valuesCheckboxesDefault = [];
$('input[name="'+contenu["name"]+'"]:checked').each(function() {
valuesCheckboxesDefault.push(this.id);
});
contenu['default'] = valuesCheckboxesDefault;
} else if ($(this).hasClass('radios')) {
if (typeof $(this).find('input').attr('name') === '' || typeof $(this).find('input').attr('name') === 'undefined') {
alert('Le nom de variable du choix unique est incorrect');
......@@ -886,6 +893,7 @@ $(document).ready(function () {
contenu['type'] = 'radios';
contenu['name'] = $(this).find('input').attr('name');
contenu['label'] = $(this).find('.labeler').html();
contenu['default'] = $(this).find('input[name="'+contenu["name"]+'"]:checked').val();
var option = [];
......@@ -903,12 +911,22 @@ $(document).ready(function () {
contenu['name'] = $(this).find('option').attr('name');
contenu['label'] = $(this).find('.labeler').html();
var option = [];
var options = [];
$(this).find('option').each(function () {
option.push($(this).attr('value'));
if ( this.value != '') {
options.push(this.value);
}
});
contenu['options'] = option;
contenu['options'] = options;
var valuesDeroulantDefault = '';
$('option[name="'+contenu["name"]+'"]:checked').each(function() {
if ( this.value != '') {
valuesDeroulantDefault = this.id;
}
});
contenu['default'] = valuesDeroulantDefault;
} else if ($(this).hasClass('multi-select')) {
if (typeof $(this).find('option').attr('name') === '' || typeof $(this).find('option').attr('name') === 'undefined') {
alert('Le nom de variable du menu multi-select est incorrect');
......@@ -925,6 +943,12 @@ $(document).ready(function () {
option.push($(this).attr('value'));
});
contenu['options'] = option;
var valuesMultiSelectDefault = [];
$('option[name="'+contenu["name"]+'"]:checked').each(function() {
valuesMultiSelectDefault.push(this.index);
});
contenu['default'] = valuesMultiSelectDefault;
}
// else if ($(this).hasClass('fichiers'))
// {
......
......@@ -31,7 +31,7 @@ foreach ($champs as $key => $value) {
. '</label>'
. '</div>'
. '<div class="col-md-8">'
. '<input type="text" name="' . $details['name'] . '" checked="' . $details['obligatoire'] . '" placeholder="' . $details['placeholder'] . '" class="form-control champNomVariableReadonly"/>'
. '<input type="text" value="'.$details['default'].'" name="' . $details['name'] . '" checked="' . $details['obligatoire'] . '" placeholder="' . $details['placeholder'] . '" class="form-control champNomVariableReadonly"/>'
. '</div>'
. '</div>';
break;
......@@ -46,7 +46,7 @@ foreach ($champs as $key => $value) {
. '</label>'
. '</div>'
. '<div class="col-md-8">'
. '<textarea type="textarea" name="' . $details['name'] . '" checked="' . $details['obligatoire'] . '" placeholder="' . $details['placeholder'] . '"class="form-control champNomVariableReadonly" cols="30" rows="6"></textarea>'
. '<textarea type="textarea" name="' . $details['name'] . '" checked="' . $details['obligatoire'] . '" placeholder="' . $details['placeholder'] . '"class="form-control champNomVariableReadonly" cols="30" rows="6">'.$details['default'].'</textarea>'
. '</div>'
. '</div>';
break;
......@@ -61,7 +61,7 @@ foreach ($champs as $key => $value) {
. '</label>'
. '</div>'
. '<div class="col-md-8">'
. '<input class="form-control champNomVariableReadonly" id="'.$details['name'].'" name="'.$details['name'].'" required="'.$details['obligatoire'].'" placeholder="'.$details['placeholder'].'"/>'
. '<input class="form-control champNomVariableReadonly" id="'.$details['name'].'" value="'.$details['default'].'" name="'.$details['name'].'" required="'.$details['obligatoire'].'" placeholder="'.$details['placeholder'].'"/>'
. '</div>'
. '</div>';
......@@ -94,12 +94,19 @@ foreach ($champs as $key => $value) {
<label class="col-md-4">
<span class="labeler">'.$details['label'].'</span>
</label>';
echo '<div class="col-md-8 contentCheckbox">';
foreach ($details['options'] as $key => $val) {
echo '<div class="checkbox">'
. '<input class="champNomVariableReadonly" type="checkbox" name="'.$details['name'].'" value="'.$val.'" id="x'.$key.'"><label for="x'.$key.'">'.$val.'</label></div>';
}
echo '</div>
echo '<div class="col-md-8 contentCheckbox">';
foreach ($details['options'] as $key => $val) {
$checked = "";
if (isset($details['default'])) {
if (in_array($key, $details['default'])) {
$checked = "checked";
}
}
echo '<div class="checkbox">'
. '<input id="'.$key.'" class="champNomVariableReadonly" type="checkbox" '.$checked.' name="'.$details['name'].'" value="'.$val.'" id="x'.$key.'"><label for="x'.$key.'">'.$val.'</label></div>';
}
echo '</div>
</div>
</div>';
......@@ -115,9 +122,16 @@ foreach ($champs as $key => $value) {
. '</label>'
. '</div>'
. '<div class="col-md-8 contentRadio">';
foreach ($details['options'] as $val) {
echo '<div class="radio"><input class="champNomVariableReadonly" type="radio" name="'.$details['name'].'" value="'.$val.'">'.$val.'</div>';
foreach ($details['options'] as $val) {
$checked = "";
if (isset($details['default'])) {
if ($val === $details['default']) {
$checked = "checked";
}
}
echo '<div class="radio"><input class="champNomVariableReadonly" type="radio" '.$checked.' name="'.$details['name'].'" value="'.$val.'">'.$val.'</div>';
}
echo '</div></div>';
break;
......@@ -131,11 +145,19 @@ foreach ($champs as $key => $value) {
. '</label>'
. '</div>'
. '<div class="col-md-8">'
. '<select class="form-control contentDeroulant" name ="' . $details['name'] . '">';
foreach ($details['options'] as $val) {
echo '<option class="champNomVariableReadonly" type="deroulant" name ="' . $details['name'] . '" value="' . $val . '"> ' . $val . '</option></div>';
}
echo '</select>'
. '<select id="'.$details['name'].'" class="usersDeroulant transformSelect form-control" name ="data[Fiche]['.$details['name'].']" data-placeholder=" ">'
. '<option name ="'.$details['name'].'" value=""></option>';
foreach ($details['options'] as $key => $val) {
$selected = "";
if (isset($details['default'])) {
if (in_array($key, $details['default'])) {
$selected = 'selected';
}
}
echo '<option id="'.$key.'" class="champNomVariableReadonly" type="deroulant" '.$selected.' name ="'.$details['name'].'" value="'.$val.'">'.$val.'</option></div>';
}
echo '</select>'
. '</div>'
. '</div>';
break;
......@@ -143,20 +165,27 @@ foreach ($champs as $key => $value) {
case 'multi-select' :
echo '<div class="draggable col-md-6 form-group multi-select" style="top:'.$line.'px; '.$colonne.'" data="'.$champObligatoire.'">'
.'<div class="col-md-4">'
.'<label>'
.'<span class="labeler">' . $details['label'] . '</span>'
. ($details['obligatoire'] ? '<span class="obligatoire"> *</span>' : '')
.'</label>'
.'<label>'
.'<span class="labeler">' . $details['label'] . '</span>'
. ($details['obligatoire'] ? '<span class="obligatoire"> *</span>' : '')
.'</label>'
.'</div>'
.'<div class="col-md-8">'
.'<input type="hidden" name="multi-select" value="" id="multi-select_"/>'
.'<select id="'.$details['name'].'" name="multi-select" class="form-control multiSelect contentMultiSelect" multiple="multiple">';
foreach ($details['options'] as $val) {
echo '<option class="champNomVariableReadonly" name="'.$details['name'].'" value="'.$val.'"> '.$val.'</option>';
.'<input type="hidden" name="multi-select" value="" id="multi-select_"/>'
.'<select id="'.$details['name'].'" name="multi-select" class="form-control multiSelect contentMultiSelect" multiple="multiple">';
foreach ($details['options'] as $key => $val) {
$selected = "";
if (isset($details['default'])) {
if (in_array($key, $details['default'])) {
$selected = 'selected';
}
echo '</select>'
}
echo '<option class="champNomVariableReadonly" '.$selected.' name="'.$details['name'].'" value="'.$val.'"> '.$val.'</option>';
}
echo '</select>'
.'</div>'
.'</div>';
.'</div>';
break;
// Label
......
......@@ -123,4 +123,9 @@ echo $this->WebcilForm->create('Formulaire', [
</div>
<?php
echo $this->WebcilForm->end();
\ No newline at end of file
echo $this->WebcilForm->end();
?>
<script type="text/javascript">
$(":input").prop("disabled", true);
</script>
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