mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add validation of existing file
This commit is contained in:
parent
299491cb5b
commit
fcc74c993d
@ -13,6 +13,7 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* @Route("/{_locale}/person/{person}/document")
|
||||
@ -21,6 +22,18 @@ use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
||||
*/
|
||||
class DocumentPersonController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/", name="person_document_index", methods="GET")
|
||||
*/
|
||||
@ -84,8 +97,12 @@ class DocumentPersonController extends Controller
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($document);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully registered"));
|
||||
|
||||
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
return $this->render('ChillDocStoreBundle:PersonDocument:new.html.twig', [
|
||||
@ -128,10 +145,14 @@ class DocumentPersonController extends Controller
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->getDoctrine()->getManager()->flush();
|
||||
|
||||
$this->addFlash('success', $this->translator->trans("The document is successfully updated"));
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'person_document_edit',
|
||||
['id' => $document->getId(), 'person' => $person->getId()]);
|
||||
} elseif ($form->isSubmitted() and !$form->isValid()) {
|
||||
$this->addFlash('error', $this->translator->trans("This form contains errors"));
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
|
@ -27,6 +27,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.yml');
|
||||
$loader->load('services/media.yml');
|
||||
$loader->load('services/controller.yml');
|
||||
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@ use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Chill\MainBundle\Entity\HasScopeInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @ORM\MappedSuperclass()
|
||||
@ -22,6 +23,9 @@ class Document implements HasScopeInterface
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
* @Assert\Length(
|
||||
* min=2, max=250
|
||||
* )
|
||||
*/
|
||||
private $title;
|
||||
|
||||
@ -44,6 +48,7 @@ class Document implements HasScopeInterface
|
||||
* targetEntity="Chill\DocStoreBundle\Entity\StoredObject",
|
||||
* cascade={"persist"}
|
||||
* )
|
||||
* @Assert\Valid()
|
||||
*/
|
||||
private $object;
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace Chill\DocStoreBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
|
||||
use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists;
|
||||
|
||||
/**
|
||||
* Represent a document stored in an object store
|
||||
@ -14,6 +15,9 @@ use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface;
|
||||
*
|
||||
* @ORM\Entity()
|
||||
* @ORM\Table("chill_doc.stored_object")
|
||||
* @AsyncFileExists(
|
||||
* message="The file is not stored properly"
|
||||
* )
|
||||
*/
|
||||
class StoredObject implements AsyncFileInterface
|
||||
{
|
||||
|
@ -65,7 +65,9 @@ class PersonDocumentType extends AbstractType
|
||||
->add('description', TextareaType::class, [
|
||||
'required' => false
|
||||
])
|
||||
->add('object', StoredObjectType::class)
|
||||
->add('object', StoredObjectType::class, [
|
||||
'error_bubbling' => true
|
||||
])
|
||||
->add('scope', ScopePickerType::class, [
|
||||
'center' => $options['center'],
|
||||
'role' => $options['role']
|
||||
|
8
Resources/config/services/controller.yml
Normal file
8
Resources/config/services/controller.yml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
Chill\DocStoreBundle\Controller\:
|
||||
resource: '../../../Controller'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\DocStoreBundle\Controller\DocumentPersonController:
|
||||
autowire: true
|
||||
|
2
Resources/translation/messages.yml
Normal file
2
Resources/translation/messages.yml
Normal file
@ -0,0 +1,2 @@
|
||||
## YAML Template.
|
||||
---
|
1
Resources/translation/validators.fr.yml
Normal file
1
Resources/translation/validators.fr.yml
Normal file
@ -0,0 +1 @@
|
||||
The file is not stored properly: Le fichier n'est pas téléchargé correctement
|
@ -1 +0,0 @@
|
||||
{{ form_widget(form) }}
|
@ -17,14 +17,32 @@
|
||||
|
||||
{% extends "ChillPersonBundle::layout.html.twig" %}
|
||||
|
||||
{% import "@ChillDocStore/Macro/macro.html.twig" as m %}
|
||||
|
||||
{% set activeRouteKey = '' %}
|
||||
|
||||
{% block title %}{{ 'Editing document for %name%'|trans({ '%name%': person.firstName|capitalize ~ ' ' ~ person.lastName } )|capitalize }}{% endblock %}
|
||||
{% block personcontent %}
|
||||
<h1>{{ 'Edit Document' | trans }}</h1>
|
||||
|
||||
{{ form_errors(form) }}
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig', {'button_label': 'Update'}) }}
|
||||
|
||||
{{ form_row(form.title) }}
|
||||
{{ form_row(form.date) }}
|
||||
{{ form_row(form.category) }}
|
||||
{{ form_row(form.scope) }}
|
||||
{{ form_row(form.description) }}
|
||||
<div class="container">
|
||||
<div class="grid-4 clear">
|
||||
<label>{{ 'Existing document'|trans }}</label>
|
||||
</div>
|
||||
<div class="grid-8">
|
||||
{{ m.download_button(document.object, document.title) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ form_row(form.object, { 'label': 'Document', 'existing': document.object }) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li class="cancel">
|
||||
@ -33,16 +51,20 @@
|
||||
</a>
|
||||
</li>
|
||||
<li class="edit">
|
||||
<button class="sc-button bt-edit">{{ 'Edit'|trans }}</button>
|
||||
<button class="sc-button bt-edit">{{ 'Edit'|trans }}</button>
|
||||
</li>
|
||||
{% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
|
||||
{# {% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
|
||||
<li class="delete">
|
||||
{{ include('ChillDocStoreBundle:PersonDocument:_delete_form.html.twig') }}
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %} #}
|
||||
</ul>
|
||||
|
||||
{{ form_end(form) }}
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script src="{{ asset('build/async_upload.js') }}" type="text/javascript"></script>
|
||||
{% endblock %}
|
||||
|
@ -22,9 +22,11 @@
|
||||
|
||||
{% block personcontent %}
|
||||
<h1>{{ 'Create new Document' | trans }}</h1>
|
||||
|
||||
{{ form_errors(form) }}
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ include('ChillDocStoreBundle:PersonDocument:_form.html.twig') }}
|
||||
{{ form_widget(form) }}
|
||||
|
||||
<ul class="record_actions">
|
||||
<li class="cancel">
|
||||
|
Loading…
x
Reference in New Issue
Block a user