Date handling fixes for JS files
This commit is contained in:
parent
f2bb4519a5
commit
0c5c1347aa
5 changed files with 41 additions and 34 deletions
|
@ -105,7 +105,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
|
|
||||||
// Add the provider breaks to the column.
|
// Add the provider breaks to the column.
|
||||||
var workingPlan = JSON.parse(provider.settings.working_plan);
|
var workingPlan = JSON.parse(provider.settings.working_plan);
|
||||||
var day = date.toString('dddd').toLowerCase();
|
var day = moment(date).format('dddd').toLowerCase();
|
||||||
if (workingPlan[day]) {
|
if (workingPlan[day]) {
|
||||||
var breaks = workingPlan[day].breaks;
|
var breaks = workingPlan[day].breaks;
|
||||||
createBreaks($providerColumn, breaks);
|
createBreaks($providerColumn, breaks);
|
||||||
|
@ -505,8 +505,8 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
}).appendTo('#calendar');
|
}).appendTo('#calendar');
|
||||||
|
|
||||||
$calendarView.data({
|
$calendarView.data({
|
||||||
startDate: startDate.toString('yyyy-MM-dd'),
|
startDate: moment(startDate).format('YYYY-MM-DD'),
|
||||||
endDate: endDate.toString('yyyy-MM-dd')
|
endDate: moment(endDate).format('YYYY-MM-DD')
|
||||||
});
|
});
|
||||||
|
|
||||||
var $wrapper = $('<div/>').appendTo($calendarView);
|
var $wrapper = $('<div/>').appendTo($calendarView);
|
||||||
|
@ -846,7 +846,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
var view = $calendar.fullCalendar('getView');
|
var view = $calendar.fullCalendar('getView');
|
||||||
var start = view.start.clone();
|
var start = view.start.clone();
|
||||||
var end = view.end.clone();
|
var end = view.end.clone();
|
||||||
var selDayName = start.toDate().toString('dddd').toLowerCase();
|
var selDayName = start.format('dddd').toLowerCase();
|
||||||
var selDayDate = start.format('YYYY-MM-DD');
|
var selDayDate = start.format('YYYY-MM-DD');
|
||||||
var calendarEventSource = [];
|
var calendarEventSource = [];
|
||||||
|
|
||||||
|
@ -892,7 +892,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var workDateStart = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + workingPlan[selDayName].start);
|
var workDateStart = moment(start.format('YYYY-MM-DD') + ' ' + workingPlan[selDayName].start);
|
||||||
|
|
||||||
if (start < workDateStart) {
|
if (start < workDateStart) {
|
||||||
unavailablePeriod = {
|
unavailablePeriod = {
|
||||||
|
@ -909,7 +909,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add unavailable period after work ends.
|
// Add unavailable period after work ends.
|
||||||
var workDateEnd = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + workingPlan[selDayName].end);
|
var workDateEnd = moment(start.format('YYYY-MM-DD') + ' ' + workingPlan[selDayName].end);
|
||||||
|
|
||||||
if (end > workDateEnd) {
|
if (end > workDateEnd) {
|
||||||
var unavailablePeriod = {
|
var unavailablePeriod = {
|
||||||
|
@ -930,8 +930,8 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
var breakEnd;
|
var breakEnd;
|
||||||
|
|
||||||
workingPlan[selDayName].breaks.forEach(function (currentBreak) {
|
workingPlan[selDayName].breaks.forEach(function (currentBreak) {
|
||||||
breakStart = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + currentBreak.start);
|
breakStart = moment(start.format('YYYY-MM-DD') + ' ' + currentBreak.start);
|
||||||
breakEnd = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + currentBreak.end);
|
breakEnd = moment(start.format('YYYY-MM-DD') + ' ' + currentBreak.end);
|
||||||
|
|
||||||
var unavailablePeriod = {
|
var unavailablePeriod = {
|
||||||
title: EALang.break,
|
title: EALang.break,
|
||||||
|
@ -1072,7 +1072,12 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
$event.html(
|
$event.html(
|
||||||
EALang.break + ' <span class="hour">' + eventDate.toString('HH:mm') + '</span> (' + eventDuration + "')"
|
EALang.break +
|
||||||
|
' <span class="hour">' +
|
||||||
|
moment(eventDate).format('HH:mm') +
|
||||||
|
'</span> (' +
|
||||||
|
eventDuration +
|
||||||
|
"')"
|
||||||
);
|
);
|
||||||
|
|
||||||
$event.data(entry);
|
$event.data(entry);
|
||||||
|
@ -1087,7 +1092,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
|
|
||||||
if (eventDate < cellDate) {
|
if (eventDate < cellDate) {
|
||||||
// Remove the hour from the event if it is the same as the row.
|
// Remove the hour from the event if it is the same as the row.
|
||||||
if (eventDate.toString('HH:mm') === $(tr).prev().find('td').eq(0).text()) {
|
if (moment(eventDate).format('HH:mm') === $(tr).prev().find('td').eq(0).text()) {
|
||||||
$event.find('.hour').remove();
|
$event.find('.hour').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1784,8 +1789,8 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
csrfToken: GlobalVariables.csrfToken,
|
csrfToken: GlobalVariables.csrfToken,
|
||||||
startDate: startDate.toString('yyyy-MM-dd'),
|
startDate: moment(startDate).format('YYYY-MM-DD'),
|
||||||
endDate: endDate.toString('yyyy-MM-dd')
|
endDate: moment(endDate).format('YYYY-MM-DD')
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
|
|
|
@ -66,8 +66,8 @@ window.BackendCalendarWorkingPlanExceptionsModal = window.BackendCalendarWorking
|
||||||
}
|
}
|
||||||
|
|
||||||
var workingPlanException = {
|
var workingPlanException = {
|
||||||
start: start.toString('HH:mm'),
|
start: moment(start).format('HH:mm'),
|
||||||
end: end.toString('HH:mm'),
|
end: moment(end).format('HH:mm'),
|
||||||
breaks: []
|
breaks: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,12 +88,12 @@ window.BackendCalendarWorkingPlanExceptionsModal = window.BackendCalendarWorking
|
||||||
throw new Error('Provider could not be found: ' + providerId);
|
throw new Error('Provider could not be found: ' + providerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedDate = date.toString('yyyy-MM-dd');
|
var selectedDate = moment(date).format('yyyy-MM-dd');
|
||||||
var workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions);
|
var workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions);
|
||||||
|
|
||||||
workingPlanExceptions[selectedDate] = {
|
workingPlanExceptions[selectedDate] = {
|
||||||
start: start.toString('HH:mm'),
|
start: moment(start).format('HH:mm'),
|
||||||
end: end.toString('HH:mm'),
|
end: moment(end).format('HH:mm'),
|
||||||
breaks: []
|
breaks: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -145,16 +145,17 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
closeText: EALang.close,
|
closeText: EALang.close,
|
||||||
|
|
||||||
onSelect: function (dateText, instance) {
|
onSelect: function (dateText, instance) {
|
||||||
FrontendBookApi.getAvailableHours($(this).datepicker('getDate').toString('yyyy-MM-dd'));
|
FrontendBookApi.getAvailableHours(moment($(this).datepicker('getDate')).format('YYYY-MM-DD'));
|
||||||
FrontendBook.updateConfirmFrame();
|
FrontendBook.updateConfirmFrame();
|
||||||
},
|
},
|
||||||
|
|
||||||
onChangeMonthYear: function (year, month, instance) {
|
onChangeMonthYear: function (year, month, instance) {
|
||||||
var currentDate = new Date(year, month - 1, 1);
|
var currentDate = new Date(year, month - 1, 1);
|
||||||
|
|
||||||
FrontendBookApi.getUnavailableDates(
|
FrontendBookApi.getUnavailableDates(
|
||||||
$('#select-provider').val(),
|
$('#select-provider').val(),
|
||||||
$('#select-service').val(),
|
$('#select-service').val(),
|
||||||
currentDate.toString('yyyy-MM-dd')
|
moment(currentDate).format('YYYY-MM-DD')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -220,7 +221,7 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrontendBookApi.getAvailableHours(date.toString('yyyy-MM-dd'));
|
FrontendBookApi.getAvailableHours(moment(date).format('YYYY-MM-DD'));
|
||||||
|
|
||||||
FrontendBook.updateConfirmFrame();
|
FrontendBook.updateConfirmFrame();
|
||||||
});
|
});
|
||||||
|
@ -234,7 +235,7 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
FrontendBookApi.getUnavailableDates(
|
FrontendBookApi.getUnavailableDates(
|
||||||
$(this).val(),
|
$(this).val(),
|
||||||
$('#select-service').val(),
|
$('#select-service').val(),
|
||||||
$('#select-date').datepicker('getDate').toString('yyyy-MM-dd')
|
moment($('#select-date').datepicker('getDate')).format('YYYY-MM-DD')
|
||||||
);
|
);
|
||||||
FrontendBook.updateConfirmFrame();
|
FrontendBook.updateConfirmFrame();
|
||||||
});
|
});
|
||||||
|
@ -274,7 +275,7 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
FrontendBookApi.getUnavailableDates(
|
FrontendBookApi.getUnavailableDates(
|
||||||
$('#select-provider').val(),
|
$('#select-provider').val(),
|
||||||
$(this).val(),
|
$(this).val(),
|
||||||
$('#select-date').datepicker('getDate').toString('yyyy-MM-dd')
|
moment($('#select-date').datepicker('getDate')).format('YYYY-MM-DD')
|
||||||
);
|
);
|
||||||
FrontendBook.updateConfirmFrame();
|
FrontendBook.updateConfirmFrame();
|
||||||
updateServiceDescription(serviceId);
|
updateServiceDescription(serviceId);
|
||||||
|
@ -671,7 +672,7 @@ window.FrontendBook = window.FrontendBook || {};
|
||||||
start_datetime:
|
start_datetime:
|
||||||
moment($('#select-date').datepicker('getDate')).format('YYYY-MM-DD') +
|
moment($('#select-date').datepicker('getDate')).format('YYYY-MM-DD') +
|
||||||
' ' +
|
' ' +
|
||||||
moment($('.selected-hour').data('value') || '').format('HH:mm') +
|
moment($('.selected-hour').data('value'), 'HH:mm').format('HH:mm') +
|
||||||
':00',
|
':00',
|
||||||
end_datetime: calculateEndDatetime(),
|
end_datetime: calculateEndDatetime(),
|
||||||
notes: $('#notes').val(),
|
notes: $('#notes').val(),
|
||||||
|
|
|
@ -272,15 +272,16 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
||||||
processingUnavailabilities = true;
|
processingUnavailabilities = true;
|
||||||
|
|
||||||
// Select first enabled date.
|
// Select first enabled date.
|
||||||
var selectedDate = moment(selectedDateString).toDate();
|
var selectedDateMoment = moment(selectedDateString);
|
||||||
var numberOfDays = moment(selectedDateString).daysInMonth();
|
var selectedDate = selectedDateMoment.toDate();
|
||||||
|
var numberOfDays = selectedDateMoment.daysInMonth();
|
||||||
|
|
||||||
if (setDate && !GlobalVariables.manageMode) {
|
if (setDate && !GlobalVariables.manageMode) {
|
||||||
for (var i = 1; i <= numberOfDays; i++) {
|
for (var i = 1; i <= numberOfDays; i++) {
|
||||||
var currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i);
|
var currentDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), i);
|
||||||
if (unavailableDates.indexOf(currentDate.toString('yyyy-MM-dd')) === -1) {
|
if (unavailableDates.indexOf(moment(currentDate).format('YYYY-MM-DD')) === -1) {
|
||||||
$('#select-date').datepicker('setDate', currentDate);
|
$('#select-date').datepicker('setDate', currentDate);
|
||||||
FrontendBookApi.getAvailableHours(currentDate.toString('yyyy-MM-dd'));
|
FrontendBookApi.getAvailableHours(moment(currentDate).format('YYYY-MM-DD'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,8 +294,8 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
||||||
|
|
||||||
// Grey out unavailable dates.
|
// Grey out unavailable dates.
|
||||||
$('#select-date .ui-datepicker-calendar td:not(.ui-datepicker-other-month)').each(function (index, td) {
|
$('#select-date .ui-datepicker-calendar td:not(.ui-datepicker-other-month)').each(function (index, td) {
|
||||||
selectedDate.set({day: index + 1});
|
selectedDateMoment.set({day: index + 1});
|
||||||
if (unavailableDates.indexOf(selectedDate.toString('yyyy-MM-dd')) !== -1) {
|
if (unavailableDates.indexOf(selectedDateMoment.format('YYYY-MM-DD')) !== -1) {
|
||||||
$(td).addClass('ui-datepicker-unselectable ui-state-disabled');
|
$(td).addClass('ui-datepicker-unselectable ui-state-disabled');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -83,11 +83,11 @@ $(function () {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var date = $date.datepicker('getDate').toString('yyyy-MM-dd');
|
var date = moment($date.datepicker('getDate')).format('YYYY-MM-DD');
|
||||||
|
|
||||||
var workingPlanException = {
|
var workingPlanException = {
|
||||||
start: $start.datetimepicker('getDate').toString('HH:mm'),
|
start: moment($start.datetimepicker('getDate')).format('HH:mm'),
|
||||||
end: $end.datetimepicker('getDate').toString('HH:mm'),
|
end: moment($end.datetimepicker('getDate')).format('HH:mm'),
|
||||||
breaks: getBreaks()
|
breaks: getBreaks()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -170,11 +170,11 @@ $(function () {
|
||||||
'html': [
|
'html': [
|
||||||
$('<td/>', {
|
$('<td/>', {
|
||||||
'class': 'working-plan-exceptions-break-start editable',
|
'class': 'working-plan-exceptions-break-start editable',
|
||||||
'text': moment(breakPeriod.start, 'HH:mm').toString(timeFormat)
|
'text': moment(breakPeriod.start, 'HH:mm').format(timeFormat)
|
||||||
}),
|
}),
|
||||||
$('<td/>', {
|
$('<td/>', {
|
||||||
'class': 'working-plan-exceptions-break-end editable',
|
'class': 'working-plan-exceptions-break-end editable',
|
||||||
'text': moment(breakPeriod.end, 'HH:mm').toString(timeFormat)
|
'text': moment(breakPeriod.end, 'HH:mm').format(timeFormat)
|
||||||
}),
|
}),
|
||||||
$('<td/>', {
|
$('<td/>', {
|
||||||
'html': [
|
'html': [
|
||||||
|
|
Loading…
Reference in a new issue