mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 22:52:35 +03:00
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
874c94e2ae
commit
78bd5e67fd
3 changed files with 76 additions and 2 deletions
|
@ -801,9 +801,13 @@ 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 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,4 +431,71 @@ 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;
|
||||
};
|
||||
|
||||
})(window.GeneralFunctions);
|
||||
|
|
|
@ -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