| ... | ... |
@@ -82,15 +82,30 @@ |
| 82 | 82 |
{% if buchen.buchbar %}
|
| 83 | 83 |
<form hx-post="/_ajax/vr_wa/v1/slot?do=reservate" enctype="multipart/form-data"> |
| 84 | 84 |
<input type="hidden" name="id" value="{{ id }}">
|
| 85 |
- <fieldset> |
|
| 86 |
- <label for="res-behaelter"><strong>Liefernde Behältermenge<sup class="text-danger">*</sup></strong></label> |
|
| 87 |
- <select id="res-behaelter" name="behaelter" required> |
|
| 88 |
- <option value="">-</option> |
|
| 89 |
- {% for option in buchen.behaelter %}
|
|
| 90 |
- <option value="{{ option }}">{{ option }}</option>
|
|
| 91 |
- {% endfor %}
|
|
| 92 |
- </select> |
|
| 93 |
- </fieldset> |
|
| 85 |
+ <div class="grid-md u-gap-2"> |
|
| 86 |
+ <div class="grid-c-6 mb-2 mb-0-md"> |
|
| 87 |
+ <fieldset> |
|
| 88 |
+ <label for="res-behaeltereinheit"><strong>Liefernde Behältereinheit<sup class="text-danger">*</sup></strong></label> |
|
| 89 |
+ <select id="res-behaeltereinheit" name="unit" hx-get="/_ajax/vr_wa/v1/slot?do=availableUnitAmount&id={{ id }}" hx-target="#res-behaelter" hx-indicator="#wa-slot-{{ id }}">
|
|
| 90 |
+ <option value="">{{ 'tl_vr_wa_units.containers.0'|trans([], 'contao_tl_vr_wa_units') }}</option>
|
|
| 91 |
+ {% for value, option in buchen.units %}
|
|
| 92 |
+ <option value="{{ value }}">{{ option }}</option>
|
|
| 93 |
+ {% endfor %}
|
|
| 94 |
+ </select> |
|
| 95 |
+ </fieldset> |
|
| 96 |
+ </div> |
|
| 97 |
+ <div class="grid-c-6 mb-2 mb-0-md"> |
|
| 98 |
+ <fieldset> |
|
| 99 |
+ <label for="res-behaelter"><strong>Menge<sup class="text-danger">*</sup></strong></label> |
|
| 100 |
+ <select id="res-behaelter" name="behaelter" required> |
|
| 101 |
+ <option value="">-</option> |
|
| 102 |
+ {% for option in buchen.behaelter %}
|
|
| 103 |
+ <option value="{{ option }}">{{ option }}</option>
|
|
| 104 |
+ {% endfor %}
|
|
| 105 |
+ </select> |
|
| 106 |
+ </fieldset> |
|
| 107 |
+ </div> |
|
| 108 |
+ </div> |
|
| 94 | 109 |
<fieldset> |
| 95 | 110 |
<label for="res-upload"><strong>Dateianhang</strong></label> |
| 96 | 111 |
<input type="file" id="res-upload" name="upload"> |
| ... | ... |
@@ -106,6 +121,8 @@ |
| 106 | 121 |
{% endif %}
|
| 107 | 122 |
|
| 108 | 123 |
</div> |
| 124 |
+ |
|
| 125 |
+ <div class="loader animated loading"></div> |
|
| 109 | 126 |
</div> |
| 110 | 127 |
{% if modal %}</div>{% endif %}
|
| 111 | 128 |
{% endblock %}
|
| ... | ... |
@@ -36,6 +36,7 @@ use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungLeseartModel; |
| 36 | 36 |
use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungRebsorteModel; |
| 37 | 37 |
use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungReservationModel; |
| 38 | 38 |
use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungSlotsModel; |
| 39 |
+use vonRotenberg\WeinanlieferungBundle\Model\WeinanlieferungUnitsModel; |
|
| 39 | 40 |
|
| 40 | 41 |
/** |
| 41 | 42 |
* @Route("/_ajax/vr_wa/v1/slot", name="vr_wa_slot_ajax", defaults={"_scope" = "frontend", "_token_check" = false})
|
| ... | ... |
@@ -91,6 +92,9 @@ class SlotAjaxController extends AbstractController |
| 91 | 92 |
case 'updateReservation': |
| 92 | 93 |
return $this->updateReservation(); |
| 93 | 94 |
|
| 95 |
+ case 'availableUnitAmount': |
|
| 96 |
+ return $this->renderAvailableUnitAmount(); |
|
| 97 |
+ |
|
| 94 | 98 |
case 'delete': |
| 95 | 99 |
return $this->deleteReservation(); |
| 96 | 100 |
} |
| ... | ... |
@@ -125,6 +129,19 @@ class SlotAjaxController extends AbstractController |
| 125 | 129 |
|
| 126 | 130 |
// Build data |
| 127 | 131 |
$intAvailableBehaelter = max(0,$Slot->getAvailableBehaelter()); |
| 132 |
+ $arrUnits = []; |
|
| 133 |
+ |
|
| 134 |
+ if (($Site = $Slot->getRelated('pid')) !== null)
|
|
| 135 |
+ {
|
|
| 136 |
+ if (($Units = $Site->getRelated('units')) !== null)
|
|
| 137 |
+ {
|
|
| 138 |
+ foreach ($Units as $unit) |
|
| 139 |
+ {
|
|
| 140 |
+ $arrUnits[$unit->id] = $unit->title . ' (' . $unit->containers . ' '.$this->translator->trans('tl_vr_wa_units.containers.0', [], 'contao_tl_vr_wa_units').')';
|
|
| 141 |
+ } |
|
| 142 |
+ } |
|
| 143 |
+ |
|
| 144 |
+ } |
|
| 128 | 145 |
|
| 129 | 146 |
$arrData = [ |
| 130 | 147 |
'modal' => $blnModal, |
| ... | ... |
@@ -137,6 +154,7 @@ class SlotAjaxController extends AbstractController |
| 137 | 154 |
'buchen' => [ |
| 138 | 155 |
'buchbar' => (boolean) $intAvailableBehaelter, |
| 139 | 156 |
'behaelter' => range(min($intAvailableBehaelter,1),$intAvailableBehaelter), |
| 157 |
+ 'units' => $arrUnits, |
|
| 140 | 158 |
], |
| 141 | 159 |
'reservations' => $arrReservations |
| 142 | 160 |
]; |
| ... | ... |
@@ -484,4 +502,40 @@ class SlotAjaxController extends AbstractController |
| 484 | 502 |
return $this->render('@Contao/modal_unauthorized.html.twig');
|
| 485 | 503 |
} |
| 486 | 504 |
|
| 505 |
+ protected function renderAvailableUnitAmount(): Response |
|
| 506 |
+ {
|
|
| 507 |
+ if (empty($_REQUEST['id'])) |
|
| 508 |
+ {
|
|
| 509 |
+ return new Response('Required parameter missing',412);
|
|
| 510 |
+ } |
|
| 511 |
+ |
|
| 512 |
+ if (($Slot = WeinanlieferungSlotsModel::findPublishedById($_REQUEST['id'])) === null) |
|
| 513 |
+ {
|
|
| 514 |
+ return new Response('Could not load slot data',500);
|
|
| 515 |
+ } |
|
| 516 |
+ |
|
| 517 |
+ $intAvailableBehaelter = max(0,$Slot->getAvailableBehaelter()); |
|
| 518 |
+ $intAmount = $intAvailableBehaelter; |
|
| 519 |
+ |
|
| 520 |
+ if (!empty($_REQUEST['unit']) && intval($_REQUEST['unit']) > 0) |
|
| 521 |
+ {
|
|
| 522 |
+ if (($Site = $Slot->getRelated('pid')) === null || ($Unit = WeinanlieferungUnitsModel::findByPk($_REQUEST['unit'])) === null)
|
|
| 523 |
+ {
|
|
| 524 |
+ return new Response('Could not load unit data', 500);
|
|
| 525 |
+ } |
|
| 526 |
+ |
|
| 527 |
+ $intAmount = floor($intAvailableBehaelter / max(1, $Unit->containers)); |
|
| 528 |
+ } |
|
| 529 |
+ |
|
| 530 |
+ $strOutput = "<select id=\"res-behaelter\" name=\"behaelter\" required> |
|
| 531 |
+<option value=\"\">-</option>\n"; |
|
| 532 |
+ for ($i = 1; $i <= $intAmount; $i++) |
|
| 533 |
+ {
|
|
| 534 |
+ $strOutput .= "<option value=\"$i\">$i</option>\n"; |
|
| 535 |
+ } |
|
| 536 |
+ $strOutput .= "</select>\n"; |
|
| 537 |
+ |
|
| 538 |
+ return new Response($strOutput); |
|
| 539 |
+ } |
|
| 540 |
+ |
|
| 487 | 541 |
} |