diff --git a/src/assets/js/backend_calendar_default_view.js b/src/assets/js/backend_calendar_default_view.js index 4a76f346..729f78da 100755 --- a/src/assets/js/backend_calendar_default_view.js +++ b/src/assets/js/backend_calendar_default_view.js @@ -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')]; diff --git a/src/assets/js/general_functions.js b/src/assets/js/general_functions.js index eb3f8a5c..6ba97d0d 100755 --- a/src/assets/js/general_functions.js +++ b/src/assets/js/general_functions.js @@ -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. * diff --git a/src/assets/js/working_plan.js b/src/assets/js/working_plan.js index 8982619d..2560b86a 100755 --- a/src/assets/js/working_plan.js +++ b/src/assets/js/working_plan.js @@ -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());