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

Modification : Ajout, modification multi coresponsabilité

parent 43763661
......@@ -447,6 +447,21 @@ class FichesController extends AppController
return $responsables;
}
protected function _coresponsables($fiche_id)
{
$coresponsables = $this->Coresponsable->find('all', [
'conditions' => [
'fiche_id' => $fiche_id
]
]);
$coresponsableSelected = Hash::extract($coresponsables, '{n}.Coresponsable.responsable_id');
$this->request->data['Coresponsable']['coresponsables'] = $coresponsableSelected;
$this->set(compact('coresponsables'));
}
/**
* @return array
*/
......@@ -588,6 +603,8 @@ class FichesController extends AppController
$this->redirect($this->Referers->get());
}
// debug($this->request->data);die;
$success = true;
$this->Fiche->begin();
......@@ -700,6 +717,9 @@ class FichesController extends AppController
$responsables = $this->_responsables();
$this->set(compact('responsables'));
$coresponsable = $this->_coresponsables($id);
// debug($coresponsable);die;
if ($formulaireOLD['Formulaire']['oldformulaire'] === true) {
// Reprise des données de la version v1.1.0 pour la coresponsabilité
$responsables = $this->_responsables();
......
......@@ -847,15 +847,43 @@ class WebdpoFiche extends AppModel {
private function coresponsableSave ($fiche_id, $dataCoresponsable, $useCoresponsable)
{
if (empty($fiche_id)) {
return false;
}
$success = true;
$Coresponsable = ClassRegistry::init('Coresponsable');
if (empty($fiche_id)) {
$success = false;
if ($useCoresponsable == false) {
$success = $Coresponsable->deleteAll([
'Coresponsable.fiche_id' => $fiche_id
]) && $success;
}
if (isset($dataCoresponsable['currentCoresponsable']) && !empty($dataCoresponsable['currentCoresponsable'])) {
foreach ($dataCoresponsable['currentCoresponsable'] as $currentCoresponsable) {
if (($key = array_search($currentCoresponsable['responsable_id'], $dataCoresponsable['coresponsables'])) !== false) {
unset($dataCoresponsable['coresponsables'][$key]);
}
}
$noDeleteCoresponsable = Hash::extract($dataCoresponsable['currentCoresponsable'], '{n}.coresponsable_id');
$success = $Coresponsable->deleteAll([
'Coresponsable.id !=' => $noDeleteCoresponsable
]) && $success;
} else {
$success = $Coresponsable->deleteAll([
'Coresponsable.fiche_id' => $fiche_id
]) && $success;
}
if ($success === false) {
return $success;
}
if ($useCoresponsable == true && $success === true) {
if (!empty($dataCoresponsable['coresponsables'])) {
$Responsable = ClassRegistry::init('Responsable');
$Coresponsable = ClassRegistry::init('Coresponsable');
foreach ($dataCoresponsable['coresponsables'] as $coresponsable_id) {
$responsable = $Responsable->find('first', [
......@@ -865,20 +893,20 @@ class WebdpoFiche extends AppModel {
]);
$Coresponsable->create([
'fiche_id' => $fiche_id,
'responsable_id' => $responsable['Responsable']['id'],
'nomcoresponsable' => $responsable['Responsable']['nomresponsable'],
'prenomcoresponsable' => $responsable['Responsable']['prenomresponsable'],
'fonctioncoresponsable' => $responsable['Responsable']['fonctionresponsable'],
'emailcoresponsable' => $responsable['Responsable']['emailresponsable'],
'telephonecoresponsable' => $responsable['Responsable']['telephoneresponsable'],
'raisonsocialestructure' => $responsable['Responsable']['raisonsocialestructure'],
'siretstructure' => $responsable['Responsable']['siretstructure'],
'apestructure' => $responsable['Responsable']['apestructure'],
'telephonestructure' => $responsable['Responsable']['telephonestructure'],
'faxstructure' => $responsable['Responsable']['faxstructure'],
'adressestructure' => $responsable['Responsable']['adressestructure'],
'emailstructure' => $responsable['Responsable']['emailstructure']
'fiche_id' => $fiche_id,
'responsable_id' => $responsable['Responsable']['id'],
'nomcoresponsable' => $responsable['Responsable']['nomresponsable'],
'prenomcoresponsable' => $responsable['Responsable']['prenomresponsable'],
'fonctioncoresponsable' => $responsable['Responsable']['fonctionresponsable'],
'emailcoresponsable' => $responsable['Responsable']['emailresponsable'],
'telephonecoresponsable' => $responsable['Responsable']['telephoneresponsable'],
'raisonsocialestructure' => $responsable['Responsable']['raisonsocialestructure'],
'siretstructure' => $responsable['Responsable']['siretstructure'],
'apestructure' => $responsable['Responsable']['apestructure'],
'telephonestructure' => $responsable['Responsable']['telephonestructure'],
'faxstructure' => $responsable['Responsable']['faxstructure'],
'adressestructure' => $responsable['Responsable']['adressestructure'],
'emailstructure' => $responsable['Responsable']['emailstructure']
]);
$success = false !== $Coresponsable->save(null, ['atomic' => false]) && $success;
}
......
......@@ -35,7 +35,94 @@
</div>
</div>
<div id="coresponsableCards"></div>
<div id="coresponsableCards">
<?php
if (!empty($coresponsables)) {
foreach ($coresponsables as $key => $coresponsable) {
// echo $this->Form->hidden("Coresponsable.{$coresponsable['Coresponsable']['id']}.responsable_id", [
// 'value' => $coresponsable['Coresponsable']['responsable_id'],
// 'id' => false
// ]);
echo $this->Form->hidden("Coresponsable.currentCoresponsable.{$coresponsable['Coresponsable']['responsable_id']}.responsable_id", [
'value' => $coresponsable['Coresponsable']['responsable_id'],
// 'class' => 'hiddenCurrentCoresponsable',
'id' => false
]);
echo $this->Form->hidden("Coresponsable.currentCoresponsable.{$coresponsable['Coresponsable']['responsable_id']}.coresponsable_id", [
'value' => $coresponsable['Coresponsable']['id'],
// 'class' => 'hiddenCurrentCoresponsable',
'id' => false
]);
?>
<div id="card_<?php echo $coresponsable['Coresponsable']['responsable_id'];?>" class="row">
<div class="col-md-12">
<div class="panel panel-default ">
<div class="panel-body">
<div class="col-md-6">
<h4>
<?php echo $coresponsable['Coresponsable']['raisonsocialestructure'];?>
</h4>
<p>
<u>N° SIRET :</u>
<?php echo $coresponsable['Coresponsable']['siretstructure'];?>
</p>
<p>
<u>Code APE :</u>
<?php echo $coresponsable['Coresponsable']['apestructure'];?>
</p>
<p>
<u>Adresse :</u>
<?php echo $coresponsable['Coresponsable']['adressestructure'];?>
</p>
<?php
if (!empty($coresponsable['Coresponsable']['telephonestructure'])) {
?>
<p>
<u>Téléphone :</u>
<?php echo $coresponsable['Coresponsable']['telephonestructure'];?>
</p>
<?php
}
if (!empty($coresponsable['Coresponsable']['faxstructure'])) {
?>
<p>
<u>Fax :</u>
<?php echo $coresponsable['Coresponsable']['faxstructure'];?>
</p>
<?php
}
?>
</div>
<div class="col-md-6">
<h4>
<?php echo $coresponsable['Coresponsable']['prenomcoresponsable'] . ' ' . $coresponsable['Coresponsable']['nomcoresponsable'];?>
</h4>
<p>
<u>Fonction :</u>
<?php echo $coresponsable['Coresponsable']['fonctioncoresponsable'];?>
</p>
<p>
<u>Téléphone :</u>
<?php echo $coresponsable['Coresponsable']['telephonecoresponsable'];?>
</p>
<p>
<u>E-mail :</u>
<?php echo $coresponsable['Coresponsable']['emailcoresponsable'];?>
</p>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
</div>
<?php
}
?>
......@@ -70,17 +157,11 @@
let formCoreponsableFields = '';
if (fields) {
// formCoreponsableFields = '<div id="form-container-coresponsable" class="form-container col-md-12">';
// formCoreponsableFields = formCoreponsableFields + fields;
// formCoreponsableFields = formCoreponsableFields + '</div>';
formCoreponsableFields = '<div id="form-container-coresponsable">';
formCoreponsableFields = formCoreponsableFields + fields;
formCoreponsableFields = formCoreponsableFields + '</div>';
}
if (coresponsable['adressestructure'] != null) {
colLeft = colLeft + '<p>' +
'<u>Adresse :</u>' +
......@@ -111,7 +192,7 @@
let nomComplet = coresponsable['prenomresponsable'] + ' ' + coresponsable['nomresponsable'];
$('#coresponsableCards').append(' <div id="card_'+idSelect+'" class="row">' +
$('#coresponsableCards').append('<div id="card_'+idSelect+'" class="row">' +
'<div class="col-md-12">' +
' <div class="panel panel-default ">' +
' <div class="panel-body">' +
......@@ -150,9 +231,13 @@
});
$(eventSelect).on("select2:unselect", function (e) {
let idRemove = '#card_' + e.params.data.id;
let id = e.params.data.id
let idRemove = '#card_' + id;
$('#coresponsableCards').find(idRemove).remove();
$('input[type="hidden"][name="data[Coresponsable][currentCoresponsable]['+id+'][responsable_id]"]').remove();
$('input[type="hidden"][name="data[Coresponsable][currentCoresponsable]['+id+'][coresponsable_id]"]').remove();
});
});
......
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