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
foreach ($valeurs as $key => $value) {
if ($this->Fiche->isJson($value['Valeur']['valeur'])) {
$valueDecode = json_decode($value['Valeur']['valeur']);
$valueDecode = json_decode($value['Valeur']['valeur'], true);
if (is_object($valueDecode)) {
$valueDecode = json_decode(json_encode($valueDecode), true);
}
// if (is_object($valueDecode)) {
// $valueDecode = json_decode(json_encode($valueDecode), true);
// }
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 {
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'];
......
......@@ -145,7 +145,7 @@ class WebdpoCoresponsable extends AppModel
return $data;
}
$data[$this->alias]['coresponsabilitefields'] = json_encode($data[$this->alias], true);
$data['WebdpoFiche']['coresponsabilitefields'] = json_encode($data[$this->alias], true);
}
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 -->
<div id="ongletComplementaireCoresponsable" class="tab-pane">
<br>
......@@ -59,22 +67,25 @@
<!-- Fin onglet Co-responsable -->
<?php
$coresponsablesRequestData = null;
if (isset($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'];
} else {
$coresponsabilitefieldsRequestData = null;
}
$validationErrors = null;
if (isset($this->validationErrors['WebdpoCoresponsable']) && !empty($this->validationErrors['WebdpoCoresponsable'])) {
$validationErrors = $this->validationErrors['WebdpoCoresponsable'];
}
?>
<script type="text/javascript">
$(document).ready(function () {
$(document).ready(function () {
let eventSelect = $("#coresponsables");
$(eventSelect).select2({
width: '100%',
......@@ -100,17 +111,35 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
let templateFieldsCoresponsable = <?php echo json_encode($templateFieldsCoresponsable);?>;
let coresponsablesRequestData = <?php echo json_encode($coresponsablesRequestData);?>;
let coresponsabilitefieldsRequestData = <?php echo json_encode($coresponsabilitefieldsRequestData);?>;
let validationErrors = <?php echo json_encode($validationErrors);?>;
if (coresponsablesRequestData) {
$(coresponsablesRequestData).each(function (key, val) {
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)
$(eventSelect).on("select2:select", function (e) {
let idSelect = e.params.data.id;
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)
......@@ -124,6 +153,14 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
$('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) {
......@@ -211,14 +248,27 @@ if (isset($this->request->data['WebdpoCoresponsable'])) {
// On attribut la valeur au champ si il y en a une.
if (coresponsabilitefieldsRequestData !== null) {
console.log(coresponsabilitefieldsRequestData);
$.each(coresponsabilitefieldsRequestData[idSelect], function (key, val) {
let fieldId = '#cr_' + idSelect + '_' + key;
if (jQuery.isArray(val)) {
let ifMultiSelect = $(fieldId + '[name="data[WebdpoCoresponsable]['+idSelect+']['+key+'][]"]');
$.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 {
$('#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;
'text' => $options['label'],
'class' => 'col-md-4'
],
'class' => 'form-control calendar',
'required' => $options['obligatoire'],
'placeholder' => $options['placeholder']
]);
......@@ -380,7 +381,6 @@ $line = 1;
// Si le champ est de type "radio"
if ($('#'+value['hasValue']).attr('type') == "radio") {
$('#'+value['ifTheField']).parent().parent().on('show', function() {
$('#'+value['ifTheField']).parent().find('input[type=radio]:checked').each(function () {
if ($(this).val() == $('#'+value['hasValue']).attr('value')) {
......
......@@ -57,16 +57,19 @@
<!-- Fin onglet Soustraitance -->
<?php
$soustraitancesRequestData = null;
if (isset($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'];
} else {
$soustraitancefieldsRequestData = null;
}
$validationErrors = null;
if (isset($this->validationErrors['WebdpoSoustraitance']) ) {
$validationErrors = $this->validationErrors['WebdpoSoustraitance'];
}
?>
......@@ -99,11 +102,21 @@ if (isset($this->request->data['WebdpoSoustraitance'])) {
let templateFieldsSoustraitance = <?php echo json_encode($templateFieldsSoustraitance);?>;
let soustraitancesRequestData = <?php echo json_encode($soustraitancesRequestData);?>;
let soustraitancefieldsRequestData = <?php echo json_encode($soustraitancefieldsRequestData);?>;
let validationErrors = <?php echo json_encode($validationErrors);?>;
if (soustraitancesRequestData) {
$(soustraitancesRequestData).each(function (key, val) {
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) {
......@@ -194,9 +207,7 @@ if (isset($this->request->data['WebdpoSoustraitance'])) {
// On attribut la valeur au champ si il y en a une.
if (soustraitancefieldsRequestData !== null) {
console.log(soustraitancefieldsRequestData);
$.each(soustraitancefieldsRequestData[idSelect], function (key, val) {
console.log(val);
if (jQuery.isArray(val)) {
$.each(val, function (k, v) {
$('#' + key + v).attr("checked", "checked");
......
......@@ -4,7 +4,7 @@ echo $this->Html->script('scroll');
$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">
<!-- 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;?>">
......@@ -68,13 +68,15 @@ $typeCreateForm = isset($typeCreateForm) === true ? $typeCreateForm : '';
<!-- Bouton ajout d'une condition -->
<?php
if ($typeCreateForm === 'formulaire') {
echo $this->Html->link('<i class="fa fa-plus fa-lg"></i>' . ' ' . __d('formulaire', 'formulaire.btnCondition'), ['#' => '#'], [
'id' => 'btn-condition-'.$typeCreateForm,
'id' => 'btn-condition-' . $typeCreateForm,
'escape' => false,
'data-toggle' => 'modal',
'data-target' => '#modalAddCondtion',
'class' => 'btn btn-default-primary btn-sm'
]);
}
?>
</div>
......
<?php
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']) ||
isset($this->validationErrors['WebdpoCoresponsable']) && !empty($this->validationErrors['WebdpoCoresponsable']) ||
......@@ -18,7 +18,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr
$champ = null;
foreach ($this->validationErrors['WebdpoFiche'] as $key => $errorChamps) {
foreach ($fields['formulaire'] as $tab => $value) {
// foreach ($field as $value) {
if (is_array($value)) {
foreach ($value as $val) {
$options = json_decode($val['details'], true);
......@@ -30,7 +29,6 @@ if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErr
if (isset($options['name']) === true && $key == $options['name']) {
$champ = $options['label'];
}
// }
}
foreach ($errorChamps as $error) {
......@@ -290,7 +288,7 @@ echo $this->WebcilForm->end();
// Mise en évidence des onglets ayant des erreurs.
$('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).append("<span class='fa fa-exclamation-circle fa-danger' aria-hidden='true'><\/span>");
});
......@@ -304,7 +302,7 @@ echo $this->WebcilForm->end();
placeholder: '__ __ __ __ __'
});
var coresponsable = $("#coresponsable").val();
let coresponsable = $("#coresponsable").val();
displayTabCoresponsables(coresponsable);
$("#coresponsable").change(function () {
......@@ -313,11 +311,11 @@ echo $this->WebcilForm->end();
displayTabCoresponsables(idCoresponsable);
});
var sousTraitance = $("#soustraitance").val();
let sousTraitance = $("#soustraitance").val();
displayTabSousTraitances(sousTraitance);
$("#soustraitance").change(function () {
var newValSousTraitance = $(this).val();
let newValSousTraitance = $(this).val();
displayTabSousTraitances(newValSousTraitance);
});
......
......@@ -985,7 +985,7 @@ div.navbar-fixed-top ul.nav.navbar-nav.pull-right > li.dropdown > a.dropdown-tog
content: "\f077";
}
#forScroll.fixed {
.forScroll.fixed {
top: 51px;
position: fixed;
z-index: 1;
......
$(document).ready(function () {
function scrolled() {
var currentScroll = document.body.scrollTop || document.documentElement.scrollTop,
forScroll = $('#forScroll'),
let currentScroll = document.body.scrollTop || document.documentElement.scrollTop,
forScroll = $('.tab-pane.active .forScroll'),
forScrollWidth = $(forScroll).width(),
navbarHeight = $('div.navbar-fixed-top').height();
......@@ -18,7 +18,7 @@ $(document).ready(function () {
addEventListener('scroll', scrolled, false);
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e){
var forScroll = $('#forScroll');
let forScroll = $('.tab-pane.active .forScroll');
$(forScroll).removeClass('fixed');
$(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