diff --git a/assets/controllers/archiving_commentary_controller.js b/assets/controllers/archiving_commentary_controller.js index 499decb..21123b3 100755 --- a/assets/controllers/archiving_commentary_controller.js +++ b/assets/controllers/archiving_commentary_controller.js @@ -4,6 +4,10 @@ export default class extends Controller { static targets = ['archivingCommentary', 'archivingCommentaryMessage', 'archivingButton']; + connect() { + // Initialization code or leave empty if not needed + } + archivingCommentary() { console.log("archivingCommentary" + this.archivingCommentaryTarget.value); const commentary = this.archivingCommentaryTarget.value.trim(); @@ -18,4 +22,46 @@ export default class extends Controller { this.archivingCommentaryMessageTarget.style.color = "red"; // Display the message in red color. } } + + + archiveWithCommentary(event) { + + const entityType = this.trainingOperatorCodeTarget.dataset.entityType; + const efncid = this.trainingOperatorCodeTarget.dataset.efncid; + + // Prevent default form submission behavior + event.preventDefault(); + + // Validate commentary as per your logic; here directly using validateCommentary method + this.validateCommentary(); + + if (!this.archivingButtonTarget.disabled) { + const url = '/efnc/admin/archive/'; // Replace with your actual endpoint + const commentary = this.archivingCommentaryTarget.value; + + fetch(url, { + method: 'POST', + body: JSON.stringify({ archivingCommentary: commentary }), + headers: { + 'Content-Type': 'application/json', + // Add other headers like CSRF token if necessary + } + }) + .then(response => { + // Handle successful response + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); // Or `response.text()` if your server sends something other than JSON + }) + .then(data => { + // Do something with the data + console.log(data); + }) + .catch(error => { + // Handle errors here + console.error('Fetch error:', error); + }); + } + } } \ No newline at end of file diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 8a58b3f..cc4e36e 100755 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -350,8 +350,13 @@ public function productVersionCreation(Request $request): Response public function archiveEntity(Request $request, string $entityType, int $id): Response { $originUrl = $request->headers->get('referer'); - $this->logger->info('Archive entity: ' . $entityType . ' ' . $id . ' full request: ' . json_encode($request->getContent())); - $result = $this->entityDeletionService->archivedEntity($entityType, $id, $request); + $user = $this->getUser()->getUsername(); + $commentary = $request->request->get('archivingCommentary'); + + $this->logger->info($user . ' archived entity: ' . $entityType . ' ' . $id . ' ' . 'commentaire: ' . $commentary . ' full request: ' . json_encode($request->getContent())); + + $result = $this->entityDeletionService->archivedEntity($entityType, $id, $commentary, $user); + if ($result == false) { $this->addFlash('danger', 'L\'élément n\'a pas pu être archivé'); return $this->redirect($originUrl); diff --git a/src/Entity/EFNC.php b/src/Entity/EFNC.php index 1bd1908..9fd41fc 100755 --- a/src/Entity/EFNC.php +++ b/src/Entity/EFNC.php @@ -95,8 +95,8 @@ class EFNC #[ORM\Column(nullable: true)] private ?bool $archived = null; - #[ORM\ManyToOne(inversedBy: 'eFNCs')] - private ?User $lastModifier = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $lastModifier = null; #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $archivingCommentary = null; @@ -530,12 +530,12 @@ public function setArchived(?bool $archived): static return $this; } - public function getLastModifier(): ?User + public function getLastModifier(): ?string { return $this->lastModifier; } - public function setLastModifier(?User $lastModifier): static + public function setLastModifier(?string $lastModifier): static { $this->lastModifier = $lastModifier; diff --git a/src/Entity/User.php b/src/Entity/User.php index ab08b05..f0b39da 100755 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -39,13 +39,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(length: 255, nullable: true)] private ?string $emailAddress = null; - #[ORM\OneToMany(mappedBy: 'lastModifier', targetEntity: EFNC::class)] - private Collection $eFNCs; - - public function __construct() - { - $this->eFNCs = new ArrayCollection(); - } public function getId(): ?int { @@ -129,34 +122,4 @@ public function setEmailAddress(?string $emailAddress): static return $this; } - - /** - * @return Collection - */ - public function getEFNCs(): Collection - { - return $this->eFNCs; - } - - public function addEFNC(EFNC $eFNC): static - { - if (!$this->eFNCs->contains($eFNC)) { - $this->eFNCs->add($eFNC); - $eFNC->setLastModifier($this); - } - - return $this; - } - - public function removeEFNC(EFNC $eFNC): static - { - if ($this->eFNCs->removeElement($eFNC)) { - // set the owning side to null (unless already changed) - if ($eFNC->getLastModifier() === $this) { - $eFNC->setLastModifier(null); - } - } - - return $this; - } } diff --git a/src/Service/FormModificationService.php b/src/Service/FormModificationService.php index 0d69114..227cfb3 100755 --- a/src/Service/FormModificationService.php +++ b/src/Service/FormModificationService.php @@ -50,8 +50,7 @@ public function __construct( public function modifyNCForm( EFNC $efnc, Request $request, - FormInterface $form1, - User $user + FormInterface $form1 ) { $now = new \DateTime(); diff --git a/templates/services/efnc/modification/form_modification.html.twig b/templates/services/efnc/modification/form_modification.html.twig index bdb799d..af65351 100755 --- a/templates/services/efnc/modification/form_modification.html.twig +++ b/templates/services/efnc/modification/form_modification.html.twig @@ -183,53 +183,58 @@ Modifier + + + {% endif %} + + {{ form_end(form1) }} +
+ +
+ class="row justify-content-md-center">
-
- - -
+ class="col-md-12"> + +
-
+
+
+ + {% if is_granted('ROLE_MASTER_ADMIN') %} - {% if is_granted('ROLE_MASTER_ADMIN') %} - - Cloturer - - {% endif %} -
+ {% endif %}
- - {% endif %} -
- {{ form_end(form1) }} + +
{% endblock %}