Commit 62752bbf authored by tguillon's avatar tguillon
Browse files

Correction : règles de validation

parent 2b109c41
......@@ -348,3 +348,6 @@ msgstr "Cette valeur n'est pas possible"
msgid "Validate::checkNotBlankIfCountOptionsChecked"
msgstr "Champ obligatoire"
msgid "Validate::checkMultipleIf"
msgstr "Champ obligatoire"
......@@ -252,6 +252,26 @@ class AppModel extends Model
return $success;
}
public function checkMultipleIf($checks, $reference, $condition, $values, $options = [], $caseInsensitive = false)
{
if (!(is_array($checks) && !empty($reference))) {
return false;
}
$success = true;
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
foreach ($checks as $value) {
if (in_array($referenceValue, $values, true) === $condition) {
$success = Validation::multiple($value, $options, $caseInsensitive) && $success;
}
}
}
return $success;
}
/**
* Exemple: 'champ' => notEmptyIf( $check, 'reference', true, array( 'P' ) )
*
......
......@@ -302,6 +302,16 @@ class Fiche extends AppModel {
'message' => '... est déjà utilisée.'
]
],
// 'realisation_pia' => [
// 'notBlank' => [
// 'rule' => ['notBlank']
// ]
// ],
// 'depot_pia' => [
// 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
// ]
// ],
];
/**
......
......@@ -81,8 +81,6 @@ class WebdpoFiche extends AppModel {
'rule' => ['checkNotBlankIf', 'realisation_pia', true, ['1']]
]
],
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
'coresponsable' => [
'notBlank' => [
'rule' => ['notBlank']
......@@ -93,6 +91,11 @@ class WebdpoFiche extends AppModel {
'rule' => ['notBlank']
]
],
// 'obligation_pia' => [
// 'checkNotBlankIf' => [
// 'rule' => ['checkNotBlankIf', 'usepia', true, [true]]
// ]
// ],
// ---------------------------------------------------------------------
// 'declarantraisonsociale' => [
// 'notBlank' => [
......@@ -471,64 +474,24 @@ class WebdpoFiche extends AppModel {
],
// ---------------------------------------------------------------------
'criteres' => [
'checkNotBlankIf' => [
'rule' => ['checkNotBlankIf', 'localisation_large_echelle', true, ['Non']]
'checkNotBlankIfMultiple' => [
'rule' => ['checkMultipleIf', 'localisation_large_echelle', true, ['Non'], ['min' => 1]]
],
'checkBlankIf' => [
'rule' => ['checkBlankIf', 'localisation_large_echelle', true, ['Oui']]
]
],
// 'traitement_considere_risque' => [
// 'checkNotBlankIfCountOptionsChecked' => [
// 'rule' => ['checkNotBlankIfCountOptionsChecked', 'criteres', 1]
// ],
// 'checkBlankIfCountOptionsChecked' => [
// 'rule' => ['checkBlankIfCountOptionsChecked', 'criteres', 2]
// ]
// ],
'traitement_considere_risque' => [
'checkNotBlankIfCountOptionsChecked' => [
'rule' => ['checkNotBlankIfCountOptionsChecked', 'criteres', 1]
],
'checkBlankIfCountOptionsChecked' => [
'rule' => ['checkBlankIfCountOptionsChecked', 'criteres', 2]
]
],
// ---------------------------------------------------------------------
];
public function checkNotBlankIfCountOptionsChecked($checks, $reference, $nbOptionsChecked)
{
if (!(is_array($checks) && !empty($reference))) {
return false;
}
$success = true;
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
$countOptionsChecked = count($referenceValue);
if ($countOptionsChecked == $nbOptionsChecked) {
$success = Validation::notBlank($checks) && $success;
}
}
return $success;
}
public function checkBlankIfCountOptionsChecked($checks, $reference, $nbOptionsChecked)
{
if (!(is_array($checks) && !empty($reference))) {
return false;
}
$success = true;
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
$countOptionsChecked = count($referenceValue);
if ($countOptionsChecked >= $nbOptionsChecked) {
$success = Validation::blank($checks) && $success;
}
}
return $success;
}
public function saveWithVirtualFields($data, $champs, $formulaireOptions, $formulaireOLD = false, $actionAdd = false)
{
$success = true;
......@@ -643,10 +606,6 @@ class WebdpoFiche extends AppModel {
$validationErrors = $Fiche->validationErrors + $this->validationErrors;
$this->validationErrors = Hash::merge($this->validationErrors, $dynamicValidationErrors);
if ($success == false) {
return $success;
}
if ($actionAdd === false) {
$idsToDelete = array_keys($Fiche->Valeur->find('list', [
'conditions' => [
......@@ -659,7 +618,7 @@ class WebdpoFiche extends AppModel {
if (empty($idsToDelete) == false) {
$success = $Fiche->Valeur->deleteAll([
'Valeur.id' => $idsToDelete
]) && $success;
]) && $success;
}
}
......@@ -794,6 +753,50 @@ class WebdpoFiche extends AppModel {
return ($data);
}
public function checkNotBlankIfCountOptionsChecked($checks, $reference, $nbOptionsChecked)
{
if (!(is_array($checks) && !empty($reference))) {
return false;
}
$success = true;
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
if(empty($referenceValue)) {
$countOptionsChecked = 0;
} else {
$countOptionsChecked = count($referenceValue);
}
if ($countOptionsChecked == $nbOptionsChecked) {
$success = Validation::notBlank($checks) && $success;
}
}
return $success;
}
public function checkBlankIfCountOptionsChecked($checks, $reference, $nbOptionsChecked)
{
if (!(is_array($checks) && !empty($reference))) {
return false;
}
$success = true;
$referenceValue = Hash::get($this->data, "{$this->alias}.{$reference}");
if (!empty($checks)) {
$countOptionsChecked = count($referenceValue);
if ($countOptionsChecked >= $nbOptionsChecked) {
$success = Validation::blank($checks) && $success;
}
}
return $success;
}
public function beforeValidate($options = array()) {
// $this->data = $this->cleanupData($this->data);
return parent::beforeValidate($options);
......
<?php
//echo $this->Html->script('Fiches/pia');
echo $this->Html->script('Fiches/pia');
$empty = true;
if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
......@@ -40,7 +40,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'placeholder' => false,
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.relation_fournisseurs' => [
'id' => 'relation_fournisseurs',
......@@ -59,7 +59,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'placeholder' => false,
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.gestion_electoral' => [
'id' => 'gestion_electoral',
......@@ -79,7 +79,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.comites_entreprise' => [
'id' => 'comites_entreprise',
......@@ -99,7 +99,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.association' => [
'id' => 'association',
......@@ -119,7 +119,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.sante_prise_patient' => [
'id' => 'sante_prise_patient',
......@@ -139,7 +139,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.avocats' => [
'id' => 'avocats',
......@@ -159,7 +159,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.greffiers' => [
'id' => 'greffiers',
......@@ -179,7 +179,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.notaires' => [
'id' => 'notaires',
......@@ -199,7 +199,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.collectivites_affaires_scolaires' => [
'id' => 'collectivites_affaires_scolaires',
......@@ -219,7 +219,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.controles_acces' => [
'id' => 'controles_acces',
......@@ -239,7 +239,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.ethylotests' => [
'id' => 'ethylotests',
......@@ -259,7 +259,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
]
]);
?>
......@@ -299,7 +299,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'placeholder' => false,
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.donnees_genetiques' => [
'id' => 'donnees_genetiques',
......@@ -319,7 +319,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.profils_personnes_gestion_rh' => [
'id' => 'profils_personnes_gestion_rh',
......@@ -339,7 +339,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.surveiller_constante_employes' => [
'id' => 'surveiller_constante_employes',
......@@ -359,7 +359,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.gestion_alertes_sociale_sanitaire' => [
'id' => 'gestion_alertes_sociale_sanitaire',
......@@ -379,7 +379,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.gestion_alertes_professionnelle' => [
'id' => 'gestion_alertes_professionnelle',
......@@ -399,7 +399,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.donnees_sante_registre' => [
'id' => 'donnees_sante_registre',
......@@ -419,7 +419,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.profilage_rupture_contrat' => [
'id' => 'profilage_rupture_contrat',
......@@ -439,7 +439,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.mutualises_manquements_rupture_contrat' => [
'id' => 'mutualises_manquements_rupture_contrat',
......@@ -459,7 +459,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.profilage_donnees_externes' => [
'id' => 'profilage_donnees_externes',
......@@ -479,7 +479,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.biometriques' => [
'id' => 'biometriques',
......@@ -499,7 +499,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.gestion_logements_sociaux' => [
'id' => 'gestion_logements_sociaux',
......@@ -519,7 +519,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.accompagnement_social' => [
'id' => 'accompagnement_social',
......@@ -539,7 +539,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
],
'WebdpoFiche.localisation_large_echelle' => [
'id' => 'localisation_large_echelle',
......@@ -559,7 +559,7 @@ if (in_array($this->request->params['action'], ['edit', 'show']) === true) {
'data-placeholder' => ' ',
'between' => '<div class="col-md-2 top5">',
'before' => '<hr>',
'default' => 'Non'
// 'default' => 'Non'
]
]);
?>
......
<?php
echo $this->Html->script('jquery-mask-plugin/dist/jquery.mask.min.js');
debug($this->validationErrors);
if (isset($this->validationErrors['WebdpoFiche']) && !empty($this->validationErrors['WebdpoFiche'])) {
?>
<div class="alert alert-danger" role="alert">
......
......@@ -136,20 +136,9 @@ $(document).ready(function () {
//
displayFieldRisque();
$('input[type=checkbox]').change(function () {
var nbChecked = $(":checkbox:checked").length;
if (nbChecked >= 2 ){
$('#traitement_considere_risque').parent().parent().hide();
// alert("PIA OBLIGATOIRE");
$('#obligation_pia').val("1");
} else if (nbChecked == 1) {
$('#traitement_considere_risque').parent().parent().show();
} else {
// alert("PIA NON REQUIS");
$('#obligation_pia').val("0");
$('#traitement_considere_risque').parent().parent().hide();
}
displayFieldRisque();
});
$('#traitement_considere_risque').change(function () {
......@@ -157,20 +146,34 @@ $(document).ready(function () {
// alert('PIA OBLIGATOIRE');
$('#obligation_pia').val('1');
} else {
// alert('CHARGE AU DPO de TRANCHER');
// alert('PIA NON OBLIGATOIRE');
$('#obligation_pia').val('0');
}
});
});
function displayFieldRisque()
{
var nbChecked = $(":checkbox:checked").length;
if (nbChecked >= 2 ){
$('#traitement_considere_risque').parent().parent().hide();
// alert("PIA OBLIGATOIRE");
$('#obligation_pia').val('1');
} else if (nbChecked == 1) {
$('#traitement_considere_risque').parent().parent().show();
} else if (nbChecked == 0) {
$('#traitement_considere_risque').parent().parent().hide();
}
}
function displayAllInputsPia() {
$('.displayInput').parent().parent().hide();
$('#liste_obligatoire').hide();
$('#liste_criteres').hide();
}
function displayFieldPiaListNotRequired(id, val)
{
function displayFieldPiaListNotRequired(id, val) {
if (val == 'Non') {
$('#'+id).parent().parent().next('div').removeAttr('style');
......@@ -212,7 +215,7 @@ function displayFieldPiaListRequired(id, val)
$('#liste_criteres').hide();
// alert("PIA OBILGATOIRE");
$('#obligation_pia').val("1");
$('#obligation_pia').val('1');
}
}
......
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