The booking wizard will parse two new GET parameters for setting default values to providers and services (fixes #24).
This commit is contained in:
parent
057e3d139a
commit
c73e990e81
2 changed files with 43 additions and 11 deletions
|
@ -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) {
|
||||
_bindEventHandlers();
|
||||
}
|
||||
|
||||
// If the manage mode is true, the appointments data should be
|
||||
// loaded by default.
|
||||
// If the manage mode is true, the appointments data should be loaded by default.
|
||||
if (FrontendBook.manageMode) {
|
||||
_applyAppointmentData(GlobalVariables.appointmentData,
|
||||
GlobalVariables.providerData, GlobalVariables.customerData);
|
||||
} 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');
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -114,11 +114,21 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
* @return {String} Returns the parameter value.
|
||||
*/
|
||||
exports.getUrlParameter = function(url, parameterName) {
|
||||
parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
|
||||
var regexS = '[\\#&]' + parameterName + '=([^&#]*)';
|
||||
var regex = new RegExp(regexS);
|
||||
var results = regex.exec(url);
|
||||
return (results == null) ? '' : results[1];
|
||||
var parsedUrl = url.substr(url.indexOf('?')).slice(1).split('&');
|
||||
|
||||
for (var index in parsedUrl) {
|
||||
var parsedValue = parsedUrl[index].split('=');
|
||||
|
||||
if (parsedValue.length === 1 && parsedValue[0] === parameterName) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (parsedValue.length === 2 && parsedValue[0] === parameterName) {
|
||||
return decodeURIComponent(parsedValue[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue