diff --git a/.env.example b/.env.example index f0076f022..ae6c05ab4 100644 --- a/.env.example +++ b/.env.example @@ -385,6 +385,9 @@ LB_RESOURCE_CONTACT_IS_USER=false # Tablet View Options ########################################## +# Allows to make reservations in the tablet view (true/false) +LB_TABLET_VIEW_ALLOW_RESERVATIONS=true + # Allow guest users to make reservations in tablet view (true/false) LB_TABLET_VIEW_ALLOW_GUEST_RESERVATIONS=false diff --git a/Pages/ResourceDisplayPage.php b/Pages/ResourceDisplayPage.php index db51fb5e6..f9d6ee011 100644 --- a/Pages/ResourceDisplayPage.php +++ b/Pages/ResourceDisplayPage.php @@ -167,6 +167,7 @@ public function __construct() new TermsOfServiceRepository() ); + $this->Set('AllowReservations', Configuration::Instance()->GetKey(ConfigKeys::TABLET_VIEW_ALLOW_RESERVATIONS, new BooleanConverter())); $this->Set('AllowAutocomplete', Configuration::Instance()->GetKey(ConfigKeys::TABLET_VIEW_AUTO_SUGGEST_EMAILS, new BooleanConverter())); $this->Set('ShouldLogout', false); } @@ -243,7 +244,7 @@ public function GetStartDate() $parsedDate = $this->GetQuerystring(QueryStringKeys::START_DATE); if (!empty($parsedDate)) { $startDate = Date::Parse($parsedDate, $userTimezone); - }else{ + } else { $startDate = Date::Now()->ToTimezone($userTimezone); } return $startDate; @@ -290,7 +291,8 @@ public function DisplayResourceShell() if ($futureDays == 0) { $futureDays = 1; } - $this->Set('MaxFutureDate', Date::Now()->AddDays($futureDays-1)); + $this->Set('MinDate', Date::Now()); + $this->Set('MaxFutureDate', Date::Now()->AddDays($futureDays - 1)); $this->Display('ResourceDisplay/resource-display-shell.tpl'); } diff --git a/Presenters/ResourceDisplayPresenter.php b/Presenters/ResourceDisplayPresenter.php index e68827f2c..4d4fc32fb 100644 --- a/Presenters/ResourceDisplayPresenter.php +++ b/Presenters/ResourceDisplayPresenter.php @@ -163,9 +163,9 @@ public function DisplayResource($resourcePublicId, $startDate) $layout = $this->scheduleRepository->GetLayout($scheduleId, new ScheduleLayoutFactory($timezone)); $slots = $layout->GetLayout($now, true); - if(!empty($startDate)){ + if (!empty($startDate)) { $reservationDate = $startDate; - }else{ + } else { $reservationDate = $now; if ($slots[count($slots) - 1]->EndDate()->LessThanOrEqual($now)) { $now = $now->AddDays(1)->GetDate(); @@ -234,6 +234,15 @@ public function DisplayResource($resourcePublicId, $startDate) public function Reserve() { + if (!Configuration::Instance()->GetKey(ConfigKeys::TABLET_VIEW_ALLOW_RESERVATIONS)) { + $resultCollector = new ReservationResultCollector(); + $resultCollector->SetSaveSuccessfulMessage(false); + $resultCollector->SetErrors(['Reservations are disabled in tablet view']); + + $this->page->SetReservationSaveResults(false, $resultCollector); + return; + } + $timezone = $this->page->GetTimezone(); $resourceId = $this->page->GetResourceId(); $email = $this->page->GetEmail(); @@ -245,7 +254,7 @@ public function Reserve() if ($maxFutureDays == 0) { $maxFutureDays = 1; } - $maxDate = Date::Now()->ToTimezone($timezone)->AddDays($maxFutureDays+1)->GetDate(); + $maxDate = Date::Now()->ToTimezone($timezone)->AddDays($maxFutureDays + 1)->GetDate(); $resultCollector = new ReservationResultCollector(); @@ -253,7 +262,7 @@ public function Reserve() $resultCollector->SetSaveSuccessfulMessage(false); $resultCollector->SetErrors(["Unauthorized"]); $success = false; - }else{ + } else { $userSession = $this->guestUserService->CreateOrLoad($email); $resource = $this->resourceRepository->LoadById($resourceId); @@ -380,23 +389,17 @@ public function SetWarnings($warnings) /** * @param array|string[] $messages */ - public function SetRetryMessages($messages) - { - } + public function SetRetryMessages($messages) {} /** * @param bool $canBeRetried */ - public function SetCanBeRetried($canBeRetried) - { - } + public function SetCanBeRetried($canBeRetried) {} /** * @param ReservationRetryParameter[] $retryParameters */ - public function SetRetryParameters($retryParameters) - { - } + public function SetRetryParameters($retryParameters) {} /** * @return ReservationRetryParameter[] diff --git a/Web/scripts/resourceDisplay.js b/Web/scripts/resourceDisplay.js index 967d95ab3..f09a2d135 100644 --- a/Web/scripts/resourceDisplay.js +++ b/Web/scripts/resourceDisplay.js @@ -79,11 +79,9 @@ function ResourceDisplay(opts) { elements.placeholder.on('click', '#reservePopup', function (e) { pauseRefresh(); - //showPopup(); }); elements.placeholder.on('click', '#reserveCancel', function (e) { - //hidePopup(); resumeRefresh(); refreshResource(); }); @@ -101,7 +99,6 @@ function ResourceDisplay(opts) { var validationErrors = $('#validationErrors'); if (data.success) { validationErrors.find('ul').empty().addClass('d-none'); - //hidePopup(); resumeRefresh(); refreshResource(); $('#reservation-box').modal('hide'); @@ -147,34 +144,17 @@ function ResourceDisplay(opts) { $(this).removeClass('hilite'); }); - elements.startDate.on('change', function () { + elements.rawStartDate.on('change', function () { showWait(); refreshResource(hideWait); }); var beginIndex = 0; - function showPopup() { - /*$('#reservation-box-wrapper').show(); - var reservationBox = $('#reservation-box'); - reservationBox.show(); - var offsetFromTop = ($('body').height() - reservationBox.height()) / 2; - reservationBox.css( - { top: offsetFromTop + 'px' } - ); - - $('#emailAddress').focus();*/ - } - function pauseRefresh() { _refreshEnabled = false; } - function hidePopup() { - // $('#reservation-box').hide(); - // $('#reservation-box-wrapper').hide(); - } - function resumeRefresh() { _refreshEnabled = true; } @@ -197,8 +177,6 @@ function ResourceDisplay(opts) { } elements.placeholder.html(data); - //$('#resource-display').height($('body').height()); - var formCheckin = $('#formCheckin'); formCheckin.unbind('submit'); diff --git a/config/config.dist.php b/config/config.dist.php index c9b87559d..9724e53cd 100644 --- a/config/config.dist.php +++ b/config/config.dist.php @@ -440,6 +440,9 @@ ########################################## 'tablet.view' => [ + # Allow users to make reservations in the tablet view (true/false) + 'allow.reservations' => true, + # Allow guest users to make reservations in tablet view (true/false) 'allow.guest.reservations' => false, diff --git a/lib/Config/ConfigKeys.php b/lib/Config/ConfigKeys.php index a33f0a696..a327f97ed 100644 --- a/lib/Config/ConfigKeys.php +++ b/lib/Config/ConfigKeys.php @@ -962,6 +962,14 @@ class ConfigKeys ]; // Tablet View Options + public const TABLET_VIEW_ALLOW_RESERVATIONS = [ + 'key' => 'tablet.view.allow.reservations', + 'type' => 'boolean', + 'default' => true, + 'label' => 'Allows reservations', + 'description' => 'Allows users to make reservations in the tablet view', + 'section' => 'tablet.view' + ]; # previously TABLET_VIEW_ALLOW_GUESTS public const TABLET_VIEW_ALLOW_GUEST_RESERVATIONS = [ diff --git a/tests/TestBase.php b/tests/TestBase.php index a4ba0ec51..6a7192b4f 100644 --- a/tests/TestBase.php +++ b/tests/TestBase.php @@ -54,6 +54,7 @@ public function setUp(): void $this->fakeEmailService = new FakeEmailService(); $this->fakeConfig = new FakeConfig(); $this->fakeConfig->SetKey(ConfigKeys::DEFAULT_TIMEZONE, 'America/Chicago'); + $this->fakeConfig->SetKey(ConfigKeys::TABLET_VIEW_ALLOW_RESERVATIONS, true); $this->fakeResources = new FakeResources(); $this->fakeUser = $this->fakeServer->UserSession; @@ -88,7 +89,7 @@ protected function captureErrorLog(callable $testFunction, bool $displayLogs = f if (ini_set('error_log', $tempLogFile) === false) { throw new \RuntimeException("Failed to set error_log to temporary file: $tempLogFile"); } - + try { // Execute the test function $testFunction(); diff --git a/tpl/ResourceDisplay/resource-display-resource.tpl b/tpl/ResourceDisplay/resource-display-resource.tpl index 4f3097d83..60c692031 100644 --- a/tpl/ResourceDisplay/resource-display-resource.tpl +++ b/tpl/ResourceDisplay/resource-display-resource.tpl @@ -1,5 +1,5 @@ {function name=displayReservation} -