Add dropdown fallback

This commit is contained in:
Abhishek Kumar
2023-11-24 19:33:45 +05:30
parent be6148c2d1
commit 2726dbd4cd
9 changed files with 153 additions and 89 deletions

View File

@@ -315,7 +315,7 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController
if (!$hotelNameSearchThreshold && $hotelNameSearchThreshold !== '0') {
$this->errors[] = $this->l('Hotel name search threshold field is required.');
} elseif (!Validate::isUnsignedInt(Tools::getValue('WK_HOTEL_NAME_SEARCH_THRESHOLD'))) {
} elseif (!Validate::isUnsignedInt($hotelNameSearchThreshold)) {
$this->errors[] = $this->l('Hotel name search threshold field is invalid.');
}

View File

@@ -57,13 +57,17 @@ class WkRoomSearchBlockAutoCompleteSearchModuleFrontController extends ModuleFro
}
$this->context->smarty->assign(array('hotels_info' => $hotelsInfo));
$html = $this->context->smarty->fetch(
$this->module->getTemplatePath('hotel-options.tpl')
$html_select = $this->context->smarty->fetch(
$this->module->getTemplatePath('hotel-options-select.tpl')
);
$html_dropdown = $this->context->smarty->fetch(
$this->module->getTemplatePath('hotel-options-dropdown.tpl')
);
$result['status'] = 'success';
$result['data'] = $html;
$result['data_select'] = $html_select;
$result['data_dropdown'] = $html_dropdown;
} else {
$result['status'] = 'failed2';
}

View File

@@ -23,7 +23,7 @@
vertical-align: middle;
font-size: 14px;
zoom: 1;
display: inline;
/* display: inline; */
-moz-user-select: -moz-none;
-ms-user-select: none;
-webkit-user-select: none;
@@ -59,7 +59,7 @@
overflow: hidden;
padding-left: 35px;
height: 100%;
border: 1px solid #aaa;
border: 1px solid #555555;
border-radius: 4px;
background-clip: padding-box;
box-shadow: 0 0 3px #fff inset, 0 1px 1px rgba(0, 0, 0, 0.1);
@@ -68,6 +68,7 @@
white-space: nowrap;
line-height: 24px;
background: #fff url('../img/icon-hotel.svg') no-repeat 10px 50%;
min-height: 55px;
}
.chosen-container-single.error_border .chosen-single {
border: 2px solid red !important;
@@ -458,26 +459,9 @@
margin-bottom: -16px;
}
/* @end */
/* @group Retina compatibility */
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) {
.chosen-rtl .chosen-search input[type="text"],
.chosen-container-single .chosen-single abbr,
.chosen-container-single .chosen-single div b,
.chosen-container-single .chosen-search input[type="text"],
.chosen-container-multi .chosen-choices .search-choice .search-choice-close,
.chosen-container .chosen-results-scroll-down span,
.chosen-container .chosen-results-scroll-up span {
background-image: url('chosen-sprite@2x.png') !important;
background-size: 52px 37px !important;
background-repeat: no-repeat !important;
}
}
/* @end */
/* search results page - start */
#category .chosen-container-single .chosen-single span {
min-height: 45px;
top: 11px;
}
/* search results page - end */
/* search results page - end */

View File

@@ -48,6 +48,12 @@
height: unset;
min-height: 45px;
}
#search_hotel_block_form .hotel-selector-wrap .chosen-container-single .chosen-single {
min-height: 45px;
}
#search_hotel_block_form .hotel-selector-wrap .chosen-container-single .chosen-search {
height: 45px;
}
/* #search_hotel_block_form #search_room_submit {
height: 45px;
} */

View File

