mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-25 16:13:17 +03:00
Use the default service duration if the user just clicks on a calendar slot for creating a new appointment (#1237)
This commit is contained in:
parent
ae71c4c89d
commit
a9a72e503d
3 changed files with 39 additions and 7 deletions
|
@ -103,6 +103,35 @@ App.Pages.Calendar = (function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get calendar selection end date.
|
||||||
|
*
|
||||||
|
* On calendar slot selection, calculate the end date based on the provided start date.
|
||||||
|
*
|
||||||
|
* @param {Object} info Holding the "start" and "end" props, as provided by FullCalendar.
|
||||||
|
*
|
||||||
|
* @return {Date}
|
||||||
|
*/
|
||||||
|
function getSelectionEndDate(info) {
|
||||||
|
const startMoment = moment(info.start);
|
||||||
|
const endMoment = moment(info.end);
|
||||||
|
const startTillEndDiff = endMoment.diff(startMoment);
|
||||||
|
const startTillEndDuration = moment.duration(startTillEndDiff);
|
||||||
|
const durationInMinutes = startTillEndDuration.asMinutes();
|
||||||
|
const minDurationInMinutes = 15;
|
||||||
|
|
||||||
|
if (durationInMinutes <= minDurationInMinutes) {
|
||||||
|
const serviceId = $('#select-service').val();
|
||||||
|
const service = vars('available_services').find(availableService => Number(availableService.id) === Number(serviceId));
|
||||||
|
|
||||||
|
if (service) {
|
||||||
|
endMoment.add(service.duration - durationInMinutes, 'minutes');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return endMoment.toDate();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the module.
|
* Initialize the module.
|
||||||
*
|
*
|
||||||
|
@ -124,6 +153,7 @@ App.Pages.Calendar = (function () {
|
||||||
document.addEventListener('DOMContentLoaded', initialize);
|
document.addEventListener('DOMContentLoaded', initialize);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
initialize
|
initialize,
|
||||||
|
getSelectionEndDate
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -312,7 +312,7 @@ App.Utils.CalendarDefaultView = (function () {
|
||||||
$('#enable-sync span').text(lang('enable_sync'));
|
$('#enable-sync span').text(lang('enable_sync'));
|
||||||
$('#google-sync').prop('disabled', true);
|
$('#google-sync').prop('disabled', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#insert-working-plan-exception').toggle(providerId !== App.Utils.CalendarDefaultView.FILTER_TYPE_ALL);
|
$('#insert-working-plan-exception').toggle(providerId !== App.Utils.CalendarDefaultView.FILTER_TYPE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1567,7 +1567,9 @@ App.Utils.CalendarDefaultView = (function () {
|
||||||
|
|
||||||
// Preselect time
|
// Preselect time
|
||||||
$('#start-datetime').datepicker('setDate', info.start);
|
$('#start-datetime').datepicker('setDate', info.start);
|
||||||
$('#end-datetime').datepicker('setDate', info.end);
|
$('#end-datetime').datepicker('setDate', App.Pages.Calendar.getSelectionEndDate(info));
|
||||||
|
|
||||||
|
// $('#end-datetime').datepicker('setDate', info.end);
|
||||||
$('#message-box').dialog('close');
|
$('#message-box').dialog('close');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1600,8 +1602,8 @@ App.Utils.CalendarDefaultView = (function () {
|
||||||
onWindowResize();
|
onWindowResize();
|
||||||
|
|
||||||
$selectFilterItem.append(new Option(lang('all'), FILTER_TYPE_ALL, true, true));
|
$selectFilterItem.append(new Option(lang('all'), FILTER_TYPE_ALL, true, true));
|
||||||
|
|
||||||
$('#insert-working-plan-exception').hide();
|
$('#insert-working-plan-exception').hide();
|
||||||
|
|
||||||
// Fill the select list boxes of the page.
|
// Fill the select list boxes of the page.
|
||||||
if (vars('available_providers').length > 0) {
|
if (vars('available_providers').length > 0) {
|
||||||
|
|
|
@ -783,8 +783,8 @@ App.Utils.CalendarTableView = (function () {
|
||||||
$selectProvider.trigger('change');
|
$selectProvider.trigger('change');
|
||||||
|
|
||||||
// Preselect time
|
// Preselect time
|
||||||
$('#start-datetime').datepicker('setDate', new Date(moment(info.start).format('YYYY/MM/DD HH:mm:ss')));
|
$('#start-datetime').datepicker('setDate', info.start);
|
||||||
$('#end-datetime').datepicker('setDate', new Date(moment(info.end).format('YYYY/MM/DD HH:mm:ss')));
|
$('#end-datetime').datepicker('setDate', App.Pages.Calendar.getSelectionEndDate(info));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue