348 lines
13 KiB
JavaScript
348 lines
13 KiB
JavaScript
var SearchSidebar = function ($) {
|
|
$.ajaxSetup({ cache: false });
|
|
var searchSidebar = this;
|
|
var latitude;
|
|
var longitude;
|
|
var pageNumber;
|
|
var ResourcesSidebar = $.parseJSON($('#Resources_Home_Sidebar').val());
|
|
|
|
searchSidebar.bindButtonControl = function (id, whatToDo, returnFalse) {
|
|
$(id).unbind('keypress').bind('keypress', function () {
|
|
$(this).click();
|
|
});
|
|
$(id).unbind('click').bind('click', function () {
|
|
whatToDo();
|
|
if (returnFalse) {
|
|
return false;
|
|
}
|
|
});
|
|
};
|
|
|
|
searchSidebar.initialSetupSidebar = function () {
|
|
searchSidebar.ensureJqueryCookieThenRunSetup();
|
|
};
|
|
|
|
searchSidebar.setupAfterjqueryCookieConfirmed = function() {
|
|
SearchSidebarBinders.bindActions();
|
|
searchSidebar.bindActionButtons();
|
|
searchSidebar.checkLoggedInForSavedSearchesSection();
|
|
searchSidebar.checkIfSaveSearchNeedsToBeOpened();
|
|
searchSidebar.checkIfSearchButtonNeedsToBeClicked();
|
|
};
|
|
|
|
searchSidebar.ensureJqueryCookieThenRunSetup = function () {
|
|
if ($.cookie == undefined) {
|
|
$.getScript("/Common/Controls/jqueryCookie/jquery.cookie.js", searchSidebar.setupAfterjqueryCookieConfirmed);
|
|
} else {
|
|
searchSidebar.setupAfterjqueryCookieConfirmed();
|
|
}
|
|
};
|
|
|
|
searchSidebar.checkIfSaveSearchNeedsToBeOpened = function () {
|
|
var doOpen = $.cookie('openFacilitiesSaveSearchDialog');
|
|
if (doOpen != null && doOpen != undefined && doOpen == 'true') {
|
|
$.cookie('openFacilitiesSaveSearchDialog', false);
|
|
searchSidebar.saveSearch();
|
|
};
|
|
};
|
|
|
|
searchSidebar.checkIfSearchButtonNeedsToBeClicked = function () {
|
|
if ($('#hdn_ClickSearchButtonOnLoad').val() == 'True') {
|
|
searchSidebar.decideWhichSearch();
|
|
}
|
|
};
|
|
|
|
searchSidebar.decideWhichSearch = function () {
|
|
if ($('#listingResultTab').hasClass('active')) {
|
|
searchSidebar.search();
|
|
}
|
|
else {
|
|
searchSidebar.searchMap();
|
|
}
|
|
};
|
|
|
|
searchSidebar.checkLoggedInForSavedSearchesSection = function () {
|
|
searchSidebar.ajaxCall('/Facilities/Facility/IsLoggedIn', 'GET', {}, 'json', searchSidebar.processCheckLoggedInResponseForSavedSearchesSection, false);
|
|
};
|
|
|
|
searchSidebar.processCheckLoggedInResponseForSavedSearchesSection = function (loggedInResponse) {
|
|
if (loggedInResponse.loggedIn == true) {
|
|
searchSidebar.getSavedSearchesSection();
|
|
}
|
|
};
|
|
|
|
searchSidebar.getSavedSearchesSection = function () {
|
|
searchSidebar.ajaxCall('/Facilities/Facility/GetSavedSearchesSection', 'GET', {}, 'html', searchSidebar.processSavedSearchesSectionResponse, false);
|
|
};
|
|
|
|
searchSidebar.processSavedSearchesSectionResponse = function (response) {
|
|
$('#savedSearchesSection').html(response);
|
|
};
|
|
|
|
searchSidebar.saveSearch = function () {
|
|
searchSidebar.ajaxCall(
|
|
'/Facilities/Facility/IsLoggedIn',
|
|
'GET',
|
|
{},
|
|
'json',
|
|
function (response) {
|
|
if (response.loggedIn == true) {
|
|
openCpModal({
|
|
title: ResourcesSidebar.SaveSearch,
|
|
className: 'saveSearch',
|
|
isFrontEnd: true,
|
|
url: '/Facilities/Facility/GetSaveSearchModal'
|
|
});
|
|
}
|
|
},
|
|
false);
|
|
};
|
|
|
|
searchSidebar.checkLoggedInAndSaveSearch = function () {
|
|
$.cookie('openFacilitiesSaveSearchDialog', true);
|
|
var popupBasedAuthenticationJs = new PopupBasedAuthentication();
|
|
popupBasedAuthenticationJs.requireLoggedIn('', '');
|
|
};
|
|
|
|
searchSidebar.bindActionButtons = function () {
|
|
searchSidebar.bindButtonControl('#SearchButton', searchSidebar.decideWhichSearch, true);
|
|
searchSidebar.bindButtonControl('#saveSearchButton', searchSidebar.checkLoggedInAndSaveSearch, true);
|
|
};
|
|
|
|
searchSidebar.bindResetButton = function () {
|
|
SearchSidebarReservableFlippers.resetDropDownsAndReservable();
|
|
SearchSidebarReservableFlippers.resetTextBoxes();
|
|
};
|
|
|
|
searchSidebar.getAllCheckedFeatureIDs = function () {
|
|
return searchSidebar.getAllCheckedIDs('.chkSidebarFeatures');
|
|
};
|
|
|
|
searchSidebar.getAllCheckedCategoryIDs = function () {
|
|
return searchSidebar.getAllCheckedIDs('.chkSidebarFacilityTypes');
|
|
};
|
|
|
|
searchSidebar.getAllCheckedDesirableDaysIDs = function () {
|
|
return searchSidebar.getAllCheckedIDs('.chkSidebarDays');
|
|
};
|
|
|
|
searchSidebar.getAllCheckedIDs = function (id) {
|
|
var result = $(id + ':checked')
|
|
.map(function () {
|
|
return $(this).val();
|
|
}).get().join();
|
|
return result;
|
|
};
|
|
|
|
searchSidebar.ajaxCall = function (Url, Type, Data, DataType, ProcessResponseFunction, showProgress) {
|
|
$.ajax({
|
|
url: Url,
|
|
type: Type,
|
|
data: Data,
|
|
datatype: DataType,
|
|
beforeSend: function () {
|
|
if (showProgress) {
|
|
ajaxPostBackStart('Loading');
|
|
}
|
|
},
|
|
success: function (response) {
|
|
ProcessResponseFunction(response);
|
|
return false;
|
|
},
|
|
complete: function () {
|
|
if (showProgress) {
|
|
ajaxPostBackEnd();
|
|
}
|
|
},
|
|
error: function (xhr) {
|
|
alert("Error: " + xhr.statusText + "\nStatus: " + xhr.status);
|
|
if ($('#log').length > 0)
|
|
$('#log').html(xhr.responseText);
|
|
}
|
|
});
|
|
};
|
|
|
|
searchSidebar.processResponse = function (response) {
|
|
$('#mapResult').addClass('hidden');
|
|
$('#mapResultTab').removeClass('active');
|
|
$('#listingResult').html(response);
|
|
$('.sort').removeClass('hidden');
|
|
$('.sort').addClass('active');
|
|
$('#listingResult').removeClass('hidden');
|
|
$('#listingResultTab').addClass('active');
|
|
$('#mapResult').empty();
|
|
};
|
|
|
|
searchSidebar.processMapResponse = function (response) {
|
|
$('#listingResult').addClass('hidden');
|
|
$('.sort').addClass('hidden');
|
|
$('.sort').removeClass('active');
|
|
$('#listingResultTab').removeClass('active');
|
|
$('#mapResult').removeClass('hidden');
|
|
$('#mapResultTab').addClass('active');
|
|
$('#mapResult').html(response);
|
|
};
|
|
|
|
searchSidebar.search = function () {
|
|
searchSidebar.searchByPage(1);
|
|
};
|
|
|
|
searchSidebar.searchMap = function () {
|
|
var data;
|
|
if (SearchSidebarValidator.validateSidebar()) {
|
|
if ($('#chkIsReservable').is(':checked')) {
|
|
data = {
|
|
featureIDs: searchSidebar.getAllCheckedFeatureIDs(),
|
|
categoryIDs: searchSidebar.getAllCheckedCategoryIDs(),
|
|
desirableDaysIDs: searchSidebar.getAllCheckedDesirableDaysIDs(),
|
|
dateRangeStart: ($('#dateRangeStartPicker').val() == '') ? null : getDateFromInput('#dateRangeStartPicker'),
|
|
dateRangeEnd: ($('#dateRangeEndPicker').val() == '') ? null : getDateFromInput('#dateRangeEndPicker'),
|
|
startTime: ($('#startTimePicker').val() == '') ? null : $('#startTimePicker').val(),
|
|
endTime: ($('#endTimePicker').val() == '') ? null : $('#endTimePicker').val(),
|
|
occupants: ($('#occupants').val() == '' || $('#occupants').val() == null) ? null : $('#occupants').val().replace(/\,/g, ''),
|
|
keywords: $('#keywords').val(),
|
|
reservationFeeLow: ($('#lowestPrice').val() == '') ? null : $('#lowestPrice').val(),
|
|
reservationFeeHigh: ($('#highestPrice').val() == '') ? null : $('#highestPrice').val(),
|
|
reservationFeeRate: $('#reservationFeeRate').val(),
|
|
sortBy: $('#listingSortBy').val(),
|
|
isReservableOnly: true
|
|
};
|
|
}
|
|
else {
|
|
data = {
|
|
featureIDs: searchSidebar.getAllCheckedFeatureIDs(),
|
|
categoryIDs: searchSidebar.getAllCheckedCategoryIDs(),
|
|
occupants: ($('#occupants').val() == '' || $('#occupants').val() == null) ? null : $('#occupants').val().replace(/\,/g, ''),
|
|
keywords: $('#keywords').val(),
|
|
sortBy: $('#listingSortBy').val(),
|
|
isReservableOnly: false
|
|
};
|
|
}
|
|
searchSidebar.ajaxCall('/Facilities/Facility/SearchMap', 'POST',
|
|
data, 'html',
|
|
searchSidebar.processMapResponse, true);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
searchSidebar.listingResultTab = function () {
|
|
searchSidebar.ajaxCall('/Facilities/Facility/SearchListingTabResponse', 'POST',
|
|
{}, 'html',
|
|
searchSidebar.processResponse, true);
|
|
};
|
|
|
|
searchSidebar.mapResultTab = function () {
|
|
searchSidebar.ajaxCall('/Facilities/Facility/SearchMapTabResponse', 'POST',
|
|
{}, 'html',
|
|
searchSidebar.processMapResponse, true);
|
|
};
|
|
|
|
searchSidebar.searchByPage = function (PageNumber) {
|
|
pageNumber = PageNumber;
|
|
searchSidebar.setupCurrentPosition();
|
|
};
|
|
|
|
searchSidebar.searchListing = function () {
|
|
var data;
|
|
if (SearchSidebarValidator.validateSidebar()) {
|
|
if ($('#chkIsReservable').is(':checked')) {
|
|
data = {
|
|
featureIDs: searchSidebar.getAllCheckedFeatureIDs(),
|
|
categoryIDs: searchSidebar.getAllCheckedCategoryIDs(),
|
|
desirableDaysIDs: searchSidebar.getAllCheckedDesirableDaysIDs(),
|
|
dateRangeStart: ($('#dateRangeStartPicker').val() == '') ? null : getDateFromInput('#dateRangeStartPicker'),
|
|
dateRangeEnd: ($('#dateRangeEndPicker').val() == '') ? null : getDateFromInput('#dateRangeEndPicker'),
|
|
startTime: ($('#startTimePicker').val() == '') ? null : $('#startTimePicker').val(),
|
|
endTime: ($('#endTimePicker').val() == '') ? null : $('#endTimePicker').val(),
|
|
occupants: ($('#occupants').val() == '' || $('#occupants').val() == null) ? null : $('#occupants').val().replace(/\,/g, ''),
|
|
keywords: $('#keywords').val(),
|
|
reservationFeeLow: ($('#lowestPrice').val() == '') ? null : $('#lowestPrice').val(),
|
|
reservationFeeHigh: ($('#highestPrice').val() == '') ? null : $('#highestPrice').val(),
|
|
reservationFeeRate: $('#reservationFeeRate').val(),
|
|
pageSize: $('#facilityListingPagingDropDown').val(),
|
|
pageNumber: pageNumber,
|
|
sortBy: $('#listingSortBy').val(),
|
|
currentLatitude: latitude,
|
|
currentLongitude: longitude,
|
|
isReservableOnly: true
|
|
};
|
|
}
|
|
else {
|
|
data = {
|
|
featureIDs: searchSidebar.getAllCheckedFeatureIDs(),
|
|
categoryIDs: searchSidebar.getAllCheckedCategoryIDs(),
|
|
occupants: ($('#occupants').val() == '' || $('#occupants').val() == null) ? null : $('#occupants').val().replace(/\,/g, ''),
|
|
keywords: $('#keywords').val(),
|
|
pageSize: $('#facilityListingPagingDropDown').val(),
|
|
pageNumber: pageNumber,
|
|
sortBy: $('#listingSortBy').val(),
|
|
currentLatitude: latitude,
|
|
currentLongitude: longitude,
|
|
isReservableOnly: false
|
|
};
|
|
}
|
|
searchSidebar.ajaxCall('/Facilities/Facility/Search', 'POST',
|
|
data, 'html',
|
|
searchSidebar.processResponse, true);
|
|
}
|
|
};
|
|
|
|
searchSidebar.setupCurrentPosition = function () {
|
|
if (!searchSidebar.validateGeolocation()) {
|
|
searchSidebar.positionFail();
|
|
return false;
|
|
}
|
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
searchSidebar.positionSuccess,
|
|
searchSidebar.positionFailAlert
|
|
);
|
|
};
|
|
|
|
searchSidebar.validateGeolocation = function () {
|
|
if (!searchSidebar.validateGeolocationSortOption()) {
|
|
return false;
|
|
}
|
|
|
|
if (!navigator.geolocation) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
searchSidebar.validateGeolocationSortOption = function () {
|
|
if ($('#listingSortBy').val() == null) {
|
|
return false;
|
|
}
|
|
|
|
if ($('#listingSortBy').val() != "2") {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
searchSidebar.positionSuccess = function (position) {
|
|
if (position.coords.accuracy > 100000) {
|
|
alert('Cannot determine your current location');
|
|
searchSidebar.positionFail();
|
|
}
|
|
|
|
latitude = position.coords.latitude;
|
|
longitude = position.coords.longitude;
|
|
searchSidebar.searchListing();
|
|
};
|
|
|
|
searchSidebar.positionFailAlert = function (error) {
|
|
alert('Cannot determine your current location ' + error.message);
|
|
searchSidebar.searchListing();
|
|
};
|
|
|
|
searchSidebar.positionFail = function () {
|
|
latitude = null;
|
|
longitude = null;
|
|
searchSidebar.searchListing();
|
|
};
|
|
|
|
return this;
|
|
} (jQuery); |