@@ -72,6 +72,12 @@
#date-range-picker-container.bottom {
top: 85px;
}
.fancybox-wrap #search_hotel_block_form .form-group.xs-calendar {
position: relative;
}
.fancybox-wrap #search_hotel_block_form #date-range-picker-container {
top: 56px;
}
/* #search_hotel_block_form {
display: grid;
grid-template-columns: 0.8fr repeat(3, 1fr) 0.6fr;
@@ -126,14 +132,16 @@
color: #333;}
.header-rmsearch-input:-moz-placeholder {
/* Firefox 18- */
color: #999999;
font-weight: 400;}
color: #333;
font-weight: 400;
opacity: 1;}
.header-rmsearch-input::-moz-placeholder {
/* Firefox 19+ */
color: #999999;
font-weight: 400;}
color: #333;
font-weight: 400;
opacity: 1;}
.header-rmsearch-input:-ms-input-placeholder {
color: #999999;
color: #333;
font-weight: 400;}
.search_block_container .dropdown-toggle {
background-color: #f2f2f2;

View File

@@ -86,9 +86,14 @@ $(document).ready(function() {
helpers: {
overlay: { closeClick: false } //Disable click outside event
},
'beforeShow': function() {
$('#date-range-picker-container').closest('.form-group').addClass('xs-calendar');
},
'afterClose': function() {
$('.header-rmsearch-container').show();
$('#xs_room_search_form').show();
$('#date-range-picker-container').closest('.form-group').removeClass('xs-calendar');
},
});
});
@@ -250,7 +255,9 @@ $(document).ready(function() {
success: function(result) {
if (result.status == 'success') {
$('#hotel_cat_id').val('');
$('#id_hotel_button').html(result.data);
$('#id_hotel_button').html(result.data_select);
$('.hotel_dropdown_ul').empty();
$('.hotel_dropdown_ul').html(result.data_dropdown);
$('#id_hotel_button').trigger('chosen:updated');
if (focusHotelSelection) {
@@ -312,9 +319,7 @@ $(document).ready(function() {
}
});
$(document).on('change', '#id_hotel_button', function() {
let selectedHotel = $(this).find('option:selected');
function selectHotelFromList(selectedHotel) {
let max_order_date = $(selectedHotel).attr('data-max_order_date');
let preparation_time = $(selectedHotel).attr('data-preparation_time')
@@ -327,6 +332,14 @@ $(document).ready(function() {
$('#hotel_cat_name').html($(selectedHotel).html());
BookingSearchManager.activateStep('date_range');
}
$(document).on('change', '#id_hotel_button', function() {
selectHotelFromList($(this).find('option:selected'));
});
$(document).on('click', '.hotel_dropdown_ul li', function() {
selectHotelFromList($(this));
});
// If only one hotel then set max order date on date pickers
@@ -612,22 +625,19 @@ $(document).ready(function() {
});
if (page_name == 'index') {
$('#hotel_location, #guest_occupancy').focus(function () {
setBookingSearchDropdownPositions();
setBookingSearchCalendarPositions();
$('#hotel_location, #id_hotel_button, #guest_occupancy').focus(function () {
setBookingSearchPositions();
});
// after chosen has been initialized
$('select#id_hotel_button').on('chosen:ready', function() {
$('#id_hotel_button_chosen .chosen-search input').focus(function () {
setBookingSearchDropdownPositions();
setBookingSearchCalendarPositions();
setBookingSearchPositions();
});
});
$('#daterange_value').click(function () {
setBookingSearchDropdownPositions();
setBookingSearchCalendarPositions();
setBookingSearchPositions();
});
}
@@ -681,6 +691,12 @@ $(document).ready(function() {
$(this).siblings('.chosen-container').find('.chosen-single').removeClass('invisible')
});
}
// if hotel chosen is not intialized use dropdown
if ($('select#id_hotel_button').data('chosen') === undefined) {
$('#search_hotel_block_form .hotel-select-wrap').addClass('hide');
$('#search_hotel_block_form .hotel-dropdown-wrap').removeClass('hide');
}
});
// function to set occupancy infor in guest occupancy field(search form)
function setGuestOccupancy()
@@ -715,59 +731,55 @@ function setGuestOccupancy()
$('#guest_occupancy > span').text(guestButtonVal);
}
function setBookingSearchDropdownPositions() {
// position dropdowns and the calendar
function setBookingSearchPositions() {
// calculate available spaces
let searchForm = $('#search_hotel_block_form');
let inputFieldsAndDropdowns = [
{ input: $('#hotel_location'), dropdown: $('.location_search_results_ul')},
{ input: $('#id_hotel_button'), dropdown: $('.hotel_dropdown_ul')},
{ input: $('.hotel-selector-wrap'), dropdown: $('#id_hotel_button_chosen .chosen-drop')},
{ input: $('#guest_occupancy'), dropdown: $('#search_occupancy_wrapper')},
];
let dropdownHeightMax = 0;
let spaceTopMax = 0;
let spaceBottomMax = 0;
let calendarInputField = { input: $('#daterange_value'), calendarContainer: $('#date-range-picker-container')};
$(inputFieldsAndDropdowns).each(function (i, inputFieldAndDropdown) {
// find available space
let inputFieldHeight = inputFieldAndDropdown.input.outerHeight();
let spaceTop = inputFieldAndDropdown.input.offset().top - $(window).scrollTop();
let spaceBottom = $(window).height() - inputFieldHeight - spaceTop;
let cssMaxHeight = inputFieldAndDropdown.dropdown.css('max-height') || '292px';
let dropdownHeight = parseInt(cssMaxHeight.replace('px', ''));
dropdownHeight = Math.max(dropdownHeight || 0, 292); // 292 is height of the calendar
let positionClass = 'bottom';
if (!searchForm.closest('.fancybox-wrap').length) {
let searchFormHeight = searchForm.outerHeight();
let spaceTop = searchForm.offset().top - $(window).scrollTop();
let spaceBottom = $(window).height() - searchFormHeight - spaceTop;
dropdownHeightMax = Math.max(dropdownHeightMax, dropdownHeight);
spaceTopMax = Math.max(spaceTopMax, spaceTop);
spaceBottomMax = Math.max(spaceBottomMax, spaceBottom);
});
let calendarHeight = 292;
let dropdownClass = 'bottom';
if (spaceBottomMax < dropdownHeightMax && spaceTopMax > spaceBottomMax) {
dropdownClass = 'top';
// calculate max height for dropdowns
let maxHeightNeeded = 0;
$(inputFieldsAndDropdowns).each(function (i, inputFieldAndDropdown) {
if (!inputFieldAndDropdown.input.length) return false;
// find needed space height
let cssMaxHeight = inputFieldAndDropdown.dropdown.css('max-height') || calendarHeight + 'px';
let dropdownHeight = parseInt(cssMaxHeight.replace('px', ''));
dropdownHeight = Math.max(dropdownHeight || 0, calendarHeight);
maxHeightNeeded = Math.max(maxHeightNeeded, dropdownHeight);
});
// manage calendar now
maxHeightNeeded = Math.max(maxHeightNeeded, calendarHeight);
// determine position class
if (spaceBottom < maxHeightNeeded && spaceTop > spaceBottom) {
positionClass = 'top';
}
}
// position dropdowns
$(inputFieldsAndDropdowns).each(function (i, inputFieldAndDropdown) {
inputFieldAndDropdown.dropdown.removeClass('top bottom').addClass(dropdownClass);
});
}
function setBookingSearchCalendarPositions() {
let calendarInputFields = [
{ input: $('#daterange_value'), calendarContainer: $('#date-range-picker-container')},
];
$(calendarInputFields).each(function (i, calendarInputField) {
// find available space
let inputFieldHeight = calendarInputField.input.outerHeight();
let spaceTop = calendarInputField.input.offset().top - $(window).scrollTop();
let spaceBottom = $(window).height() - inputFieldHeight - spaceTop;
let calendarHeight = 292; // 292 is height of the calendar
let calendarContainerClass = 'bottom';
if (spaceBottom < calendarHeight && spaceTop > spaceBottom) {
calendarContainerClass = 'top';
}
// position calendar
calendarInputField.calendarContainer.removeClass('top bottom').addClass(calendarContainerClass);
inputFieldAndDropdown.dropdown.removeClass('top bottom').addClass(positionClass);
});
// position calendar
calendarInputField.calendarContainer.removeClass('top bottom').addClass(positionClass);
}

View File

@@ -0,0 +1,26 @@
{**
* 2010-2023 Webkul.
*
* NOTICE OF LICENSE
*
* All right is reserved,
* Please go through LICENSE.txt file inside our module
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
*
* @author Webkul IN
* @copyright 2010-2023 Webkul IN
* @license LICENSE.txt
*}
{if isset($hotels_info) && is_array($hotels_info)}
{foreach from=$hotels_info item=hotel_info}
<li tabindex="-1" class="search_result_li" data-id-hotel="{$hotel_info.id_hotel}" data-hotel-cat-id="{$hotel_info.id_category}" data-max_order_date="{$hotel_info.max_order_date}">
{$hotel_info.hotel_name}
</li>
{/foreach}
{/if}

View File

@@ -21,13 +21,37 @@
<input type="hidden" id="max_order_date" name="max_order_date" value="{if isset($max_order_date)}{$max_order_date|escape:'htmlall':'UTF-8'}{/if}">
<input type="hidden" id="preparation_time" name="preparation_time" value="{if isset($preparation_time)}{$preparation_time|escape:'htmlall':'UTF-8'}{/if}">
<div class="hotel-selector-wrap">
<select name="id_hotel" class="chosen invisible" data-placeholder="{l s='Select Hotel' mod='wkroomsearchblock'}" id="id_hotel_button">
<option value=""></option>
{foreach $hotels_info as $name_val}
<option class="search_result_li" value="{$name_val['id']|escape:'htmlall':'UTF-8'}" data-id-hotel="{$name_val['id']|escape:'htmlall':'UTF-8'}" data-hotel-cat-id="{$name_val['id_category']|escape:'htmlall':'UTF-8'}" data-max_order_date="{$name_val['max_order_date']}" data-preparation_time="{$name_val['preparation_time']|escape:'htmlall':'UTF-8'}">{$name_val['hotel_name']|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
<div class="hotel-select-wrap">
<div class="hotel-selector-wrap">
<select name="id_hotel" class="chosen invisible" data-placeholder="{l s='Select Hotel' mod='wkroomsearchblock'}" id="id_hotel_button">
<option value=""></option>
{foreach $hotels_info as $name_val}
<option class="search_result_li" value="{$name_val['id']|escape:'htmlall':'UTF-8'}" data-id-hotel="{$name_val['id']|escape:'htmlall':'UTF-8'}" data-hotel-cat-id="{$name_val['id_category']|escape:'htmlall':'UTF-8'}" data-max_order_date="{$name_val['max_order_date']}" data-preparation_time="{$name_val['preparation_time']|escape:'htmlall':'UTF-8'}" {if isset($search_data) && $name_val['id'] == $search_data['htl_dtl']['id']}selected{/if}>{$name_val['hotel_name']|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</select>
</div>
</div>
<div class="hotel-dropdown-wrap hide">
{if isset($hotels_info) && count($hotels_info)}
<div class="dropdown">
<button class="form-control header-rmsearch-input input-hotel {if isset($error) && $error == 1}error_border{/if}" type="button" data-toggle="dropdown" id="id_hotel_button">
{if isset($search_data)}
<span id="hotel_cat_name" class="pull-left">{$search_data['htl_dtl']['hotel_name']|escape:'htmlall':'UTF-8'}</span>
{else}
<span id="hotel_cat_name" class="pull-left">{l s='Select Hotel' mod='wkroomsearchblock'}</span>
{/if}
</button>
<ul class="dropdown-menu hotel_dropdown_ul">
{if isset($hotels_info) && $hotels_info}
{foreach $hotels_info as $name_val}
<li tabindex="-1" class="search_result_li" data-id-hotel="{$name_val['id']|escape:'htmlall':'UTF-8'}" data-hotel-cat-id="{$name_val['id_category']|escape:'htmlall':'UTF-8'}" data-max_order_date="{$name_val['max_order_date']}" data-preparation_time="{$name_val['preparation_time']|escape:'htmlall':'UTF-8'}">
{$name_val['hotel_name']|escape:'htmlall':'UTF-8'}
</li>
{/foreach}
{/if}
</ul>
</div>
{/if}
</div>
</div>
{/if}