Removed the use of jQuery methods for array and data processing wherever possible, along with other improvements in the javascript code.
This commit is contained in:
parent
25e8bbed31
commit
03b4adc6ad
19 changed files with 397 additions and 507 deletions
|
@ -26,9 +26,6 @@ window.Backend = window.Backend || {};
|
|||
* Main javascript code for the backend of Easy!Appointments.
|
||||
*/
|
||||
$(document).ready(function () {
|
||||
window.console = window.console || function () {
|
||||
}; // IE compatibility
|
||||
|
||||
$(window)
|
||||
.on('resize', function () {
|
||||
Backend.placeFooterToBottom();
|
||||
|
|
|
@ -292,26 +292,27 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
*/
|
||||
$('#select-service').change(function () {
|
||||
var serviceId = $('#select-service').val();
|
||||
|
||||
$('#select-provider').empty();
|
||||
|
||||
// Automatically update the service duration.
|
||||
$.each(GlobalVariables.availableServices, function (indexService, availableService) {
|
||||
if (Number(availableService.id) === serviceId) {
|
||||
var start = $('#start-datetime').datetimepicker('getDate');
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + availableService.duration * 60000));
|
||||
return false; // break loop
|
||||
}
|
||||
var service = GlobalVariables.availableServices.find(function (availableService) {
|
||||
return Number(availableService.id) === Number(serviceId);
|
||||
});
|
||||
|
||||
var start = $('#start-datetime').datetimepicker('getDate');
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + service.duration * 60000));
|
||||
|
||||
// Update the providers select box.
|
||||
$.each(GlobalVariables.availableProviders, function (indexProvider, provider) {
|
||||
$.each(provider.services, function (indexService, providerServiceId) {
|
||||
|
||||
GlobalVariables.availableProviders.forEach(function (provider) {
|
||||
provider.services.forEach(function (providerServiceId) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && Number(provider.id) !== GlobalVariables.user.id) {
|
||||
return true; // continue
|
||||
return; // continue
|
||||
}
|
||||
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY && GlobalVariables.secretaryProviders.indexOf(provider.id) === -1) {
|
||||
return true; // continue
|
||||
return; // continue
|
||||
}
|
||||
|
||||
// If the current provider is able to provide the selected service, add him to the listbox.
|
||||
|
@ -359,22 +360,18 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
// Fill the providers listbox with providers that can serve the appointment's
|
||||
// service and then select the user's provider.
|
||||
$dialog.find('#select-provider').empty();
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
GlobalVariables.availableProviders.forEach(function (provider, index) {
|
||||
var canProvideService = false;
|
||||
|
||||
var serviceId = $dialog.find('#select-service').val();
|
||||
|
||||
$.each(provider.services, function (index, providerServiceId) {
|
||||
if (Number(providerServiceId) === Number(serviceId)) {
|
||||
canProvideService = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
var canProvideService = provider.services.filter(function(providerServiceId) {
|
||||
return Number(providerServiceId) === Number(serviceId)
|
||||
}).length > 0;
|
||||
|
||||
if (canProvideService) { // Add the provider to the listbox.
|
||||
var option = new Option(provider.first_name
|
||||
+ ' ' + provider.last_name, provider.id);
|
||||
$dialog.find('#select-provider').append(option);
|
||||
$dialog.find('#select-provider')
|
||||
.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -386,16 +383,15 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
// Setup start and datetimepickers.
|
||||
// Get the selected service duration. It will be needed in order to calculate the appointment end datetime.
|
||||
var serviceId = $dialog.find('#select-service').val();
|
||||
var serviceDuration = 0;
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (Number(service.id) === Number(serviceId)) {
|
||||
serviceDuration = service.duration;
|
||||
return false;
|
||||
}
|
||||
|
||||
var service = GlobalVariables.availableServices.forEach(function(service) {
|
||||
return Number(service.id) === Number(serviceId);
|
||||
});
|
||||
|
||||
var duration = service ? service.duration : 0;
|
||||
|
||||
var startDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout);
|
||||
var endDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout).addMinutes(serviceDuration);
|
||||
var endDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout).addMinutes(duration);
|
||||
var dateFormat;
|
||||
|
||||
switch (GlobalVariables.dateFormat) {
|
||||
|
@ -446,13 +442,12 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
var serviceId = $('#select-service').val();
|
||||
|
||||
// Automatically update the #end-datetime DateTimePicker based on service duration.
|
||||
$.each(GlobalVariables.availableServices, function (indexService, availableService) {
|
||||
if (Number(availableService.id) === Number(serviceId)) {
|
||||
var start = $('#start-datetime').datetimepicker('getDate');
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + availableService.duration * 60000));
|
||||
return false; // break loop
|
||||
}
|
||||
var service = GlobalVariables.availableServices.find(function (availableService) {
|
||||
return Number(availableService.id) === Number(serviceId);
|
||||
});
|
||||
|
||||
var start = $('#start-datetime').datetimepicker('getDate');
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + service.duration * 60000));
|
||||
}
|
||||
});
|
||||
$dialog.find('#start-datetime').datetimepicker('setDate', startDatetime);
|
||||
|
@ -505,9 +500,9 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
// Check required fields.
|
||||
var missingRequiredField = false;
|
||||
|
||||
$dialog.find('.required').each(function () {
|
||||
if ($(this).val() === '' || $(this).val() === null) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$dialog.find('.required').each(function (index, requiredField) {
|
||||
if ($(requiredField).val() === '' || $(requiredField).val() === null) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequiredField = true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -54,7 +54,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* Hides the open popover element.
|
||||
*/
|
||||
$calendarPage.on('click', '.close-popover', function () {
|
||||
$(this).parents().eq(2).remove();
|
||||
$(this).parents('.popover').popover('destroy');
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* Enables the edit dialog of the selected calendar event.
|
||||
*/
|
||||
$calendarPage.on('click', '.edit-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover
|
||||
$(this).parents('.popover').popover('destroy');
|
||||
|
||||
var $dialog;
|
||||
|
||||
|
@ -130,7 +130,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* deletion then an AJAX call is made to the server and deletes the appointment from the database.
|
||||
*/
|
||||
$calendarPage.on('click', '.delete-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover.
|
||||
$(this).parents('.popover').popover('destroy');
|
||||
|
||||
var url;
|
||||
var data;
|
||||
|
@ -277,7 +277,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* above the calendar item.
|
||||
*/
|
||||
function calendarEventClick(event, jsEvent, view) {
|
||||
$('.popover').remove(); // Close all open popovers.
|
||||
$('.popover').popover('destroy'); // Close all open popovers.
|
||||
|
||||
var $html;
|
||||
var displayEdit;
|
||||
|
@ -833,13 +833,13 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$(window).trigger('resize'); // Places the footer on the bottom.
|
||||
|
||||
// Remove all open popovers.
|
||||
$('.close-popover').each(function () {
|
||||
$(this).parents().eq(2).remove();
|
||||
$('.close-popover').each(function (index, closePopoverButton) {
|
||||
$(closePopoverButton).parents('.popover').popover('destroy');
|
||||
});
|
||||
|
||||
// Add new pop overs.
|
||||
$('.fv-events').each(function (index, eventHandle) {
|
||||
$(eventHandle).popover();
|
||||
$('.fv-events').each(function (index, eventElement) {
|
||||
$(eventElement).popover();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -853,11 +853,11 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
*/
|
||||
function convertTitlesToHtml() {
|
||||
// Convert the titles to html code.
|
||||
$('.fc-custom').each(function () {
|
||||
var title = $(this).find('.fc-event-title').text();
|
||||
$(this).find('.fc-event-title').html(title);
|
||||
var time = $(this).find('.fc-event-time').text();
|
||||
$(this).find('.fc-event-time').html(time);
|
||||
$('.fc-custom').each(function (index, customEventElement) {
|
||||
var title = $(customEventElement).find('.fc-event-title').text();
|
||||
$(customEventElement).find('.fc-event-title').html(title);
|
||||
var time = $(customEventElement).find('.fc-event-time').text();
|
||||
$(customEventElement).find('.fc-event-time').html(time);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -889,9 +889,10 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
.done(function (response) {
|
||||
// Add appointments to calendar.
|
||||
var calendarEvents = [];
|
||||
|
||||
var $calendar = $('#calendar');
|
||||
|
||||
$.each(response.appointments, function (index, appointment) {
|
||||
response.appointments.forEach(function (appointment) {
|
||||
var event = {
|
||||
id: appointment.id,
|
||||
title: appointment.service.name + ' - '
|
||||
|
@ -923,9 +924,9 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
var calendarView = $calendar.fullCalendar('getView').name;
|
||||
|
||||
if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
GlobalVariables.availableProviders.forEach(function (provider, index) {
|
||||
if (Number(provider.id) === Number(recordId)) {
|
||||
var workingPlan={};
|
||||
var workingPlan = {};
|
||||
var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan);
|
||||
var extraWorkingPlan = jQuery.parseJSON(provider.settings.extra_working_plan);
|
||||
var unavailablePeriod;
|
||||
|
@ -941,7 +942,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
.getWeekdayName(parseInt($calendar.fullCalendar('getView').start.format('d')));
|
||||
|
||||
// Add custom unavailable periods.
|
||||
$.each(response.unavailables, function (index, unavailable) {
|
||||
response.unavailables.forEach(function (unavailable, index) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
|
||||
if (unavailable.notes.length > 30) {
|
||||
|
@ -1048,7 +1049,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
var breakStart;
|
||||
var breakEnd;
|
||||
|
||||
$.each(workingPlan[selectedDayName].breaks, function (index, currentBreak) {
|
||||
workingPlan[selectedDayName].breaks.forEach(function (currentBreak) {
|
||||
var breakStartString = currentBreak.start.split(':');
|
||||
breakStart = calendarDateStart.clone();
|
||||
breakStart.hour(parseInt(breakStartString[0]));
|
||||
|
@ -1080,7 +1081,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
|
||||
// Add custom unavailable periods (they are always displayed on the calendar, even if
|
||||
// the provider won't work on that day).
|
||||
$.each(response.unavailables, function (index, unavailable) {
|
||||
response.unavailables.forEach(function (unavailable) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
|
||||
if (unavailable.notes.length > 30) {
|
||||
|
@ -1107,13 +1108,13 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
if (extraWorkingPlan && currentDateStart.format('YYYY-MM-DD') in extraWorkingPlan) {
|
||||
workingDay = extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')]
|
||||
|
||||
var start_extra = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].start;
|
||||
var end_extra = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].end;
|
||||
var extraPeriodStart = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].start;
|
||||
var extraPeriodEnd = currentDateStart.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[currentDateStart.format('YYYY-MM-DD')].end;
|
||||
|
||||
var extraPeriod = {
|
||||
title: EALang.extra_period,
|
||||
start: moment(start_extra, 'YYYY-MM-DD HH:mm', true),
|
||||
end: moment(end_extra, 'YYYY-MM-DD HH:mm', true).add(1, 'day'),
|
||||
start: moment(extraPeriodStart, 'YYYY-MM-DD HH:mm', true),
|
||||
end: moment(extraPeriodEnd, 'YYYY-MM-DD HH:mm', true).add(1, 'day'),
|
||||
allDay: true,
|
||||
color: '#879DB4',
|
||||
editable: false,
|
||||
|
@ -1189,7 +1190,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
var breakStart;
|
||||
var breakEnd;
|
||||
|
||||
$.each(workingDay.breaks, function (index, currentBreak) {
|
||||
workingDay.breaks.forEach(function (currentBreak, index) {
|
||||
var breakStartString = currentBreak.start.split(':');
|
||||
breakStart = currentDateStart.clone();
|
||||
breakStart.hour(parseInt(breakStartString[0]));
|
||||
|
@ -1417,16 +1418,11 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY) {
|
||||
// Remove the providers that are not connected to the secretary.
|
||||
$('#select-filter-item option[type="provider"]').each(function (index, option) {
|
||||
var found = false;
|
||||
|
||||
$.each(GlobalVariables.secretaryProviders, function (index, secretaryProviderId) {
|
||||
if (Number($(option).val()) === Number(secretaryProviderId)) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
var provider = GlobalVariables.secretaryProviders.find(function(secretaryProviderId) {
|
||||
return Number($(option).val()) === Number(secretaryProviderId);
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
if (!provider) {
|
||||
$(option).remove();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -71,9 +71,8 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
$('#google-calendar').empty();
|
||||
$.each(response, function () {
|
||||
var option = '<option value="' + this.id + '">' + this.summary + '</option>';
|
||||
$('#google-calendar').append(option);
|
||||
response.forEach(response, function (event) {
|
||||
$('#google-calendar').append(new Option(event.summary, event.id));
|
||||
});
|
||||
|
||||
$('#select-google-calendar').modal('show');
|
||||
|
@ -92,21 +91,21 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
// Disable synchronization for selected provider.
|
||||
// Update page elements and make an AJAX call to remove the google sync setting of the
|
||||
// selected provider.
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
if (Number(provider.id) === Number($('#select-filter-item').val())) {
|
||||
provider.settings.google_sync = '0';
|
||||
provider.settings.google_token = null;
|
||||
var providerId = $('#select-filter-item').val();
|
||||
|
||||
disableProviderSync(provider.id);
|
||||
|
||||
$('#enable-sync').removeClass('btn-danger enabled');
|
||||
$('#enable-sync span:eq(1)').text(EALang.enable_sync);
|
||||
$('#google-sync').prop('disabled', true);
|
||||
$('#select-filter-item option:selected').attr('google-sync', 'false');
|
||||
|
||||
return false;
|
||||
}
|
||||
var provider = GlobalVariables.availableProviders.find(function (availableProvider) {
|
||||
return Number(provider.id) === Number(providerId);
|
||||
});
|
||||
|
||||
provider.settings.google_sync = '0';
|
||||
provider.settings.google_token = null;
|
||||
|
||||
disableProviderSync(provider.id);
|
||||
|
||||
$('#enable-sync').removeClass('btn-danger enabled');
|
||||
$('#enable-sync span:eq(1)').text(EALang.enable_sync);
|
||||
$('#google-sync').prop('disabled', true);
|
||||
$('#select-filter-item option:selected').attr('google-sync', 'false');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -89,22 +89,22 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
var $providerColumn = $(providerColumn);
|
||||
var provider = $providerColumn.data('provider');
|
||||
|
||||
$providerColumn.find('.calendar-wrapper').fullCalendar('removeEvents');
|
||||
// $providerColumn.find('.calendar-wrapper').fullCalendar('removeEvents');
|
||||
|
||||
createNonWorkingHours($providerColumn.find('.calendar-wrapper'), JSON.parse($providerColumn.data('provider').settings.working_plan));
|
||||
// createNonWorkingHours($providerColumn.find('.calendar-wrapper'), JSON.parse($providerColumn.data('provider').settings.working_plan));
|
||||
|
||||
// Add the appointments to the column.
|
||||
createAppointments($providerColumn, response.appointments);
|
||||
// createAppointments($providerColumn, response.appointments);
|
||||
|
||||
// Add the unavailabilities to the column.
|
||||
createUnavailabilities($providerColumn, response.unavailabilities);
|
||||
// createUnavailabilities($providerColumn, response.unavailabilities);
|
||||
|
||||
// Add the provider breaks to the column.
|
||||
var workingPlan = JSON.parse(provider.settings.working_plan);
|
||||
var day = date.toString('dddd').toLowerCase();
|
||||
if (workingPlan[day]) {
|
||||
var breaks = workingPlan[day].breaks;
|
||||
createBreaks($providerColumn, breaks);
|
||||
// createBreaks($providerColumn, breaks);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -132,7 +132,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* Hides the open popover element.
|
||||
*/
|
||||
$calendar.on('click', '.close-popover', function () {
|
||||
$(this).parents().eq(2).popover('destroy');
|
||||
$(this).parents('.popover').popover('destroy');
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -141,7 +141,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* Enables the edit dialog of the selected table event.
|
||||
*/
|
||||
$calendar.on('click', '.edit-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover
|
||||
$(this).parents('.popover').popover('destroy');
|
||||
|
||||
var $dialog;
|
||||
|
||||
|
@ -208,7 +208,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* deletion then an ajax call is made to the server and deletes the appointment from the database.
|
||||
*/
|
||||
$calendar.on('click', '.delete-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover.
|
||||
$(this).parents('.popover').popover('destroy'); // Hide the popover.
|
||||
|
||||
var url;
|
||||
var data;
|
||||
|
@ -448,12 +448,14 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
*/
|
||||
function createView(startDate, endDate) {
|
||||
// Disable date navigation.
|
||||
$('#calendar .calendar-header .btn').addClass('disabled').prop('disabled', true);
|
||||
$('#calendar .calendar-header .btn')
|
||||
.addClass('disabled')
|
||||
.prop('disabled', true);
|
||||
|
||||
// Remember provider calendar view mode.
|
||||
var providerView = {};
|
||||
$('.provider-column').each(function () {
|
||||
var $providerColumn = $(this);
|
||||
$('.provider-column').each(function (index, providerColumn) {
|
||||
var $providerColumn = $(providerColumn);
|
||||
var providerId = $providerColumn.data('provider').id;
|
||||
providerView[providerId] = $providerColumn.find('.calendar-wrapper').fullCalendar('getView').name;
|
||||
});
|
||||
|
@ -491,8 +493,8 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
$('#calendar .calendar-header .btn').removeClass('disabled').prop('disabled', false);
|
||||
|
||||
// Apply provider calendar view mode.
|
||||
$('.provider-column').each(function () {
|
||||
var $providerColumn = $(this);
|
||||
$('.provider-column').each(function (index, providerColumn) {
|
||||
var $providerColumn = $(providerColumn);
|
||||
var providerId = $providerColumn.data('provider').id;
|
||||
$providerColumn.find('.calendar-wrapper')
|
||||
.fullCalendar('changeView', providerView[providerId] || 'agendaDay');
|
||||
|
@ -1002,7 +1004,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* above the calendar item.
|
||||
*/
|
||||
function onEventClick(event, jsEvent) {
|
||||
$('.popover').remove(); // Close all open popovers.
|
||||
$('.popover').popover('destroy'); // Close all open popovers.
|
||||
|
||||
var $html;
|
||||
var displayEdit;
|
||||
|
|
|
@ -64,12 +64,9 @@
|
|||
}
|
||||
|
||||
var categoryId = $(this).attr('data-id');
|
||||
var category = {};
|
||||
$.each(instance.filterResults, function (index, item) {
|
||||
if (item.id === categoryId) {
|
||||
category = item;
|
||||
return false;
|
||||
}
|
||||
|
||||
var category = instance.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(categoryId);
|
||||
});
|
||||
|
||||
instance.display(category);
|
||||
|
@ -182,7 +179,8 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-categories .results').empty();
|
||||
$.each(response, function (index, category) {
|
||||
|
||||
response.forEach(function(category) {
|
||||
$('#filter-categories .results')
|
||||
.append(this.getFilterHtml(category))
|
||||
.append($('<hr/>'));
|
||||
|
@ -284,9 +282,9 @@
|
|||
try {
|
||||
var missingRequired = false;
|
||||
|
||||
$('#categories .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#categories .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -350,21 +348,16 @@
|
|||
|
||||
$('#filter-categories .selected').removeClass('selected');
|
||||
|
||||
$('#filter-categories .category-row').each(function () {
|
||||
if ($(this).attr('data-id') === id) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-categories .category-row[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, category) {
|
||||
if (category.id === id) {
|
||||
this.display(category);
|
||||
$('#edit-category, #delete-category').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
var category = this.filterResults.find(function (category) {
|
||||
return Number(category.id) === Number(id);
|
||||
}.bind(this));
|
||||
|
||||
this.display(category);
|
||||
|
||||
$('#edit-category, #delete-category').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -64,12 +64,8 @@
|
|||
}
|
||||
|
||||
var customerId = $(this).attr('data-id');
|
||||
var customer = {};
|
||||
$.each(instance.filterResults, function (index, item) {
|
||||
if (Number(item.id) === Number(customerId)) {
|
||||
customer = item;
|
||||
return false;
|
||||
}
|
||||
var customer = instance.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(customerId);
|
||||
});
|
||||
|
||||
instance.display(customer);
|
||||
|
@ -88,19 +84,15 @@
|
|||
$(this).addClass('selected');
|
||||
|
||||
var customerId = $('#filter-customers .selected').attr('data-id');
|
||||
var appointmentId = $(this).attr('data-id');
|
||||
var appointment = {};
|
||||
|
||||
$.each(instance.filterResults, function (index, customer) {
|
||||
if (customer.id === customerId) {
|
||||
$.each(customer.appointments, function (index, customerAppointment) {
|
||||
if (Number(customerAppointment.id) === Number(appointmentId)) {
|
||||
appointment = customerAppointment;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
var customer = instance.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(customerId);
|
||||
});
|
||||
|
||||
var appointmentId = $(this).attr('data-id');
|
||||
|
||||
var appointment = customer.appointments.find(function (customerAppointment) {
|
||||
return Number(customerAppointment.id) === Number(appointmentId);
|
||||
});
|
||||
|
||||
instance.displayAppointment(appointment);
|
||||
|
@ -253,9 +245,9 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
|
||||
$('.required').each(function () {
|
||||
if ($(this).val() === '') {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('.required').each(function (index, requiredField) {
|
||||
if ($(requiredField).val() === '') {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -319,13 +311,13 @@
|
|||
$('#timezone').val(customer.timezone);
|
||||
|
||||
$('#customer-appointments').empty();
|
||||
$.each(customer.appointments, function (index, appointment) {
|
||||
customer.appointments.forEach(function (appointment) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && parseInt(appointment.id_users_provider) !== GlobalVariables.user.id) {
|
||||
return true; // continue
|
||||
return;
|
||||
}
|
||||
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY && GlobalVariables.secretaryProviders.indexOf(appointment.id_users_provider) === -1) {
|
||||
return true; // continue
|
||||
return;
|
||||
}
|
||||
|
||||
var start = GeneralFunctions.formatDate(Date.parse(appointment.start_datetime), GlobalVariables.dateFormat, true);
|
||||
|
@ -377,7 +369,8 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-customers .results').empty();
|
||||
$.each(response, function (index, customer) {
|
||||
|
||||
response.forEach(function (customer) {
|
||||
$('#filter-customers .results')
|
||||
.append(this.getFilterHtml(customer))
|
||||
.append($('<hr/>'));
|
||||
|
@ -454,21 +447,16 @@
|
|||
|
||||
$('#filter-customers .selected').removeClass('selected');
|
||||
|
||||
$('#filter-customers .entry').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-customers .entry[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, customer) {
|
||||
if (Number(customer.id) === Number(id)) {
|
||||
this.display(customer);
|
||||
$('#edit-customer, #delete-customer').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
}.bind(this));
|
||||
var customer = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(id);
|
||||
});
|
||||
|
||||
this.display(customer);
|
||||
|
||||
$('#edit-customer, #delete-customer').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ window.BackendServices = window.BackendServices || {};
|
|||
defaultEventHandlers = defaultEventHandlers || true;
|
||||
|
||||
// Fill available service categories listbox.
|
||||
$.each(GlobalVariables.categories, function (index, category) {
|
||||
var option = new Option(category.name, category.id);
|
||||
$('#service-category').append(option);
|
||||
GlobalVariables.categories.forEach(function (category) {
|
||||
$('#service-category').append(new Option(category.name, category.id));
|
||||
});
|
||||
|
||||
$('#service-category').append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
||||
|
||||
// Instantiate helper object (service helper by default).
|
||||
|
@ -102,11 +102,13 @@ window.BackendServices = window.BackendServices || {};
|
|||
.done(function (response) {
|
||||
GlobalVariables.categories = response;
|
||||
var $select = $('#service-category');
|
||||
|
||||
$select.empty();
|
||||
$.each(response, function (index, category) {
|
||||
var option = new Option(category.name, category.id);
|
||||
$select.append(option);
|
||||
|
||||
response.forEach(function (category) {
|
||||
$select.append(new Option(category.name, category.id));
|
||||
});
|
||||
|
||||
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
|
|
|
@ -62,12 +62,9 @@
|
|||
}
|
||||
|
||||
var serviceId = $(this).attr('data-id');
|
||||
var service = {};
|
||||
$.each(instance.filterResults, function (index, item) {
|
||||
if (item.id === serviceId) {
|
||||
service = item;
|
||||
return false;
|
||||
}
|
||||
|
||||
var service = instance.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(serviceId);
|
||||
});
|
||||
|
||||
// Add dedicated provider link.
|
||||
|
@ -251,9 +248,9 @@
|
|||
// validate required fields.
|
||||
var missingRequired = false;
|
||||
|
||||
$('#services .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#services .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -329,7 +326,8 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-services .results').empty();
|
||||
$.each(response, function (index, service) {
|
||||
|
||||
response.forEach(function (service, index) {
|
||||
$('#filter-services .results')
|
||||
.append(ServicesHelper.prototype.getFilterHtml(service))
|
||||
.append( $('<hr/>'))
|
||||
|
@ -403,21 +401,16 @@
|
|||
|
||||
$('#filter-services .selected').removeClass('selected');
|
||||
|
||||
$('#filter-services .service-row').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-services .service-row[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, service) {
|
||||
if (Number(service.id) === Number(id)) {
|
||||
this.display(service);
|
||||
$('#edit-service, #delete-service').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
}.bind(this));
|
||||
var service = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(id);
|
||||
});
|
||||
|
||||
this.display(service);
|
||||
|
||||
$('#edit-service, #delete-service').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -46,19 +46,18 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
*
|
||||
* @param {bool} bindEventHandlers Optional (true), determines whether to bind the default event handlers.
|
||||
*/
|
||||
exports.initialize = function (bindEventHandlers) {
|
||||
bindEventHandlers = bindEventHandlers || true;
|
||||
exports.initialize = function (defaultEventHandlers) {
|
||||
defaultEventHandlers = defaultEventHandlers || true;
|
||||
|
||||
$('#cookie-notice-content, #terms-and-conditions-content, #privacy-policy-content').trumbowyg();
|
||||
|
||||
// Apply setting values from database.
|
||||
$.each(GlobalVariables.settings.system, function (index, setting) {
|
||||
var workingPlan = {};
|
||||
|
||||
GlobalVariables.settings.system.forEach(function (setting) {
|
||||
$('input[data-field="' + setting.name + '"]').val(setting.value);
|
||||
$('select[data-field="' + setting.name + '"]').val(setting.value);
|
||||
});
|
||||
|
||||
var workingPlan = {};
|
||||
$.each(GlobalVariables.settings.system, function (index, setting) {
|
||||
if (setting.name === 'company_working_plan') {
|
||||
workingPlan = $.parseJSON(setting.value);
|
||||
}
|
||||
|
@ -121,7 +120,6 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
$('#zip-code').val(GlobalVariables.settings.user.zip_code);
|
||||
$('#notes').val(GlobalVariables.settings.user.notes);
|
||||
$('#timezone').val(GlobalVariables.settings.user.timezone);
|
||||
|
||||
$('#username').val(GlobalVariables.settings.user.settings.username);
|
||||
$('#password, #retype-password').val('');
|
||||
$('#calendar-view').val(GlobalVariables.settings.user.settings.calendar_view);
|
||||
|
@ -135,7 +133,7 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
// Set default settings helper.
|
||||
settings = new SystemSettings();
|
||||
|
||||
if (bindEventHandlers) {
|
||||
if (defaultEventHandlers) {
|
||||
bindEventHandlers();
|
||||
var $link = $('#settings-page .nav li').not('.hidden').first().find('a');
|
||||
$link.tab('show');
|
||||
|
|
|
@ -67,10 +67,10 @@
|
|||
var settings = [];
|
||||
|
||||
// General Settings Tab
|
||||
$('#general').find('input, select').each(function () {
|
||||
$('#general').find('input, select').each(function (index, field) {
|
||||
settings.push({
|
||||
name: $(this).attr('data-field'),
|
||||
value: $(this).val()
|
||||
name: $(field).attr('data-field'),
|
||||
value: $(field).val()
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -153,9 +153,9 @@
|
|||
try {
|
||||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#general .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#general .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -96,9 +96,9 @@
|
|||
try {
|
||||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#user .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#user .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -150,6 +150,8 @@ window.BackendUsers = window.BackendUsers || {};
|
|||
.done(function (response) {
|
||||
GlobalVariables.providers = response;
|
||||
|
||||
$('#secretary-providers').empty();
|
||||
|
||||
GlobalVariables.providers.forEach(function(provider) {
|
||||
$('<div/>', {
|
||||
'class': 'checkbox',
|
||||
|
|
|
@ -56,25 +56,21 @@
|
|||
*
|
||||
* Display the selected admin data to the user.
|
||||
*/
|
||||
$('#admins').on('click', '.admin-row', function (e) {
|
||||
$('#admins').on('click', '.admin-row', function (event) {
|
||||
if ($('#filter-admins .filter').prop('disabled')) {
|
||||
$('#filter-admins .results').css('color', '#AAA');
|
||||
return; // exit because we are currently on edit mode
|
||||
}
|
||||
|
||||
var adminId = $(e.currentTarget).attr('data-id');
|
||||
var admin = {};
|
||||
var adminId = $(event.currentTarget).attr('data-id');
|
||||
|
||||
$.each(this.filterResults, function (index, item) {
|
||||
if (item.id === adminId) {
|
||||
admin = item;
|
||||
return false;
|
||||
}
|
||||
var admin = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(adminId);
|
||||
});
|
||||
|
||||
this.display(admin);
|
||||
$('#filter-admins .selected').removeClass('selected');
|
||||
$(e.currentTarget).addClass('selected');
|
||||
$(event.currentTarget).addClass('selected');
|
||||
$('#edit-admin, #delete-admin').prop('disabled', false);
|
||||
}.bind(this));
|
||||
|
||||
|
@ -245,9 +241,9 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
|
||||
$('#admins .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#admins .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -362,7 +358,8 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-admins .results').empty();
|
||||
$.each(response, function (index, admin) {
|
||||
|
||||
response.forEach(function (admin) {
|
||||
$('#filter-admins .results')
|
||||
.append(this.getFilterHtml(admin))
|
||||
.append($('<hr/>'));
|
||||
|
@ -439,21 +436,16 @@
|
|||
|
||||
$('#filter-admins .selected').removeClass('selected');
|
||||
|
||||
$('.admin-row').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-admins .admin-row[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, admin) {
|
||||
if (Number(admin.id) === Number(id)) {
|
||||
this.display(admin);
|
||||
$('#edit-admin, #delete-admin').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
}.bind(this));
|
||||
var admin = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(id);
|
||||
});
|
||||
|
||||
this.display(admin);
|
||||
|
||||
$('#edit-admin, #delete-admin').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -58,25 +58,20 @@
|
|||
*
|
||||
* Display the selected provider data to the user.
|
||||
*/
|
||||
$('#providers').on('click', '.provider-row', function (e) {
|
||||
$('#providers').on('click', '.provider-row', function (event) {
|
||||
if ($('#filter-providers .filter').prop('disabled')) {
|
||||
$('#filter-providers .results').css('color', '#AAA');
|
||||
return; // Exit because we are currently on edit mode.
|
||||
}
|
||||
|
||||
var providerId = $(e.currentTarget).attr('data-id');
|
||||
var provider = {};
|
||||
|
||||
$.each(this.filterResults, function (index, item) {
|
||||
if (item.id === providerId) {
|
||||
provider = item;
|
||||
return false;
|
||||
}
|
||||
var providerId = $(event.currentTarget).attr('data-id');
|
||||
var provider = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(providerId);
|
||||
});
|
||||
|
||||
this.display(provider);
|
||||
$('#filter-providers .selected').removeClass('selected');
|
||||
$(e.currentTarget).addClass('selected');
|
||||
$(event.currentTarget).addClass('selected');
|
||||
$('#edit-provider, #delete-provider').prop('disabled', false);
|
||||
}.bind(this));
|
||||
|
||||
|
@ -172,9 +167,9 @@
|
|||
|
||||
// Include provider services.
|
||||
provider.services = [];
|
||||
$('#provider-services input:checkbox').each(function () {
|
||||
if ($(this).prop('checked')) {
|
||||
provider.services.push($(this).attr('data-id'));
|
||||
$('#provider-services input:checkbox').each(function (index, checkbox) {
|
||||
if ($(checkbox).prop('checked')) {
|
||||
provider.services.push($(checkbox).attr('data-id'));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -297,9 +292,9 @@
|
|||
try {
|
||||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#providers .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#providers .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -421,26 +416,30 @@
|
|||
|
||||
$('#provider-services a').remove();
|
||||
$('#provider-services input:checkbox').prop('checked', false);
|
||||
$.each(provider.services, function (index, serviceId) {
|
||||
$('#provider-services input:checkbox').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(serviceId)) {
|
||||
$(this).prop('checked', true);
|
||||
// Add dedicated service-provider link.
|
||||
dedicatedUrl = GlobalVariables.baseUrl + '/index.php?provider=' + encodeURIComponent(provider.id)
|
||||
+ '&service=' + encodeURIComponent(serviceId);
|
||||
|
||||
$link = $('<a/>', {
|
||||
'href': dedicatedUrl,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-link'
|
||||
})
|
||||
]
|
||||
});
|
||||
provider.services.forEach(function (providerServiceId) {
|
||||
var $checkbox = $('#provider-services input[data-id="' + providerServiceId + '"]');
|
||||
|
||||
$(this).parent().append($link);
|
||||
}
|
||||
if (!$checkbox.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$checkbox.prop('checked', true);
|
||||
|
||||
// Add dedicated service-provider link.
|
||||
dedicatedUrl = GlobalVariables.baseUrl + '/index.php?provider=' + encodeURIComponent(provider.id)
|
||||
+ '&service=' + encodeURIComponent(providerServiceId);
|
||||
|
||||
$link = $('<a/>', {
|
||||
'href': dedicatedUrl,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-link'
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
$checkbox.parent().append($link);
|
||||
});
|
||||
|
||||
// Display working plan
|
||||
|
@ -476,7 +475,7 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-providers .results').empty();
|
||||
$.each(response, function (index, provider) {
|
||||
response.forEach(function (provider) {
|
||||
$('#filter-providers .results')
|
||||
.append(this.getFilterHtml(provider))
|
||||
.append($('<hr/>'));
|
||||
|
@ -617,22 +616,17 @@
|
|||
display = display || false;
|
||||
|
||||
// Select record in filter results.
|
||||
$('#filter-providers .provider-row').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-providers .provider-row[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
// Display record in form (if display = true).
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, provider) {
|
||||
if (Number(provider.id) === Number(id)) {
|
||||
this.display(provider);
|
||||
$('#edit-provider, #delete-provider').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
var provider = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(id);
|
||||
}.bind(this));
|
||||
|
||||
this.display(provider);
|
||||
|
||||
$('#edit-provider, #delete-provider').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -58,26 +58,22 @@
|
|||
*
|
||||
* Display the selected secretary data to the user.
|
||||
*/
|
||||
$('#secretaries').on('click', '.secretary-row', function (e) {
|
||||
$('#secretaries').on('click', '.secretary-row', function (event) {
|
||||
if ($('#filter-secretaries .filter').prop('disabled')) {
|
||||
$('#filter-secretaries .results').css('color', '#AAA');
|
||||
return; // exit because we are currently on edit mode
|
||||
}
|
||||
|
||||
var secretaryId = $(e.currentTarget).attr('data-id');
|
||||
var secretary = {};
|
||||
var secretaryId = $(event.currentTarget).attr('data-id');
|
||||
|
||||
$.each(this.filterResults, function (index, item) {
|
||||
if (item.id === secretaryId) {
|
||||
secretary = item;
|
||||
return false;
|
||||
}
|
||||
var secretary = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(secretaryId);
|
||||
});
|
||||
|
||||
this.display(secretary);
|
||||
|
||||
$('#filter-secretaries .selected').removeClass('selected');
|
||||
$(e.currentTarget).addClass('selected');
|
||||
$(event.currentTarget).addClass('selected');
|
||||
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
||||
}.bind(this));
|
||||
|
||||
|
@ -163,9 +159,9 @@
|
|||
|
||||
// Include secretary services.
|
||||
secretary.providers = [];
|
||||
$('#secretary-providers input:checkbox').each(function () {
|
||||
if ($(this).prop('checked')) {
|
||||
secretary.providers.push($(this).attr('data-id'));
|
||||
$('#secretary-providers input:checkbox').each(function (index, checkbox) {
|
||||
if ($(checkbox).prop('checked')) {
|
||||
secretary.providers.push($(checkbox).attr('data-id'));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -258,9 +254,9 @@
|
|||
try {
|
||||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#secretaries .required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('#secretaries .required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
@ -353,12 +349,15 @@
|
|||
}
|
||||
|
||||
$('#secretary-providers input:checkbox').prop('checked', false);
|
||||
$.each(secretary.providers, function (index, providerId) {
|
||||
$('#secretary-providers input:checkbox').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(providerId)) {
|
||||
$(this).prop('checked', true);
|
||||
}
|
||||
});
|
||||
|
||||
secretary.providers.forEach(function (secretaryProviderId) {
|
||||
var $checkbox = $('#secretary-providers input[data-id="' + secretaryProviderId + '"]');
|
||||
|
||||
if (!$checkbox.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
$checkbox.prop('checked', true);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -386,7 +385,8 @@
|
|||
this.filterResults = response;
|
||||
|
||||
$('#filter-secretaries .results').empty();
|
||||
$.each(response, function (index, secretary) {
|
||||
|
||||
response.forEach(function (secretary) {
|
||||
$('#filter-secretaries .results')
|
||||
.append(this.getFilterHtml(secretary))
|
||||
.append($('<hr/>'));
|
||||
|
@ -462,21 +462,16 @@
|
|||
|
||||
$('#filter-secretaries .selected').removeClass('selected');
|
||||
|
||||
$('#filter-secretaries .secretary-row').each(function () {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
$('#filter-secretaries .secretary-row[data-id="' + id + '"]').addClass('selected');
|
||||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, secretary) {
|
||||
if (Number(secretary.id) === Number(id)) {
|
||||
this.display(secretary);
|
||||
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
||||
return false;
|
||||
}
|
||||
var secretary = this.filterResults.find(function (filterResult) {
|
||||
return Number(filterResult.id) === Number(id);
|
||||
}.bind(this));
|
||||
|
||||
this.display(secretary);
|
||||
|
||||
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
/**
|
||||
* This method initializes the book appointment page.
|
||||
*
|
||||
* @param {Boolean} bindEventHandlers (OPTIONAL) Determines whether the default
|
||||
* @param {Boolean} defaultEventHandlers (OPTIONAL) Determines whether the default
|
||||
* event handlers will be bound to the dom elements.
|
||||
* @param {Boolean} manageMode (OPTIONAL) Determines whether the customer is going
|
||||
* to make changes to an existing appointment rather than booking a new one.
|
||||
|
@ -57,11 +57,6 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
defaultEventHandlers = defaultEventHandlers || true;
|
||||
manageMode = manageMode || false;
|
||||
|
||||
if (window.console) {
|
||||
window.console = function () {
|
||||
}; // IE compatibility
|
||||
}
|
||||
|
||||
if (GlobalVariables.displayCookieNotice) {
|
||||
cookieconsent.initialise({
|
||||
palette: {
|
||||
|
@ -231,18 +226,18 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
*/
|
||||
$('#select-service').change(function () {
|
||||
var serviceId = $('#select-service').val();
|
||||
|
||||
$('#select-provider').empty();
|
||||
|
||||
$.each(GlobalVariables.availableProviders, function (indexProvider, provider) {
|
||||
$.each(provider.services, function (indexService, providerServiceId) {
|
||||
// If the current provider is able to provide the selected service, add him to the listbox.
|
||||
if (Number(providerServiceId) === Number(serviceId)) {
|
||||
var optionHtml = '<option value="' + provider.id + '">'
|
||||
+ provider.first_name + ' ' + provider.last_name
|
||||
+ '</option>';
|
||||
$('#select-provider').append(optionHtml);
|
||||
}
|
||||
});
|
||||
GlobalVariables.availableProviders.forEach(function (provider) {
|
||||
// If the current provider is able to provide the selected service, add him to the list box.
|
||||
var canServeService = provider.services.filter(function (providerServiceId) {
|
||||
return Number(providerServiceId) === Number(serviceId);
|
||||
}).length > 0;
|
||||
|
||||
if (canServeService) {
|
||||
$('#select-provider').append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
||||
}
|
||||
});
|
||||
|
||||
// Add the "Any Provider" entry.
|
||||
|
@ -464,9 +459,9 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
try {
|
||||
// Validate required fields.
|
||||
var missingRequiredField = false;
|
||||
$('.required').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).parents('.form-group').addClass('has-error');
|
||||
$('.required').each(function (index, requiredField) {
|
||||
if (!$(requiredField).val()) {
|
||||
$(requiredField).parents('.form-group').addClass('has-error');
|
||||
missingRequiredField = true;
|
||||
}
|
||||
});
|
||||
|
@ -528,6 +523,8 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
}
|
||||
});
|
||||
|
||||
$('#appointment-details').empty();
|
||||
|
||||
$('<div/>', {
|
||||
'html': [
|
||||
$('<h4/>', {
|
||||
|
@ -548,7 +545,7 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
$('<br/>'),
|
||||
$('<span/>', {
|
||||
'text': $('#select-timezone option:selected').text()
|
||||
+ servicePrice + ' ' + serviceCurrency
|
||||
+ ' - ' + servicePrice + ' ' + serviceCurrency
|
||||
})
|
||||
]
|
||||
})
|
||||
|
@ -567,6 +564,8 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
var city = GeneralFunctions.escapeHtml($('#city').val());
|
||||
var zipCode = GeneralFunctions.escapeHtml($('#zip-code').val());
|
||||
|
||||
$('#customer-details').empty();
|
||||
|
||||
$('<div/>', {
|
||||
'html': [
|
||||
$('<h4/>)', {
|
||||
|
@ -644,13 +643,9 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
function calculateEndDatetime() {
|
||||
// Find selected service duration.
|
||||
var serviceId = $('#select-service').val();
|
||||
var serviceDuration;
|
||||
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (Number(service.id) === Number(serviceId)) {
|
||||
serviceDuration = service.duration;
|
||||
return false;
|
||||
}
|
||||
var service = GlobalVariables.availableServices.find(function (availableService) {
|
||||
return Number(availableService.id) === Number(serviceId);
|
||||
});
|
||||
|
||||
// Add the duration to the start datetime.
|
||||
|
@ -659,8 +654,8 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
startDatetime = Date.parseExact(startDatetime, 'dd-MM-yyyy HH:mm');
|
||||
var endDatetime;
|
||||
|
||||
if (serviceDuration && startDatetime) {
|
||||
endDatetime = startDatetime.add({'minutes': parseInt(serviceDuration)});
|
||||
if (service.duration && startDatetime) {
|
||||
endDatetime = startDatetime.add({'minutes': parseInt(service.duration)});
|
||||
} else {
|
||||
endDatetime = new Date();
|
||||
}
|
||||
|
|
|
@ -76,9 +76,9 @@ $(function () {
|
|||
|
||||
// Check for empty fields.
|
||||
var missingRequired = false;
|
||||
$('input').each(function () {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
$('input').each(function (index, field) {
|
||||
if (!$(field).val()) {
|
||||
$(field).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
* @param {Object} workingPlan Contains the working hours and breaks for each day of the week.
|
||||
*/
|
||||
WorkingPlan.prototype.setup = function (workingPlan) {
|
||||
var fDaynum = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
|
||||
var workingPlanSorted = GeneralFunctions.sortWeekDictionary(workingPlan,fDaynum);
|
||||
var weekDayId = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
|
||||
var workingPlanSorted = GeneralFunctions.sortWeekDictionary(workingPlan, weekDayId);
|
||||
|
||||
$('.working-plan tbody').empty();
|
||||
$('.breaks tbody').empty();
|
||||
|
@ -57,7 +57,7 @@
|
|||
$.each(workingPlanSorted, function (index, workingDay) {
|
||||
var day = this.convertValueToDay(index);
|
||||
|
||||
var dayTranslatedName = GeneralFunctions.upperCaseFirstLetter(day)
|
||||
var dayDisplayName = GeneralFunctions.upperCaseFirstLetter(day)
|
||||
|
||||
$('<tr/>', {
|
||||
'html': [
|
||||
|
@ -70,10 +70,10 @@
|
|||
'html': [
|
||||
$('<input/>', {
|
||||
'type': 'checkbox',
|
||||
'id': index,
|
||||
'id': index
|
||||
}),
|
||||
$('<span/>', {
|
||||
'text': dayTranslatedName
|
||||
'text': dayDisplayName
|
||||
})
|
||||
]
|
||||
})
|
||||
|
@ -108,19 +108,16 @@
|
|||
|
||||
// Sort day's breaks according to the starting hour
|
||||
workingDay.breaks.sort(function (break1, break2) {
|
||||
// We can do a direct string comparison since we have time based on 24 hours clock.
|
||||
return (break1.start).localeCompare(break2.start);
|
||||
});
|
||||
// We can do a direct string comparison since we have time based on 24 hours clock.
|
||||
return (break1.start).localeCompare(break2.start);
|
||||
});
|
||||
|
||||
// Add the day's breaks on the breaks table.
|
||||
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm';
|
||||
|
||||
workingDay.breaks.forEach(function(workingDayBreak, index) {
|
||||
workingDay.breaks.forEach(function (workingDayBreak) {
|
||||
$('<tr/>', {
|
||||
'html': [
|
||||
$('<td/>', {
|
||||
'class': 'break-day editable',
|
||||
'text': dayTranslatedName
|
||||
'text': dayDisplayName
|
||||
}),
|
||||
$('<td/>', {
|
||||
'class': 'break-start editable',
|
||||
|
@ -141,11 +138,7 @@
|
|||
'class': 'glyphicon glyphicon-pencil'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm delete-break',
|
||||
|
@ -155,11 +148,7 @@
|
|||
'class': 'glyphicon glyphicon-trash'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm save-break hidden',
|
||||
|
@ -169,11 +158,7 @@
|
|||
'class': 'glyphicon glyphicon-ok'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm cancel-break hidden',
|
||||
|
@ -210,7 +195,6 @@
|
|||
WorkingPlan.prototype.setupExtraPeriods = function (extraWorkingPlan) {
|
||||
$.each(extraWorkingPlan, function (index, extraWorkingDay) {
|
||||
if (extraWorkingDay) {
|
||||
|
||||
$('#' + index).prop('checked', true);
|
||||
$('#' + index + '-start').val(Date.parse(extraWorkingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
$('#' + index + '-end').val(Date.parse(extraWorkingDay.end).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
|
@ -244,11 +228,7 @@
|
|||
'class': 'glyphicon glyphicon-pencil'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm delete-extra',
|
||||
|
@ -258,11 +238,7 @@
|
|||
'class': 'glyphicon glyphicon-trash'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm save-extra hidden',
|
||||
|
@ -272,11 +248,7 @@
|
|||
'class': 'glyphicon glyphicon-ok'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm cancel-extra hidden',
|
||||
|
@ -395,7 +367,7 @@
|
|||
*
|
||||
* Enable or disable the time selection for each day.
|
||||
*/
|
||||
$('.working-plan tbody').on( "click", "input:checkbox", function () {
|
||||
$('.working-plan tbody').on("click", "input:checkbox", function () {
|
||||
var id = $(this).attr('id');
|
||||
|
||||
if ($(this).prop('checked') === true) {
|
||||
|
@ -416,79 +388,67 @@
|
|||
$('.add-break').click(function () {
|
||||
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm';
|
||||
|
||||
var $newBreak = $('<tr/>', {
|
||||
'html': [
|
||||
$('<td/>', {
|
||||
'class': 'break-day editable',
|
||||
'text': EALang.sunday
|
||||
}),
|
||||
$('<td/>', {
|
||||
'class': 'break-start editable',
|
||||
'text': '9:00 AM'
|
||||
}),
|
||||
$('<td/>', {
|
||||
'class': 'break-end editable',
|
||||
'text': '10:00 AM'
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm edit-break',
|
||||
'title': EALang.edit,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-pencil'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm delete-break',
|
||||
'title': EALang.delete,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-trash'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm save-break hidden',
|
||||
'title': EALang.save,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-ok'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm cancel-break hidden',
|
||||
'title': EALang.cancel,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-ban-circle'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
.appendTo('.breaks tbody');
|
||||
var $newBreak = $('<tr/>', {
|
||||
'html': [
|
||||
$('<td/>', {
|
||||
'class': 'break-day editable',
|
||||
'text': EALang.sunday
|
||||
}),
|
||||
$('<td/>', {
|
||||
'class': 'break-start editable',
|
||||
'text': '9:00 AM'
|
||||
}),
|
||||
$('<td/>', {
|
||||
'class': 'break-end editable',
|
||||
'text': '10:00 AM'
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm edit-break',
|
||||
'title': EALang.edit,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-pencil'
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm delete-break',
|
||||
'title': EALang.delete,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-trash'
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm save-break hidden',
|
||||
'title': EALang.save,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-ok'
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm cancel-break hidden',
|
||||
'title': EALang.cancel,
|
||||
'html': [
|
||||
$('<span/>', {
|
||||
'class': 'glyphicon glyphicon-ban-circle'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
.appendTo('.breaks tbody');
|
||||
|
||||
// Bind editable and event handlers.
|
||||
this.editableBreakDay($newBreak.find('.break-day'));
|
||||
|
@ -503,9 +463,10 @@
|
|||
* Enables the row editing for the "Breaks" table rows.
|
||||
*/
|
||||
$(document).on('click', '.edit-break', function () {
|
||||
// Reset previous editable tds
|
||||
var $previousEdt = $(this).closest('table').find('.editable').get();
|
||||
$.each($previousEdt, function (index, editable) {
|
||||
// Reset previous editable table cells.
|
||||
var $previousEdits = $(this).closest('table').find('.editable');
|
||||
|
||||
$previousEdits.each(function (index, editable) {
|
||||
if (editable.reset) {
|
||||
editable.reset();
|
||||
}
|
||||
|
@ -525,9 +486,10 @@
|
|||
$(this).parent().parent().find('.break-day select').focus();
|
||||
|
||||
// Show save - cancel buttons.
|
||||
$(this).closest('table').find('.edit-break, .delete-break').addClass('hidden');
|
||||
$(this).parent().find('.save-break, .cancel-break').removeClass('hidden');
|
||||
$(this).closest('tr').find('select,input:text').addClass('form-control input-sm')
|
||||
var $tr = $(this).closest('tr');
|
||||
$tr.find('.edit-break, .delete-break').addClass('hidden');
|
||||
$tr.find('.save-break, .cancel-break').removeClass('hidden');
|
||||
$tr.find('select,input:text').addClass('form-control input-sm')
|
||||
|
||||
$('.add-break').prop('disabled', true);
|
||||
});
|
||||
|
@ -548,8 +510,8 @@
|
|||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
$(document).on('click', '.cancel-break', function (e) {
|
||||
var element = e.target;
|
||||
$(document).on('click', '.cancel-break', function (event) {
|
||||
var element = event.target;
|
||||
var $modifiedRow = $(element).closest('tr');
|
||||
this.enableCancel = true;
|
||||
$modifiedRow.find('.cancel-editable').trigger('click');
|
||||
|
@ -567,12 +529,12 @@
|
|||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
$(document).on('click', '.save-break', function (e) {
|
||||
$(document).on('click', '.save-break', function (event) {
|
||||
// Break's start time must always be prior to break's end.
|
||||
var element = e.target,
|
||||
$modifiedRow = $(element).closest('tr'),
|
||||
start = Date.parse($modifiedRow.find('.break-start input').val()),
|
||||
end = Date.parse($modifiedRow.find('.break-end input').val());
|
||||
var element = event.target;
|
||||
var $modifiedRow = $(element).closest('tr');
|
||||
var start = Date.parse($modifiedRow.find('.break-start input').val());
|
||||
var end = Date.parse($modifiedRow.find('.break-end input').val());
|
||||
|
||||
if (start > end) {
|
||||
$modifiedRow.find('.break-end input').val(start.addHours(1).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm'));
|
||||
|
@ -589,7 +551,6 @@
|
|||
// Refresh working plan to have the new break sorted in the break list.
|
||||
var workingPlan = this.get();
|
||||
this.setup(workingPlan);
|
||||
|
||||
}.bind(this));
|
||||
|
||||
/**
|
||||
|
@ -601,8 +562,6 @@
|
|||
$('.add-extra-periods').click(function () {
|
||||
var today = GeneralFunctions.formatDate(new Date(), GlobalVariables.dateFormat, false);
|
||||
|
||||
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm';
|
||||
|
||||
var $newExtraPeriod = $('<tr/>', {
|
||||
'html': [
|
||||
$('<td/>', {
|
||||
|
@ -628,11 +587,7 @@
|
|||
'class': 'glyphicon glyphicon-pencil'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm delete-extra',
|
||||
|
@ -642,11 +597,7 @@
|
|||
'class': 'glyphicon glyphicon-trash'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm save-extra hidden',
|
||||
|
@ -656,11 +607,7 @@
|
|||
'class': 'glyphicon glyphicon-ok'
|
||||
})
|
||||
]
|
||||
})
|
||||
]
|
||||
}),
|
||||
$('<td/>', {
|
||||
'html': [
|
||||
}),
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'btn btn-default btn-sm cancel-extra hidden',
|
||||
|
@ -672,7 +619,7 @@
|
|||
]
|
||||
})
|
||||
]
|
||||
})
|
||||
}),
|
||||
]
|
||||
})
|
||||
.appendTo('.extra-periods tbody');
|
||||
|
@ -690,9 +637,10 @@
|
|||
* Enables the row editing for the "Extra Period" table rows.
|
||||
*/
|
||||
$(document).on('click', '.edit-extra', function () {
|
||||
// Reset previous editable tds
|
||||
var $previousEdt = $(this).closest('table').find('.editable').get();
|
||||
$.each($previousEdt, function (index, editable) {
|
||||
// Reset previous editable table cells.
|
||||
var $previousEdits = $(this).closest('table').find('.editable');
|
||||
|
||||
$previousEdits.each(function (index, editable) {
|
||||
if (editable.reset) {
|
||||
editable.reset();
|
||||
}
|
||||
|
@ -750,9 +698,10 @@
|
|||
});
|
||||
|
||||
// Show save - cancel buttons.
|
||||
$(this).closest('table').find('.edit-extra, .delete-extra').addClass('hidden');
|
||||
$(this).parent().find('.save-extra, .cancel-extra').removeClass('hidden');
|
||||
$(this).closest('tr').find('select,input:text').addClass('form-control input-sm')
|
||||
var $tr = $(this).closest('tr');
|
||||
$tr.find('.edit-extra, .delete-extra').addClass('hidden');
|
||||
$tr.find('.save-extra, .cancel-extra').removeClass('hidden');
|
||||
$tr.find('select,input:text').addClass('form-control input-sm')
|
||||
|
||||
$('.add-extra-periods').prop('disabled', true);
|
||||
});
|
||||
|
@ -773,8 +722,8 @@
|
|||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
$(document).on('click', '.cancel-extra', function (e) {
|
||||
var element = e.target;
|
||||
$(document).on('click', '.cancel-extra', function (event) {
|
||||
var element = event.target;
|
||||
var $modifiedRow = $(element).closest('tr');
|
||||
this.enableCancel = true;
|
||||
$modifiedRow.find('.cancel-editable').trigger('click');
|
||||
|
@ -792,12 +741,12 @@
|
|||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
$(document).on('click', '.save-extra', function (e) {
|
||||
$(document).on('click', '.save-extra', function (event) {
|
||||
// Break's start time must always be prior to break's end.
|
||||
var element = e.target,
|
||||
$modifiedRow = $(element).closest('tr'),
|
||||
start = Date.parse($modifiedRow.find('.extra-start input').val()),
|
||||
end = Date.parse($modifiedRow.find('.extra-end input').val());
|
||||
var element = event.target;
|
||||
var $modifiedRow = $(element).closest('tr');
|
||||
var start = Date.parse($modifiedRow.find('.extra-start input').val());
|
||||
var end = Date.parse($modifiedRow.find('.extra-end input').val());
|
||||
|
||||
if (start > end) {
|
||||
$modifiedRow.find('.extra-end input').val(start.addHours(1).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
|
|
Loading…
Reference in a new issue