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

Modification : du typage des annexes

parent eba9abbd
......@@ -59,13 +59,69 @@ class TypagesController extends AppController {
];
if ($this->request->is('post')) {
debug("rrrr");die;
if (isset($this->request->data['TypageOrganisation']) && empty($this->request->data['TypageOrganisation']['organisation_id'])) {
$this->redirect(['action' => 'index']);
}
debug($this->request->data);
$success = true;
$this->TypageOrganisation->begin();
$organisations_ids = Hash::extract($this->request->data, 'TypageOrganisation.organisation_id');
$typage_ids = Hash::extract($this->request->data, 'TypageOrganisation.typage_id');
foreach ($organisations_ids as $organisation_id) {
$typageEntite = $this->TypageOrganisation->find('list', [
'conditions' => [
'organisation_id' => $organisation_id
],
'fields' => [
'typage_id'
]
]);
$result = array_intersect($typageEntite, $typage_ids);
$typage_ids = array_diff($typage_ids, $result);
foreach ($typage_ids as $typage_id) {
$data = [
'TypageOrganisation' => [
'typage_id' => $typage_id,
'organisation_id' => $organisation_id,
]
];
$this->TypageOrganisation->create($data);
$success = $success && false !== $this->TypageOrganisation->save(null, ['atomic' => false]);
}
}
if ($success == true) {
$this->Organisation->commit();
$this->Session->setFlash(__d('responsable', 'responsable.flashsuccessSousTraitantAffecterEnregistrer'), 'flashsuccess');
$this->redirect(['action' => 'index']);
} else {
$this->Organisation->rollback();
$this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurEnregistrementSousTraitantAffecter'), 'flasherror');
}
}
$this->paginate = $query;
$typages = $this->paginate($this->Typage);
$this->set(compact('typages'));
$mesOrganisations = $this->WebcilUsers->organisations(
'list',
[
'droits' => 'add' === $this->request->params['action']
? ListeDroit::CREER_UTILISATEUR
: ListeDroit::MODIFIER_UTILISATEUR
]
);
$this->set(compact('typages', 'mesOrganisations'));
}
/**
......@@ -121,14 +177,14 @@ class TypagesController extends AppController {
$data = $this->request->data;
if ($this->request->params['action'] === 'add') {
$data['Typage']['createdbyorganisation'] = $this->Session->read('Organisation.id');
}
if ($this->request->params['action'] === 'edit') {
$data['Typage']['id'] = $id;
}
if ($this->request->params['action'] === 'add') {
$data['Typage']['createdbyorganisation'] = $this->Session->read('Organisation.id');
}
$this->Typage->create($data);
$success = $success && false !== $this->Typage->save();
......@@ -196,32 +252,30 @@ class TypagesController extends AppController {
throw new ForbiddenException(__d('default', 'default.flasherrorPasDroitPage'));
}
// @TODO
// $associationResponsable = $this->ResponsableOrganisation->find('all', [
// 'conditions' => [
// 'responsable_id' => $id
// ]
// ]);
//
// if (empty($associationResponsable)) {
// $success = true;
// $this->Responsable->begin();
//
// $success = $success && false !== $this->Responsable->deleteAll([
// 'id' => $id
// ]);
//
// if ($success == true) {
// $this->Responsable->commit();
// $this->Session->setFlash(__d('responsable', 'responsable.flashsuccessSuppressionResponsableEntite'), 'flashsuccess');
// } else {
// $this->Responsable->rollback();
// $this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurSuppressionResponsableEntite'), 'flasherror');
// }
// } else {
// $this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurAssociationExistanteResponsableEntite'), 'flasherror');
// }
$associationTypage = $this->TypageOrganisation->find('all', [
'conditions' => [
'typage_id' => $id
]
]);
if (empty($associationTypage)) {
$success = true;
$this->Typage->begin();
$success = $success && false !== $this->Typage->deleteAll([
'id' => $id
]);
if ($success == true) {
$this->Typage->commit();
$this->Session->setFlash(__d('responsable', 'responsable.flashsuccessSuppressionResponsableEntite'), 'flashsuccess');
} else {
$this->Typage->rollback();
$this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurSuppressionResponsableEntite'), 'flasherror');
}
} else {
$this->Session->setFlash(__d('responsable', 'responsable.flasherrorErreurAssociationExistanteResponsableEntite'), 'flasherror');
}
$this->redirect(['action' => 'index']);
}
......
......@@ -82,6 +82,15 @@ msgstr "Dissocier le type d'annexe de l'entité"
msgid "typage.confirmationDissocierType"
msgstr "Voulez vous dissocier le type d'annexe "
msgid "typage.popupTitreAffecterType"
msgstr "Associer un ou plusieurs type(s) d'annexe à une ou plusieurs entité(s)"
msgid "typage.champSelectOrganisation"
msgstr "Sélectionnez une ou plusieurs entité(s)"
msgid "typage.placeholderSelectOrganisation"
msgstr "Sélectionnez une ou plusieurs entité(s)"
###############################################################################
######################## View/Typages/add.ctp|edit.ctp ########################
......
<!-- Pop-up de modification de la position d'un traitement pour la génération -->
<div class="modal fade" id="modalAddTypeToEntity" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<?php
echo $this->WebcilForm->create('Typage',[
'autocomplete' => 'off',
'inputDefaults' => ['div' => false],
'class' => 'form-horizontal',
'novalidate' => 'novalidate'
]);
?>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title" id="myModalLabel">
<?php
echo __d('typage', 'typage.popupTitreAffecterType');
?>
</h4>
</div>
<div class="modal-body">
<?php
echo $this->WebcilForm->input('TypageOrganisation.organisation_id', [
'id' => 'organisation_id',
'class' => 'form-control usersDeroulant',
'options' => $mesOrganisations,
'empty' => true,
'multiple' => true,
'data-placeholder' => __d('typage','typage.placeholderSelectOrganisation'),
'label' => [
'text' => __d('typage','typage.champSelectOrganisation'),
]
]);
?>
</div>
<div class="modal-footer">
<div class="btn-group">
<button type="button" class="btn btn-default-default" data-dismiss="modal">
<i class="fa fa-times-circle fa-lg"><!----></i>
<?php
echo __d('default', 'default.btnAnnuler');
?>
</button>
<?php
echo $this->WebcilForm->button("<i class='fa fa-floppy-o fa-lg'><!----></i>" . __d('default', 'default.btnEnregistrer'), [
'type' => 'submit',
'url' => [
'controller' => 'soutraitants',
'action' => 'toto'
],
'class' => 'btn btn-default-success',
'escape' => false,
'id' => 'btnSave'
]);
?>
</div>
</div>
</div>
<?php
echo $this->WebcilForm->end();
?>
</div>
</div>
\ No newline at end of file
......@@ -113,7 +113,7 @@
<h3>
<div class='text-warning'>
<i class="fa fa-fw fa-exclamation-triangle"><!----></i>
<i class="fa fa-fw fa-exclamation-triangle"></i>
<?php
echo __d('responsable', 'responsable.warningTexteExplication')
?>
......@@ -202,17 +202,17 @@
<?php
$items = Hash::extract($responsable, 'Responsable.fonctionresponsable');
if (empty($items) === false) {
echo '<li><strong>Fonction : </strong>' . implode('</li><li>', $items) . '</li>';
echo '<ul><li><strong>Fonction : </strong>' . implode('</li><li>', $items) . '</li></ul>';
}
$items = Hash::extract($responsable, 'Responsable.telephoneresponsable');
if (empty($items) === false) {
echo '<li><strong>Téléphone : </strong>'.implode('</li><li>', $items).'</li>';
echo '<ul><li><strong>Téléphone : </strong>'.implode('</li><li>', $items).'</li></ul>';
}
$items = Hash::extract($responsable, 'Responsable.emailresponsable');
if (empty($items) === false) {
echo '<li><strong>E-mail : </strong>'.implode('</li><li>', $items).'</li>';
echo '<ul><li><strong>E-mail : </strong>'.implode('</li><li>', $items).'</li></ul>';
}
?>
</td>
......@@ -222,22 +222,22 @@
<?php
$items = Hash::extract($responsable, 'Responsable.raisonsocialestructure');
if (empty($items) === false) {
echo '<li><strong>Structure : </strong>' . implode('</li><li>', $items) . '</li>';
echo '<ul><li><strong>Structure : </strong>' . implode('</li><li>', $items) . '</li></ul>';
}
$items = Hash::extract($responsable, 'Responsable.telephonestructure');
if (empty($items) === false) {
echo '<li><strong>Téléphone : </strong>'.implode('</li><li>', $items).'</li>';
echo '<ul><li><strong>Téléphone : </strong>'.implode('</li><li>', $items).'</li></ul>';
}
$items = Hash::extract($responsable, 'Responsable.faxstructure');
if (empty($items) === false) {
echo '<li><strong>Fax : </strong>'.implode('</li><li>', $items).'</li>';
echo '<ul><li><strong>Fax : </strong>'.implode('</li><li>', $items).'</li></ul>';
}
$items = Hash::extract($responsable, 'Responsable.emailstructure');
if (empty($items) === false) {
echo '<li><strong>E-mail : </strong>'.implode('</li><li>', $items).'</li>';
echo '<ul><li><strong>E-mail : </strong>'.implode('</li><li>', $items).'</li></ul>';
}
?>
</td>
......
......@@ -10,12 +10,11 @@ echo $pagination;
?>
<?php
debug($typages);
if (!empty($typages)) {
?>
<fieldset>
<div class="pull-left btnAffecterEntite" style="margin-left:25px">
<button type="button" id="btnAffecterEntite" class="btn btn-default-primary btn_affecterEntite" data-toggle="modal" data-target="#modalAffecterEntite">
<button type="button" id="btnAffecterEntite" class="btn btn-default-primary btn_affecterEntite" data-toggle="modal" data-target="#modalAddTypeToEntity">
<span class="fa fa-link fa-lg"><!----></span>
<?php
echo __d('typage', 'typage.btnAffecterEntite');
......@@ -141,6 +140,10 @@ if (!empty($typages)) {
?>
</div>
<?php
echo $this->element("Typages/modals/modalAddTypeToEntity");
?>
<script type="text/javascript">
$(document).ready(function () {
......@@ -171,5 +174,28 @@ if (!empty($typages)) {
$('input[type="hidden"]').remove()
});
$('#modalAddTypeToEntity').on('shown.bs.modal', function () {
var checkboxes = $('table tbody input[type=checkbox]'),
hidden, value;
$(checkboxes).each(function(idx) {
if ($(checkboxes[idx]).prop('checked') === true) {
value = $(checkboxes[idx]).prop('value');
hidden = '<input type="hidden" name="data[TypageOrganisation][typage_id][]" value="'+value+'" />';
$("#modalAddTypeToEntity .modal-body").append(hidden);
}
});
});
$('#btnSave').attr('disabled', true);
// Lors d'action sur une menu déroulant : organisation_id
$("#organisation_id").change(function () {
if ($("#organisation_id").val() != null) {
$('#btnSave').removeAttr('disabled');
} else {
$('#btnSave').attr('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