Fix display of breaks in the backend for working plans stored in database with Monday as the first weekday (EA! Issue #506).
Prior commit 00372f2f1a
, the first weekday was Monday.
After this commit, it is set to Sunday and the display of breaks in the backend calendar is broken for former working plans.
The fix consists in reordering the working plan elements with Sunday as the first day prior displaying the backend calendar.
In addition, the working plan elements are also reordered when displaying 'Settings/Business Logic' and 'Users/Providers' tabs.
This is to ensure that breaks are always displayed with Sunday first, like done for the Working Plan in those tabs, for consistency purpose..
This commit is contained in:
parent
683b7a4d2d
commit
8ca935c412
3 changed files with 83 additions and 9 deletions
|
@ -855,13 +855,13 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$calendar.fullCalendar('addEventSource', calendarEvents);
|
||||
|
||||
var weekDays = [
|
||||
'sunday',
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday'
|
||||
'sunday',
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday'
|
||||
];
|
||||
|
||||
// :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS
|
||||
|
@ -870,10 +870,14 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
if (provider.id == recordId) {
|
||||
var workingPlan = jQuery.parseJSON(provider.settings.working_plan);
|
||||
var workingPlan={};
|
||||
var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan);
|
||||
var extraWorkingPlan = jQuery.parseJSON(provider.settings.extra_working_plan);
|
||||
var unavailablePeriod;
|
||||
|
||||
// Sort the working plan starting with the first day as set in General settings to correctly align breaks in the calendar display
|
||||
workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,0); // 0 is the ID for Sunday
|
||||
|
||||
switch (calendarView) {
|
||||
case 'agendaDay':
|
||||
var selectedDayName = weekDays[$calendar.fullCalendar('getView').start.format('d')];
|
||||
|
|
|
@ -431,6 +431,73 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the name in lowercase of a Weekday using its Id.
|
||||
*
|
||||
* @param {Integer} weekDayId The Id (From 0 for sunday to 6 for saturday).
|
||||
|
||||
* @return {String} Returns the name of the weekday.
|
||||
*/
|
||||
exports.getWeekDayName = function (weekDayId) {
|
||||
var result;
|
||||
|
||||
switch (weekDayId) {
|
||||
|
||||
case 0:
|
||||
result = 'sunday';
|
||||
break;
|
||||
|
||||
case 1:
|
||||
result = 'monday';
|
||||
break;
|
||||
|
||||
case 2:
|
||||
result = 'tuesday';
|
||||
break;
|
||||
|
||||
case 3:
|
||||
result = 'wednesday';
|
||||
break;
|
||||
|
||||
case 4:
|
||||
result = 'thursday';
|
||||
break;
|
||||
|
||||
case 5:
|
||||
result = 'friday';
|
||||
break;
|
||||
|
||||
case 6:
|
||||
result = 'saturday';
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error('Invalid weekday Id provided!', weekDayId);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort a dictionary where keys are weekdays
|
||||
*
|
||||
* @param {Object} weekDict A dictionnary with weekdays as keys.
|
||||
* @param {Integer} startDayId Id of the first day to start sorting (From 0 for sunday to 6 for saturday).
|
||||
|
||||
* @return {Object} Returns a sorted dictionary
|
||||
*/
|
||||
exports.sortWeekDict = function (weekDict, startDayId) {
|
||||
var sortedWeekDict={};
|
||||
|
||||
for (var i = startDayId; i < startDayId+7; i++)
|
||||
{
|
||||
var weekDayname = GeneralFunctions.getWeekDayName(i%7);
|
||||
sortedWeekDict[weekDayname] = weekDict[weekDayname];
|
||||
}
|
||||
|
||||
return sortedWeekDict;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render a map icon that links to Google maps.
|
||||
*
|
||||
|
|
|
@ -45,7 +45,10 @@
|
|||
* @param {Object} workingPlan Contains the working hours and breaks for each day of the week.
|
||||
*/
|
||||
WorkingPlan.prototype.setup = function (workingPlan) {
|
||||
$.each(workingPlan, function (index, workingDay) {
|
||||
// Always displaying breaks with Sunday as the first day to be consistent with what is done in the the working plan view.
|
||||
var workingPlanSorted = GeneralFunctions.sortWeekDict(workingPlan,0); // 0 is the ID for Sunday
|
||||
|
||||
$.each(workingPlanSorted, function (index, workingDay) {
|
||||
if (workingDay != null) {
|
||||
$('#' + index).prop('checked', true);
|
||||
$('#' + index + '-start').val(Date.parse(workingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
|
|
Loading…
Reference in a new issue