Added date dynamic date format to booking wizard.

This commit is contained in:
Alex Tselegidis 2015-12-01 23:25:59 +01:00
parent d88362dcc0
commit 284abdfd54
4 changed files with 41 additions and 11 deletions

View file

@ -62,6 +62,7 @@ class Appointments extends CI_Controller {
$available_services = $this->services_model->get_available_services();
$available_providers = $this->providers_model->get_available_providers();
$company_name = $this->settings_model->get_setting('company_name');
$date_format = $this->settings_model->get_setting('date_format');
// If an appointment hash is provided then it means that the customer
// is trying to edit a registered appointment record.
@ -105,6 +106,7 @@ class Appointments extends CI_Controller {
'available_providers' => $available_providers,
'company_name' => $company_name,
'manage_mode' => $manage_mode,
'date_format' => $date_format,
'appointment_data' => $appointment,
'provider_data' => $provider,
'customer_data' => $customer,

View file

@ -75,6 +75,7 @@
availableProviders : <?php echo json_encode($available_providers); ?>,
baseUrl : <?php echo '"' . $this->config->item('base_url') . '"'; ?>,
manageMode : <?php echo ($manage_mode) ? 'true' : 'false'; ?>,
dateFormat : <?php echo json_encode($date_format); ?>,
appointmentData : <?php echo json_encode($appointment_data); ?>,
providerData : <?php echo json_encode($provider_data); ?>,
customerData : <?php echo json_encode($customer_data); ?>,

View file

@ -399,7 +399,7 @@ var FrontendBook = {
// Appointment Details
var selectedDate = $('#select-date').datepicker('getDate');
if (selectedDate !== null) {
selectedDate = Date.parse(selectedDate).toString('dd/MM/yyyy');
selectedDate = GeneralFunctions.formatDate(selectedDate, GlobalVariables.dateFormat);
}
var selServiceId = $('#select-service').val();

View file

@ -113,13 +113,10 @@ var GeneralFunctions = {
*/
getUrlParameter: function(url, parameterName) {
parameterName = parameterName.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');
var regexS = '[\\#&]' + parameterName + '=([^&#]*)';
var regex = new RegExp( regexS );
var results = regex.exec( url );
if( results == null )
return '';
else
return results[1];
var regexS = '[\\#&]' + parameterName + '=([^&#]*)',
regex = new RegExp(regexS),
results = regex.exec(url);
return (results == null) ? '' : results[1];
},
/**
@ -130,7 +127,9 @@ var GeneralFunctions = {
* @returns {String} Returns the transformed string.
*/
ISODateString: function(dt) {
function pad(n) { return n<10 ? '0'+n : n; }
function pad(n) {
return n<10 ? '0'+n : n;
}
return dt.getUTCFullYear()+'-'
+ pad(dt.getUTCMonth()+1)+'-'
@ -365,5 +364,33 @@ var GeneralFunctions = {
*/
escapeHtml: function(str) {
return $('<div/>').text(str).html();
},
/**
* Format a given date according to the date format setting.
*
* @param {Date]} date The date to be formatted.
* @param {string} dateFormatSetting The setting provided by PHP must be one of
* the "DMY", "MDY" or "YMD".
* @returns {string} Returns the formatted date string.
*/
formatDate: function(date, dateFormatSetting) {
var result;
switch(dateFormatSetting) {
case 'DMY':
result = Date.parse(date).toString('dd/MM/yyyy');
break;
case 'MDY':
result = Date.parse(date).toString('MM/dd/yyyy');
break;
case 'YMD':
result = Date.parse(date).toString('yyyy/MM/dd');
break;
default:
throw new Error('Invalid date format setting provided!', dateFormatSetting);
}
return result;
}
};