Commit 272bc7d2 authored by Théo GUILLON's avatar Théo GUILLON
Browse files

Correction : scroll sur les onglets dans le formulaire

Modification : valeur des champs afficher pour la coresponsabilité
parent 21b3aa5f
...@@ -2079,13 +2079,19 @@ class FichesController extends AppController ...@@ -2079,13 +2079,19 @@ class FichesController extends AppController
foreach ($valeurs as $key => $value) { foreach ($valeurs as $key => $value) {
if ($this->Fiche->isJson($value['Valeur']['valeur'])) { if ($this->Fiche->isJson($value['Valeur']['valeur'])) {
$valueDecode = json_decode($value['Valeur']['valeur']); $valueDecode = json_decode($value['Valeur']['valeur'], true);
if (is_object($valueDecode)) { // if (is_object($valueDecode)) {
$valueDecode = json_decode(json_encode($valueDecode), true); // $valueDecode = json_decode(json_encode($valueDecode), true);
} // }
$this->request->data['WebdpoFiche'][$value['Valeur']['champ_name']] = $valueDecode; if ($value['Valeur']['champ_name'] === 'coresponsabilitefields') {
$this->request->data['WebdpoCoresponsable'] = $valueDecode;
} else if ($value['Valeur']['champ_name'] === 'soustraitancefields') {
$this->request->data['WebdpoSoustraitance'] = $valueDecode;
} else {
$this->request->data['WebdpoFiche'][$value['Valeur']['champ_name']] = $valueDecode;
}
} else { } else {
if (in_array($value['Valeur']['champ_name'], $changeArrayFields) && in_array($this->request->params['action'], ['edit', 'show']) === true ) { if (in_array($value['Valeur']['champ_name'], $changeArrayFields) && in_array($this->request->params['action'], ['edit', 'show']) === true ) {
$this->request->data['Trash'][$value['Valeur']['champ_name']] = $value['Valeur']['valeur']; $this->request->data['Trash'][$value['Valeur']['champ_name']] = $value['Valeur']['valeur'];
......
...@@ -145,7 +145,7 @@ class WebdpoCoresponsable extends AppModel ...@@ -145,7 +145,7 @@ class WebdpoCoresponsable extends AppModel
return $data; return $data;
} }
$data[$this->alias]['coresponsabilitefields'] = json_encode($data[$this->alias], true); $data['WebdpoFiche']['coresponsabilitefields'] = json_encode($data[$this->alias], true);
} }
return $data; return $data;
......
<?php
echo $this->Html->script([
'smalot-bootstrap-datetimepicker/js/bootstrap-datetimepicker.min',
'smalot-bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.fr.js'
]);
echo $this->Html->css('/js/smalot-bootstrap-datetimepicker/css/bootstrap-datetimepicker.min');
?>
<!-- Onglet Co-responsable --> <!-- Onglet Co-responsable -->
<div id="ongletComplementaireCoresponsable" class="tab-pane"> <div id="ongletComplementaireCoresponsable" class="tab-pane">
<br> <br>
...@@ -59,22 +67,25 @@ ...@@ -59,22 +67,25 @@
<!-- Fin onglet Co-responsable --> <!-- Fin onglet Co-responsable -->
<?php <?php
$coresponsablesRequestData = null;
if (isset($this->request->data['Coresponsable']['coresponsables'])) { if (isset($this->request->data['Coresponsable']['coresponsables'])) {
$coresponsablesRequestData = $this->request->data['Coresponsable']['coresponsables']; $coresponsablesRequestData = $this->request->data['Coresponsable']['coresponsables'];
} else {
$coresponsablesRequestData = null;
} }
if (isset($this->request->data['WebdpoCoresponsable'])) { $coresponsabilitefieldsRequestData = null;
if (isset($this->request->data['WebdpoCoresponsable']) && !empty($this->request->data['WebdpoCoresponsable'])) {
$coresponsabilitefieldsRequestData = $this->request->data['WebdpoCoresponsable']; $coresponsabilitefieldsRequestData = $this->request->data['WebdpoCoresponsable'];
} else { }
$coresponsabilitefieldsRequestData = null;
$validationErrors = null;
if (isset($this->validationErrors['WebdpoCoresponsable']) && !empty($this->validationErrors['WebdpoCoresponsable'])) {
$validationErrors = $this->validationErrors['WebdpoCoresponsable'];
} }
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function () {
$(document).ready(function () {
let eventSelect = $("#coresponsables"); let eventSelect = $("#coresponsables");
$(eventSelect).select2({ $(eventSelect).select2({
width: '100%', width: '100%',
...@@ -100,17 +111,35 @@ if (isset($this->request->data['WebdpoCoresponsable'])) { ...@@ -100,17 +111,35 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
let templateFieldsCoresponsable = <?php echo json_encode($templateFieldsCoresponsable);?>; let templateFieldsCoresponsable = <?php echo json_encode($templateFieldsCoresponsable);?>;
let coresponsablesRequestData = <?php echo json_encode($coresponsablesRequestData);?>; let coresponsablesRequestData = <?php echo json_encode($coresponsablesRequestData);?>;
let coresponsabilitefieldsRequestData = <?php echo json_encode($coresponsabilitefieldsRequestData);?>; let coresponsabilitefieldsRequestData = <?php echo json_encode($coresponsabilitefieldsRequestData);?>;
let validationErrors = <?php echo json_encode($validationErrors);?>;
if (coresponsablesRequestData) { if (coresponsablesRequestData) {
$(coresponsablesRequestData).each(function (key, val) { $(coresponsablesRequestData).each(function (key, val) {
createCard(templateFieldsCoresponsable, infoCoresponsables, val, coresponsabilitefieldsRequestData); createCard(templateFieldsCoresponsable, infoCoresponsables, val, coresponsabilitefieldsRequestData);
}); });
// Mise en évidence des champs en erreur
if (validationErrors !== null) {
$.each(validationErrors, function (responsableId, fieldError) {
$.each(fieldError, function (field, errorMessage) {
$('#cr_' + responsableId + '_' + field).closest('div').after('<div class="error-message">'+errorMessage.toString()+'</div>');
});
});
}
} }
// Quand on sélectionne dans le champ Co-responsable(s) // Quand on sélectionne dans le champ Co-responsable(s)
$(eventSelect).on("select2:select", function (e) { $(eventSelect).on("select2:select", function (e) {
let idSelect = e.params.data.id; let idSelect = e.params.data.id;
createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect); createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect);
$('.calendar').datetimepicker({
viewMode: 'year',
startView: 'decade',
format: 'dd/mm/yyyy',
minView: 2,
language: 'fr'
});
}); });
// Quand on déselectionne dans le champ Co-responsable(s) // Quand on déselectionne dans le champ Co-responsable(s)
...@@ -124,6 +153,14 @@ if (isset($this->request->data['WebdpoCoresponsable'])) { ...@@ -124,6 +153,14 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
$('input[type="hidden"][name="data[Coresponsable][currentCoresponsable]['+id+'][coresponsable_id]"]').remove(); $('input[type="hidden"][name="data[Coresponsable][currentCoresponsable]['+id+'][coresponsable_id]"]').remove();
}); });
$('.calendar').datetimepicker({
viewMode: 'year',
startView: 'decade',
format: 'dd/mm/yyyy',
minView: 2,
language: 'fr'
});
}); });
function createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect, coresponsabilitefieldsRequestData = null) { function createCard(templateFieldsCoresponsable, infoCoresponsables, idSelect, coresponsabilitefieldsRequestData = null) {
...@@ -211,14 +248,27 @@ if (isset($this->request->data['WebdpoCoresponsable'])) { ...@@ -211,14 +248,27 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
// On attribut la valeur au champ si il y en a une. // On attribut la valeur au champ si il y en a une.
if (coresponsabilitefieldsRequestData !== null) { if (coresponsabilitefieldsRequestData !== null) {
console.log(coresponsabilitefieldsRequestData);
$.each(coresponsabilitefieldsRequestData[idSelect], function (key, val) { $.each(coresponsabilitefieldsRequestData[idSelect], function (key, val) {
let fieldId = '#cr_' + idSelect + '_' + key;
if (jQuery.isArray(val)) { if (jQuery.isArray(val)) {
let ifMultiSelect = $(fieldId + '[name="data[WebdpoCoresponsable]['+idSelect+']['+key+'][]"]');
$.each(val, function (k, v) { $.each(val, function (k, v) {
$('#' + key + v).attr("checked", "checked"); if (ifMultiSelect.length) {
$(fieldId + ' option[value="' + v + '"]').prop("selected", true);
} else {
$('#' + key + v).prop("checked", true);
}
}); });
} else { } else {
$('#cr_' + idSelect + '_' + key).val(val); let ifRadio = $('input[type="radio"][name="data[WebdpoCoresponsable]['+idSelect+']['+key+']"][value="'+val+'"]');
if (ifRadio.length) {
$(ifRadio).prop("checked",true);
} else {
$(fieldId).val(val);
}
} }
}); });
} }
......
...@@ -83,6 +83,7 @@ $line = 1; ...@@ -83,6 +83,7 @@ $line = 1;
'text' => $options['label'], 'text' => $options['label'],
'class' => 'col-md-4' 'class' => 'col-md-4'
], ],
'class' => 'form-control calendar',
'required' => $options['obligatoire'], 'required' => $options['obligatoire'],
'placeholder' => $options['placeholder'] 'placeholder' => $options['placeholder']
]); ]);
...@@ -380,7 +381,6 @@ $line = 1; ...@@ -380,7 +381,6 @@ $line = 1;
// Si le champ est de type "radio" // Si le champ est de type "radio"
if ($('#'+value['hasValue']).attr('type') == "radio") { if ($('#'+value['hasValue']).attr('type') == "radio") {
$('#'+value['ifTheField']).parent().parent().on('show', function() { $('#'+value['ifTheField']).parent().parent().on('show', function() {
$('#'+value['ifTheField']).parent().find('input[type=radio]:checked').each(function () { $('#'+value['ifTheField']).parent().find('input[type=radio]:checked').each(function () {
if ($(this).val() == $('#'+value['hasValue']).attr('value')) { if ($(this).val() == $('#'+value['hasValue']).attr('value')) {
......
...@@ -57,16 +57,19 @@ ...@@ -57,16 +57,19 @@
<!-- Fin onglet Soustraitance --> <!-- Fin onglet Soustraitance -->
<?php <?php
$soustraitancesRequestData = null;
if (isset($this->request->data['Soustraitance']['soustraitances'])) { if (isset($this->request->data['Soustraitance']['soustraitances'])) {
$soustraitancesRequestData = $this->request->data['Soustraitance']['soustraitances']; $soustraitancesRequestData = $this->request->data['Soustraitance']['soustraitances'];
} else {
$soustraitancesRequestData = null;
} }
if (isset($this->request->data['WebdpoSoustraitance'])) { $soustraitancefieldsRequestData = null;
if (isset($this->request->data['WebdpoSoustraitance']) && !empty($this->request->data['WebdpoSoustraitance'])) {
$soustraitancefieldsRequestData = $this->request->data['WebdpoSoustraitance']; $soustraitancefieldsRequestData = $this->request->data['WebdpoSoustraitance'];
} else { }
$soustraitancefieldsRequestData = null;
$validationErrors = null;
if (isset($this->validationErrors['WebdpoSoustraitance']) ) {
$validationErrors = $this->validationErrors['WebdpoSoustraitance'];
} }
?> ?>
...@@ -99,11 +102,21 @@ if (isset($this->request->data['WebdpoSoustraitance'])) { ...@@ -99,11 +102,21 @@ if (isset($this->request->data['WebdpoSoustraitance'])) {
let templateFieldsSoustraitance = <?php echo json_encode($templateFieldsSoustraitance);?>; let templateFieldsSoustraitance = <?php echo json_encode($templateFieldsSoustraitance);?>;
let soustraitancesRequestData = <?php echo json_encode($soustraitancesRequestData);?>; let soustraitancesRequestData = <?php echo json_encode($soustraitancesRequestData);?>;
let soustraitancefieldsRequestData = <?php echo json_encode($soustraitancefieldsRequestData);?>; let soustraitancefieldsRequestData = <?php echo json_encode($soustraitancefieldsRequestData);?>;
let validationErrors = <?php echo json_encode($validationErrors);?>;
if (soustraitancesRequestData) { if (soustraitancesRequestData) {
$(soustraitancesRequestData).each(function (key, val) { $(soustraitancesRequestData).each(function (key, val) {
createCardSoustraitant(templateFieldsSoustraitance, infoSoustraitances, val, soustraitancefieldsRequestData); createCardSoustraitant(templateFieldsSoustraitance, infoSoustraitances, val, soustraitancefieldsRequestData);
}); });
// Mise en évidence des champs en erreur
if (validationErrors !== null) {
$.each(validationErrors, function (soustraitantId, fieldError) {
$.each(fieldError, function (field, errorMessage) {
$('#st_' + soustraitantId + '_' + field).closest('div').after('<div class="error-message">'+errorMessage.toString()+'</div>');
});
});
}
} }
$(eventSelect).on("select2:select", function (e) { $(eventSelect).on("select2:select", function (e) {
...@@ -194,9 +207,7 @@ if (isset($this->request->data['WebdpoSoustraitance'])) { ...@@ -194,9 +207,7 @@ if (isset($this->request->data['WebdpoSoustraitance'])) {
// On attribut la valeur au champ si il y en a une. // On attribut la valeur au champ si il y en a une.
if (soustraitancefieldsRequestData !== null) { if (soustraitancefieldsRequestData !== null) {
console.log(soustraitancefieldsRequestData);
$.each(soustraitancefieldsRequestData[idSelect], function (key, val) { $.each(soustraitancefieldsRequestData[idSelect], function (key, val) {
console.log(val);
if (jQuery.isArray(val)) { if (jQuery.isArray(val)) {
$.each(val, function (k, v) { $.each(val, function (k, v) {
$('#' + key + v).attr("checked", "checked"); $('#' + key + v).attr("checked", "checked");
......
...@@ -4,7 +4,7 @@ echo $this->Html->script('scroll'); ...@@ -4,7 +4,7 @@ echo $this->Html->script('scroll');
$typeCreateForm = isset($typeCreateForm) === true ? $typeCreateForm : ''; $typeCreateForm = isset($typeCreateForm) === true ? $typeCreateForm : '';
?> ?>
<div class="col-md-12" id="forScroll" style="padding: 0;"> <div class="col-md-12 forScroll">
<div class="btn-group-<?php echo $typeCreateForm;?>" role="group"> <div class="btn-group-<?php echo $typeCreateForm;?>" role="group">
<!-- Bouton Petit champ texte --> <!-- Bouton Petit champ texte -->
<button type="button" class="btn btn-default-default btn-sm btn-input-<?php echo $typeCreateForm;?>" id="btn-small-text-<?php echo $typeCreateForm;?>"> <button type="button" class="btn btn-default-default btn-sm btn-input-<?php echo $typeCreateForm;?>" id="btn-small-text-<?php echo $typeCreateForm;?>">
...@@ -68,13 +68,15 @@ $typeCreateForm = isset($typeCreateForm) === true ? $typeCreateForm : ''; ...@@ -68,13 +68,15 @@ $typeCreateForm = isset($typeCreateForm) === true ? $typeCreateForm : '';
<!-- Bouton ajout d'une condition --> <!-- Bouton ajout d'une condition -->
<?php <?php
echo $this->Html->link('<i class="fa fa-plus fa-lg"></i>' . ' ' . __d('formulaire', 'formulaire.btnCondition'), ['#' => '#'], [ if ($typeCreateForm === 'formulaire') {
'id' => 'btn-condition-'.$typeCreateForm, echo $this->Html->link('<i class="fa fa-plus fa-lg"></i>' . ' ' . __d('formulaire', 'formulaire.btnCondition'), ['#' => '#'], [
'escape' => false, 'id' => 'btn-condition-' . $typeCreateForm,
'data-toggle' => 'modal', 'escape' => false,
'data-target' => '#modalAddCondtion', 'data-toggle' => 'modal',
'class' => 'btn btn-default-primary btn-sm' 'data-target' => '#modalAddCondtion',
]); 'class' => 'btn btn-default-primary btn-sm'
]);
}
?> ?>
</div> </div>
......
<?php <?php
echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js'); echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js');
debug($this->validationErrors); debug($this->request->data);
if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche']) || if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche']) ||
isset($this->validationErrors['WebdpoCoresponsable']) && !empty($this->validationErrors['WebdpoCoresponsable']) || isset($this->validationErrors['WebdpoCoresponsable']) && !empty($this->validationErrors['WebdpoCoresponsable']) ||
...@@ -18,7 +18,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr ...@@ -18,7 +18,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr
$champ = null; $champ = null;
foreach ($this->validationErrors['WebdpoFiche'] as $key => $errorChamps) { foreach ($this->validationErrors['WebdpoFiche'] as $key => $errorChamps) {
foreach ($fields['formulaire'] as $tab => $value) { foreach ($fields['formulaire'] as $tab => $value) {
// foreach ($field as $value) {
if (is_array($value)) { if (is_array($value)) {
foreach ($value as $val) { foreach ($value as $val) {
$options = json_decode($val['details'], true); $options = json_decode($val['details'], true);
...@@ -30,7 +29,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr ...@@ -30,7 +29,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr
if (isset($options['name']) === true && $key == $options['name']) { if (isset($options['name']) === true && $key == $options['name']) {
$champ = $options['label']; $champ = $options['label'];
} }
// }
} }
foreach ($errorChamps as $error) { foreach ($errorChamps as $error) {
...@@ -290,7 +288,7 @@ echo $this->WebcilForm->end(); ...@@ -290,7 +288,7 @@ echo $this->WebcilForm->end();
// Mise en évidence des onglets ayant des erreurs. // Mise en évidence des onglets ayant des erreurs.
$('div.form-group .error-message').closest('div.tab-pane').each(function(idx, pane) { $('div.form-group .error-message').closest('div.tab-pane').each(function(idx, pane) {
var a = $( "a[href='#"+$(pane).attr('id')+"']" ); let a = $( "a[href='#"+$(pane).attr('id')+"']" );
$(a).closest("li").addClass("form-error"); $(a).closest("li").addClass("form-error");
$(a).append("<span class='fa fa-exclamation-circle fa-danger' aria-hidden='true'><\/span>"); $(a).append("<span class='fa fa-exclamation-circle fa-danger' aria-hidden='true'><\/span>");
}); });
...@@ -304,7 +302,7 @@ echo $this->WebcilForm->end(); ...@@ -304,7 +302,7 @@ echo $this->WebcilForm->end();
placeholder: '__ __ __ __ __' placeholder: '__ __ __ __ __'
}); });
var coresponsable = $("#coresponsable").val(); let coresponsable = $("#coresponsable").val();
displayTabCoresponsables(coresponsable); displayTabCoresponsables(coresponsable);
$("#coresponsable").change(function () { $("#coresponsable").change(function () {
...@@ -313,11 +311,11 @@ echo $this->WebcilForm->end(); ...@@ -313,11 +311,11 @@ echo $this->WebcilForm->end();
displayTabCoresponsables(idCoresponsable); displayTabCoresponsables(idCoresponsable);
}); });
var sousTraitance = $("#soustraitance").val(); let sousTraitance = $("#soustraitance").val();
displayTabSousTraitances(sousTraitance); displayTabSousTraitances(sousTraitance);
$("#soustraitance").change(function () { $("#soustraitance").change(function () {
var newValSousTraitance = $(this).val(); let newValSousTraitance = $(this).val();
displayTabSousTraitances(newValSousTraitance); displayTabSousTraitances(newValSousTraitance);
}); });
......
...@@ -985,7 +985,7 @@ div.navbar-fixed-top ul.nav.navbar-nav.pull-right > li.dropdown > a.dropdown-tog ...@@ -985,7 +985,7 @@ div.navbar-fixed-top ul.nav.navbar-nav.pull-right > li.dropdown > a.dropdown-tog
content: "\f077"; content: "\f077";
} }
#forScroll.fixed { .forScroll.fixed {
top: 51px; top: 51px;
position: fixed; position: fixed;
z-index: 1; z-index: 1;
......
$(document).ready(function () { $(document).ready(function () {
function scrolled() { function scrolled() {
var currentScroll = document.body.scrollTop || document.documentElement.scrollTop, let currentScroll = document.body.scrollTop || document.documentElement.scrollTop,
forScroll = $('#forScroll'), forScroll = $('.tab-pane.active .forScroll'),
forScrollWidth = $(forScroll).width(), forScrollWidth = $(forScroll).width(),
navbarHeight = $('div.navbar-fixed-top').height(); navbarHeight = $('div.navbar-fixed-top').height();
...@@ -18,7 +18,7 @@ $(document).ready(function () { ...@@ -18,7 +18,7 @@ $(document).ready(function () {
addEventListener('scroll', scrolled, false); addEventListener('scroll', scrolled, false);
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e){ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e){
var forScroll = $('#forScroll'); let forScroll = $('.tab-pane.active .forScroll');
$(forScroll).removeClass('fixed'); $(forScroll).removeClass('fixed');
$(forScroll).css('width', ''); $(forScroll).css('width', '');
......
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