The booking wizard will parse two new GET parameters for setting default values to providers and services (fixes #24).

This commit is contained in:
Alex Tselegidis 2016-07-16 21:06:55 +02:00
parent 057e3d139a
commit c73e990e81
2 changed files with 43 additions and 11 deletions

View file

@ -97,20 +97,42 @@ window.FrontendBook = window.FrontendBook || {};
} }
}); });
// Bind the event handlers (might not be necessary every time we use this class).
// Bind the event handlers (might not be necessary every time
// we use this class).
if (bindEventHandlers) { if (bindEventHandlers) {
_bindEventHandlers(); _bindEventHandlers();
} }
// If the manage mode is true, the appointments data should be // If the manage mode is true, the appointments data should be loaded by default.
// loaded by default.
if (FrontendBook.manageMode) { if (FrontendBook.manageMode) {
_applyAppointmentData(GlobalVariables.appointmentData, _applyAppointmentData(GlobalVariables.appointmentData,
GlobalVariables.providerData, GlobalVariables.customerData); GlobalVariables.providerData, GlobalVariables.customerData);
} else { } else {
$('#select-service').trigger('change'); // Load the available hours. var $selectProvider = $('#select-provider');
var $selectService = $('#select-service');
// Check if a specific service was selected.
var selectedServiceId = GeneralFunctions.getUrlParameter(location.href, 'service');
if (selectedServiceId && $selectService.find('option[value="' + selectedServiceId + '"]').length > 0) {
$selectService
.val(selectedServiceId)
.prop('disabled', true)
.css('opacity', '0.5');
}
$selectService.trigger('change'); // Load the available hours.
// Check if a specific provider was selected.
var selectedProviderId = GeneralFunctions.getUrlParameter(location.href, 'provider');
if (selectedProviderId && $selectProvider.find('option[value="' + selectedProviderId + '"]').length > 0) {
$selectProvider
.val(selectedProviderId)
.prop('disabled', true)
.css('opacity', '0.5')
.trigger('change');
}
} }
}; };

View file

@ -114,11 +114,21 @@ window.GeneralFunctions = window.GeneralFunctions || {};
* @return {String} Returns the parameter value. * @return {String} Returns the parameter value.
*/ */
exports.getUrlParameter = function(url, parameterName) { exports.getUrlParameter = function(url, parameterName) {
parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]'); var parsedUrl = url.substr(url.indexOf('?')).slice(1).split('&');
var regexS = '[\\#&]' + parameterName + '=([^&#]*)';
var regex = new RegExp(regexS); for (var index in parsedUrl) {
var results = regex.exec(url); var parsedValue = parsedUrl[index].split('=');
return (results == null) ? '' : results[1];
if (parsedValue.length === 1 && parsedValue[0] === parameterName) {
return '';
}
if (parsedValue.length === 2 && parsedValue[0] === parameterName) {
return decodeURIComponent(parsedValue[1]);
}
}
return '';
}; };
/** /**