add creation of new history line

This commit is contained in:
Julien Fastré 2013-12-01 19:55:56 +01:00
parent 9c249160cc
commit c9204e32d8
5 changed files with 88 additions and 5 deletions

View File

@ -23,6 +23,64 @@ class HistoryController extends Controller
}
public function createAction($personId) {
$person = $this->_getPerson($personId);
if ($person === null) {
return $this->createNotFoundException('Person not found');
}
$history = new PersonHistoryFile(new \DateTime());
$history->setPerson($person);
$motivesArray = $this->get('service_container')
->getParameter('person.history.close.motives');
$form = $this->createForm(new PersonHistoryFileType($motivesArray),
$history);
$request = $this->getRequest();
if ($request->getMethod() === 'POST') {
$form->handleRequest($request);
$errors = $this->_validatePerson($person);
$flashBag = $this->get('session')->getFlashBag();
if ($form->isValid(array('Default', 'closed'))
&& count($errors) === 0) {
$em = $this->getDoctrine()->getManager();
$em->persist($history);
$em->flush();
$flashBag->add('success',
$this->get('translator')->trans(
'controller.Person.history.create.done'));
return $this->redirect($this->generateUrl('chill_person_history_list',
array('id' => $person->getId())));
} else {
$flashBag->add('danger', $this->get('translator')
->trans('controller.Person.history.create.error'));
foreach($errors as $error) {
$flashBag->add('info', $error->getMessage());
}
}
}
return $this->render('CLChillPersonBundle:History:update.html.twig',
array('form' => $form->createView(),
'person' => $person ) );
}
public function updateAction($id, $historyId){
$em = $this->getDoctrine()->getManager();

View File

@ -32,7 +32,9 @@ class PersonHistoryFileType extends AbstractType
'choices' => $this->motives,
'required' => true
))
->add('memo', 'textarea')
->add('memo', 'textarea', array(
'required' => false
))
;
}

View File

@ -29,6 +29,11 @@ chill_person_history_list:
order: 100
label: menu.person.history
chill_person_history_create:
pattern: /{personId}/history/create
defaults: { _controller: CLChillPersonBundle:History:create }
chill_person_history_update:
pattern: /{id}/history/{historyId}/update
defaults: { _controller: CLChillPersonBundle:History:update }

View File

@ -42,11 +42,14 @@ controller:
open:
done: Bravo ! Le dossier de <em>%name%</em> est maintenant ouvert.
error: Les informations introduites ne sont pas valides. Le dossier n'a pu être ouvert.
error_in_fom: Le formulaire n'est pas valide.
error_in_form: Le formulaire n'est pas valide.
is_not_closed: Le dossier de <em>%name%</em> n'est pas fermé. Il ne peut donc être ouvert.
update:
done: Bravo ! La mise à jour de l'historique a réussi !
error: Les données introduites ne sont pas valides. Veuillez vérifier les informations ci-dessous.
create:
done: Bravo ! L'historique a été modifié.
error: Les données introduites ne sont pas valides. Veuillez vérifier les informations ci-dessous.
views:
layout:
@ -92,6 +95,7 @@ views:
edit: Modifier
close: Clôre le dossier
open: Ouvrir le dossier
create: Nouvel ouverture-fermeture à une autre date
close:
last_opening_since: Dernière ouverture le %last_opening%.
action: Clotûrer

View File

@ -7,7 +7,7 @@
{% block personcontent %}
<table class="striped rounded">
<table class="rounded">
<thead>
<tr>
<th>{{ 'views.Person.hlist.dateOpening_title'|trans }}</th>
@ -17,8 +17,9 @@
</thead>
<tbody>
{% set i = 0 %}
{% for history in histories %}
<tr>
<tr class="{% if i is not even %}striped{% endif %}">
<td>{{ history.dateOpening|date(date_format) }}</td>
<td>{% spaceless %}
{% if history.isOpen %}
@ -39,7 +40,14 @@
</div>
</td>
</tr>
{% if history.memo is not empty %}
<tr class="{% if i is not even %}striped{% endif %}">
<td colspan="3">
<pre>{{ history.memo }}</pre>
</td>
</tr>
{% endif %}
{% set i = i+1 %}
{% endfor %}
</tbody>
@ -49,6 +57,12 @@
<div class="form_control">
<div class="btn small warning icon-right entypo icon-plus">
<a href="{{ path ('chill_person_history_create', {'personId' : person.id } ) }}">
{{ 'views.Person.hlist.create'|trans }}
</a>
</div>
<div class="controls">
<div class="btn medium danger icon-right entypo {% spaceless %}
{% if person.isOpen == true %}