diff --git a/assets/controllers/pages/part_withdraw_modal_controller.js b/assets/controllers/pages/part_withdraw_modal_controller.js index f7e6e7a7..2fdba906 100644 --- a/assets/controllers/pages/part_withdraw_modal_controller.js +++ b/assets/controllers/pages/part_withdraw_modal_controller.js @@ -31,6 +31,38 @@ export default class extends Controller this.element.querySelector('input[name="action"]').setAttribute('value', action); this.element.querySelector('input[name="lot_id"]').setAttribute('value', lotID); + //Set the title + const titleElement = this.element.querySelector('.modal-title'); + switch (action) { + case 'withdraw': + titleElement.innerText = titleElement.getAttribute('data-withdraw'); + break; + case 'add': + titleElement.innerText = titleElement.getAttribute('data-add'); + break; + case 'move': + titleElement.innerText = titleElement.getAttribute('data-move'); + break; + } + + //Hide the move to lot select, if the action is not move (and unhide it, if it is) + const moveToLotSelect = this.element.querySelector('#withdraw-modal-move-to'); + if (action === 'move') { + moveToLotSelect.classList.remove('d-none'); + } else { + moveToLotSelect.classList.add('d-none'); + } + + //First unhide all move to lot options and then hide the currently selected lot + const moveToLotOptions = moveToLotSelect.querySelectorAll('input[type="radio"]'); + moveToLotOptions.forEach(option => option.parentElement.classList.remove('d-none')); + moveToLotOptions.forEach(option => { + if (option.getAttribute('value') === lotID) { + option.parentElement.classList.add('d-none'); + option.selected = false; + } + }); + //For adding parts there is no limit on the amount to add if (action == 'add') { amountInput.removeAttribute('max'); diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 7c626b8a..125956d5 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -81,7 +81,7 @@ class PartController extends AbstractController * @throws Exception */ public function show(Part $part, Request $request, TimeTravel $timeTravel, HistoryHelper $historyHelper, - DataTableFactory $dataTable, ParameterExtractor $parameterExtractor, ?string $timestamp = null): Response + DataTableFactory $dataTable, ParameterExtractor $parameterExtractor, PartLotWithdrawAddHelper $withdrawAddHelper, ?string $timestamp = null): Response { $this->denyAccessUnlessGranted('read', $part); @@ -122,6 +122,7 @@ class PartController extends AbstractController 'timeTravel' => $timeTravel_timestamp, 'description_params' => $parameterExtractor->extractParameters($part->getDescription()), 'comment_params' => $parameterExtractor->extractParameters($part->getComment()), + 'withdraw_add_helper' => $withdrawAddHelper, ] ); } @@ -330,6 +331,9 @@ class PartController extends AbstractController if ($this->isCsrfTokenValid('part_withraw' . $part->getID(), $request->request->get('_csfr'))) { //Retrieve partlot from the request $partLot = $em->find(PartLot::class, $request->request->get('lot_id')); + if($partLot === null) { + throw new \RuntimeException('Part lot not found!'); + } //Ensure that the partlot belongs to the part if($partLot->getPart() !== $part) { throw new \RuntimeException("The origin partlot does not belong to the part!"); diff --git a/src/Services/Parts/PartLotWithdrawAddHelper.php b/src/Services/Parts/PartLotWithdrawAddHelper.php index 3fbfb074..a757398d 100644 --- a/src/Services/Parts/PartLotWithdrawAddHelper.php +++ b/src/Services/Parts/PartLotWithdrawAddHelper.php @@ -39,6 +39,11 @@ class PartLotWithdrawAddHelper return false; } + //Part must contain more than 0 parts + if ($partLot->getAmount() <= 0) { + return false; + } + return true; } diff --git a/templates/Parts/info/_part_lots.html.twig b/templates/Parts/info/_part_lots.html.twig index 3742dac0..5663ccd8 100644 --- a/templates/Parts/info/_part_lots.html.twig +++ b/templates/Parts/info/_part_lots.html.twig @@ -63,18 +63,23 @@
- + diff --git a/templates/Parts/info/_withdraw_modal.html.twig b/templates/Parts/info/_withdraw_modal.html.twig index 0a039d4f..79ae2ea2 100644 --- a/templates/Parts/info/_withdraw_modal.html.twig +++ b/templates/Parts/info/_withdraw_modal.html.twig @@ -1,9 +1,13 @@ -