Adjusted HTTP requests in javascript files (and further code fine tuning).

This commit is contained in:
Alex Tselegidis 2020-04-27 20:14:20 +02:00
parent 54ded65728
commit 83fd802f57
24 changed files with 277 additions and 678 deletions

View file

@ -71,8 +71,9 @@
$('form').submit(function(event) {
event.preventDefault();
var postUrl = GlobalVariables.baseUrl + '/index.php/user/ajax_forgot_password';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/user/ajax_forgot_password';
var data = {
'csrfToken': GlobalVariables.csrfToken,
'username': $('#username').val(),
'email': $('#email').val()
@ -81,23 +82,20 @@
$('.alert').addClass('hidden');
$('#get-new-password').prop('disabled', true);
$.post(postUrl, postData, function(response) {
$('.alert').removeClass('hidden alert-danger alert-success');
$('#get-new-password').prop('disabled', false);
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
if (response == GlobalVariables.AJAX_SUCCESS) {
$('.alert').addClass('alert-success');
$('.alert').text(EALang['new_password_sent_with_email']);
} else {
$('.alert').addClass('alert-danger');
$('.alert').text('The operation failed! Please enter a valid username '
$.post(url, data)
.done(function(response) {
$('.alert').removeClass('hidden alert-danger alert-success');
$('#get-new-password').prop('disabled', false);
if (response === GlobalVariables.AJAX_SUCCESS) {
$('.alert').addClass('alert-success');
$('.alert').text(EALang['new_password_sent_with_email']);
} else {
$('.alert').addClass('alert-danger');
$('.alert').text('The operation failed! Please enter a valid username '
+ 'and email address in order to get a new password.');
}
}, 'json');
}
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
});
</script>

View file

@ -67,8 +67,8 @@
$('#login-form').submit(function(event) {
event.preventDefault();
var postUrl = GlobalVariables.baseUrl + '/index.php/user/ajax_check_login';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/user/ajax_check_login';
var data = {
'csrfToken': GlobalVariables.csrfToken,
'username': $('#username').val(),
'password': $('#password').val()
@ -76,20 +76,18 @@
$('.alert').addClass('hidden');
$.post(postUrl, postData, function(response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
if (response == GlobalVariables.AJAX_SUCCESS) {
window.location.href = GlobalVariables.destUrl;
} else {
$('.alert').text(EALang['login_failed']);
$('.alert')
.removeClass('hidden alert-danger alert-success')
.addClass('alert-danger');
}
}, 'json');
$.post(url, data)
.done(function(response) {
if (response === GlobalVariables.AJAX_SUCCESS) {
window.location.href = GlobalVariables.destUrl;
} else {
$('.alert').text(EALang['login_failed']);
$('.alert')
.removeClass('hidden alert-danger alert-success')
.addClass('alert-danger');
}
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
});
</script>

View file

@ -98,45 +98,65 @@ window.Backend = window.Backend || {};
/**
* Display backend notifications to user.
*
* Using this method you can display notifications to the use with custom messages. If the
* 'actions' array is provided then an action link will be displayed too.
* Using this method you can display notifications to the use with custom messages. If the 'actions' array is
* provided then an action link will be displayed too.
*
* @param {String} message Notification message
* @param {Array} actions An array with custom actions that will be available to the user. Every
* array item is an object that contains the 'label' and 'function' key values.
* @param {Array} actions An array with custom actions that will be available to the user. Every array item is an
* object that contains the 'label' and 'function' key values.
*/
exports.displayNotification = function (message, actions) {
message = message || 'NO MESSAGE PROVIDED FOR THIS NOTIFICATION';
message = message || '- No message provided for this notification -';
if (actions === undefined) {
var $notification = $('#notification');
if (!actions) {
actions = [];
setTimeout(function () {
$('#notification').fadeIn();
$notification.fadeIn();
}, 5000);
}
var customActionsHtml = '';
$notification.empty();
$('<div/>', {
'class': 'notification alert',
'html': [
$('<button/>', {
'type': 'button',
'class': 'close',
'data-dismiss': 'alert',
'html': [
$('<span/>', {
'html': '&times;'
})
]
}),
$('<strong/>', {
'html': message
}),
]
})
.appendTo($notification);
$.each(actions, function (index, action) {
var actionId = action.label.toLowerCase().replace(' ', '-');
customActionsHtml += '<button id="' + actionId + '" class="btn btn-default btn-xs">'
+ action.label + '</button>';
$(document).off('click', '#' + actionId);
$(document).on('click', '#' + actionId, action.function);
$('<button/>', {
'id': actionId,
'class': 'btn btn-default btn-xs',
'text': action.label
})
.appendTo($notification);
$(document)
.off('click', '#' + actionId)
.on('click', '#' + actionId, action.function);
});
var notificationHtml =
'<div class="notification alert">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
'<span aria-hidden="true">&times;</span>' +
'</button>' +
'<strong>' + message + '</strong>' +
customActionsHtml +
'</div>';
$('#notification').html(notificationHtml);
$('#notification').show('fade');
$notification.show('fade');
}
})(window.Backend);

View file

@ -98,12 +98,6 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
// Define success callback.
var successCallback = function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
$dialog.find('.modal-message').text(EALang.unexpected_issues_occurred);
$dialog.find('.modal-message').addClass('alert-danger').removeClass('hidden');
return false;
}
// Display success message to the user.
$dialog.find('.modal-message').text(EALang.appointment_saved);
$dialog.find('.modal-message').addClass('alert-success').removeClass('alert-danger hidden');
@ -417,8 +411,8 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
throw new Error('Invalid GlobalVariables.dateFormat value.');
}
var fDay = GlobalVariables.firstWeekday;
var fDaynum = GeneralFunctions.getWeekDayId(fDay);
var firstWeekDay = GlobalVariables.firstWeekday;
var firstWeekDayNumber = GeneralFunctions.getWeekDayId(firstWeekDay);
$dialog.find('#start-datetime').datetimepicker({
dateFormat: dateFormat,
@ -446,7 +440,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
timeText: EALang.time,
hourText: EALang.hour,
minuteText: EALang.minutes,
firstDay: fDaynum,
firstDay: firstWeekDayNumber,
onClose: function () {
var sid = $('#select-service').val();
@ -488,7 +482,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
timeText: EALang.time,
hourText: EALang.hour,
minuteText: EALang.minutes,
firstDay: fDaynum
firstDay: firstWeekDayNumber
});
$dialog.find('#end-datetime').datetimepicker('setDate', endDatetime);
};
@ -497,7 +491,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
* Validate the manage appointment dialog data. Validation checks need to
* run every time the data are going to be saved.
*
* @returns {Boolean} Returns the validation result.
* @return {Boolean} Returns the validation result.
*/
function _validateAppointmentForm() {
var $dialog = $('#manage-appointment');

View file

@ -145,19 +145,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
$.post(url, data, function (response) {
$('#message_box').dialog('close');
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
var extraWorkingPlan = jQuery.parseJSON(lastFocusedEventData.data.settings.extra_working_plan);
delete extraWorkingPlan[lastFocusedEventData.start.format('YYYY-MM-DD')];
lastFocusedEventData.data.settings.extra_working_plan = JSON.stringify(extraWorkingPlan);
@ -181,21 +168,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
$.post(url, data, function (response) {
$('#message_box').dialog('close');
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Refresh calendar event items.
$('#select-filter-item').trigger('change');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
@ -226,19 +198,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
$.post(url, data, function (response) {
$('#message_box').dialog('close');
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Refresh calendar event items.
$('#select-filter-item').trigger('change');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
@ -485,20 +444,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
// Success callback
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
// Display warning information to the user.
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Display success notification to user.
var undoFunction = function () {
appointment.end_datetime = event.data.end_datetime = Date.parseExact(
@ -546,20 +491,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
// Define success callback function.
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
// Display warning information to the user.
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Display success notification to user.
var undoFunction = function () {
unavailable.end_datetime = event.data.end_datetime = Date.parseExact(
@ -662,20 +593,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
// Define success callback function.
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
// Display warning information to the user.
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Define the undo function, if the user needs to reset the last change.
var undoFunction = function () {
appointment.start_datetime = Date.parseExact(
@ -725,19 +642,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
};
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
var undoFunction = function () {
unavailable.start_datetime = Date.parseExact(
unavailable.start_datetime, 'yyyy-MM-dd HH:mm:ss')
@ -852,10 +756,6 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
$('#loading').css('visibility', 'hidden');
return $.post(url, data, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
// Add appointments to calendar.
var calendarEvents = [];
var $calendar = $('#calendar');
@ -899,13 +799,15 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
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
var fDaynum = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
workingPlan = GeneralFunctions.sortWeekDict(workingPlanBulk,fDaynum);
// Sort the working plan starting with the first day as set in General settings to correctly
// align breaks in the calendar display.
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
workingPlan = GeneralFunctions.sortWeekDictionary(workingPlanBulk, firstWeekdayNumber);
switch (calendarView) {
case 'agendaDay':
var selectedDayName = GeneralFunctions.getWeekDayName(parseInt($calendar.fullCalendar('getView').start.format('d')));
var selectedDayName = GeneralFunctions
.getWeekdayName(parseInt($calendar.fullCalendar('getView').start.format('d')));
// Add custom unavailable periods.
$.each(response.unavailables, function (index, unavailable) {
@ -1234,15 +1136,15 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
var defaultView = window.innerWidth < 468 ? 'agendaDay' : 'agendaWeek';
var fDay = GlobalVariables.firstWeekday;
var fDaynum = GeneralFunctions.getWeekDayId(fDay);
var firstWeekday = GlobalVariables.firstWeekday;
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(firstWeekday);
// Initialize page calendar
$('#calendar').fullCalendar({
defaultView: defaultView,
height: _getCalendarHeight(),
editable: true,
firstDay: fDaynum,
firstDay: firstWeekdayNumber,
snapDuration: '00:30:00',
timeFormat: timeFormat,
slotLabelFormat: slotTimeFormat,

View file

@ -58,27 +58,6 @@ window.BackendCalendarExtraPeriodsModal = window.BackendCalendarExtraPeriodsModa
//}
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
$dialog.find('.modal-message')
.text(EALang.unexpected_issues_occurred)
.addClass('alert-danger')
.removeClass('hidden');
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Display success message to the user.
$dialog.find('.modal-message')
.text(EALang.extra_period_saved)

View file

@ -68,10 +68,6 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
$('#google-calendar').empty();
$.each(response, function () {
var option = '<option value="' + this.id + '">' + this.summary + '</option>';
@ -115,19 +111,18 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
* Event: Select Google Calendar "Click"
*/
$('#select-calendar').click(function () {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_select_google_calendar';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_select_google_calendar';
var data = {
csrfToken: GlobalVariables.csrfToken,
provider_id: $('#select-filter-item').val(),
calendar_id: $('#google-calendar').val()
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.google_calendar_selected);
$('#select-google-calendar').modal('hide');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function () {
Backend.displayNotification(EALang.google_calendar_selected);
$('#select-google-calendar').modal('hide');
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
/**
@ -151,21 +146,6 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
dataType: 'json'
})
.done(function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
Backend.displayNotification(EALang.google_sync_completed);
$('#reload-appointments').trigger('click');
})
@ -185,19 +165,14 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
function _disableProviderSync(providerId) {
// Make an ajax call to the server in order to disable the setting
// from the database.
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_disable_provider_sync';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_disable_provider_sync';
var data = {
csrfToken: GlobalVariables.csrfToken,
provider_id: providerId
};
$.post(postUrl, postData, function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
}
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.fail(GeneralFunctions.ajaxFailureHandler);
}

View file

@ -55,25 +55,21 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
var endDate = new Date(startDate.getTime()).add({days: parseInt($(this).val()) - 1});
_createView(startDate, endDate);
// Horizontal scrolling fix for sticky table headers.
// Horizontal scrolling fix for sticky table headers.
stickyTableHeaderInterval = setInterval(function () {
$(window).trigger('resize.stickyTableHeaders');
}, 1000);
});
$calendarToolbar.on('click', '#reload-appointments', function () {
// Remove all the events from the tables.
// Remove all the events from the tables.
$('.calendar-view .event').remove();
// Fetch the events and place them in the existing HTML format.
// Fetch the events and place them in the existing HTML format.
var startDate = new Date($('.calendar-view .date-column:first').data('date'));
var endDate = new Date($('.calendar-view .date-column:last').data('date'));
_getCalendarEvents(startDate, endDate)
.done(function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
var currentDate = startDate;
while (currentDate <= endDate) {
@ -89,13 +85,13 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
var $providerColumn = $(providerColumn);
var provider = $providerColumn.data('provider');
// Add the appointments to the column.
// Add the appointments to the column.
_createAppointments($providerColumn, response.appointments);
// Add the unavailabilities to the column.
// Add the unavailabilities to the column.
_createUnavailabilities($providerColumn, response.unavailabilities);
// Add the provider breaks to the column.
// Add the provider breaks to the column.
var workingPlan = JSON.parse(provider.settings.working_plan);
var day = date.toString('dddd').toLowerCase();
if (workingPlan[day]) {
@ -116,21 +112,21 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$calendar.on('click', '.calendar-view table td', function () {
if ($(this).index() === 0) {
return; // Clicked on an hour slot.
return; // Clicked on an hour slot.
}
// Open the appointments modal in the selected hour.
// Open the appointments modal in the selected hour.
var hour = $(this).parent().find('td:first').text().split(':');
var date = new Date($(this).parents('.date-column').data('date'));
date.set({hour: parseInt(hour[0]), minute: parseInt(hour[1])});
// Open the appointments dialog.
// Open the appointments dialog.
$('#insert-appointment').trigger('click');
// Update start date field.
$('#start-datetime').datepicker('setDate', date);
// Select Service and provider.
// Select Service and provider.
var $providerColumn = $(this).parents('.provider-column');
var serviceId = $providerColumn.find('thead tr:last th').eq($(this).index()).data('id');
var providerId = $providerColumn.data('provider').id;
@ -332,21 +328,6 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$.post(postUrl, postData, function (response) {
$('#message_box').dialog('close');
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Refresh calendar event items.
$('#select-filter-item').trigger('change');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
@ -385,19 +366,6 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$.post(url, data, function (response) {
$('#message_box').dialog('close');
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Refresh calendar event items.
$('#select-filter-item').trigger('change');
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
@ -491,10 +459,6 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
_getCalendarEvents(startDate, endDate)
.done(function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
var currentDate = startDate;
while (currentDate <= endDate) {
@ -572,16 +536,16 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$providerColumn.data('provider', provider);
// Create the table slots.
// Create the table slots.
_createSlots($providerColumn, date, provider);
// Add the appointments to the column.
// Add the appointments to the column.
_createAppointments($providerColumn, events.appointments);
// Add the unavailabilities to the column.
// Add the unavailabilities to the column.
_createUnavailabilities($providerColumn, events.unavailabilities);
// Add the provider breaks to the column.
// Add the provider breaks to the column.
var workingPlan = JSON.parse(provider.settings.working_plan);
var day = date.toString('dddd').toLowerCase();
if (workingPlan[day]) {
@ -707,7 +671,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
$event.appendTo($(tr).prev().find('td').eq(cellIndex));
// 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(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm') === $(tr).prev().find('td').eq(0).text()) {
$event.find('.hour').remove();
}
@ -762,7 +726,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
if (eventDate < cellDate) {
$event.appendTo($(tr).prev().find('td').eq(1));
// 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(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm') === $(tr).prev().find('td').eq(0).text()) {
$event.find('.hour').remove();
}
@ -811,7 +775,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
});
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(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm') === $(tr).prev().find('td').eq(0).text()) {
$event.find('.hour').remove();
}
@ -839,7 +803,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
height = 500;
}
// $('.calendar-view').height(height);
// $('.calendar-view').height(height);
$('.calendar-view > div').css('min-width', '1000%');
@ -893,7 +857,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
_createView(Date.today(), Date.today().add({days: parseInt($('#select-filter-item').val() - 1)}));
_bindEventHandlers();
// Hide Google Calendar Sync buttons cause they can not be used within this view.
// Hide Google Calendar Sync buttons cause they can not be used within this view.
$('#enable-sync, #google-sync').hide();
// Auto-reload the results every one minute.

View file

@ -59,27 +59,6 @@ window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabili
}
var successCallback = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
$dialog.find('.modal-message')
.text(EALang.unexpected_issues_occurred)
.addClass('alert-danger')
.removeClass('hidden');
return;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
// Display success message to the user.
$dialog.find('.modal-message')
.text(EALang.unavailable_saved)
@ -259,4 +238,4 @@ window.BackendCalendarUnavailabilitiesModal = window.BackendCalendarUnavailabili
_bindEventHandlers();
};
})(window.BackendCalendarUnavailabilitiesModal);
})(window.BackendCalendarUnavailabilitiesModal);

View file

@ -177,10 +177,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-categories .results').html('');
@ -223,10 +219,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.service_category_saved);
this.resetForm();
$('#filter-categories .key').val('');
@ -248,10 +240,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.service_category_deleted);
this.resetForm();

View file

@ -208,10 +208,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.customer_saved);
this.resetForm();
$('#filter-customers .key').val('');
@ -232,10 +228,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.customer_deleted);
this.resetForm();
this.filter($('#filter-customers .key').val());
@ -363,10 +355,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-customers .results').html('');

View file

@ -98,10 +98,6 @@ window.BackendServices = window.BackendServices || {};
};
$.post(url, data, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
GlobalVariables.categories = response;
var $select = $('#service-category');
$select.empty();

View file

@ -197,10 +197,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.service_saved);
this.resetForm();
$('#filter-services .key').val('');
@ -221,10 +217,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.service_deleted);
this.resetForm();
@ -317,10 +309,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-services .results').html('');

View file

@ -226,10 +226,6 @@ window.BackendSettings = window.BackendSettings || {};
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
if (response == false) {
$input.closest('.form-group').addClass('has-error');
Backend.displayNotification(EALang.username_already_exists);
@ -257,10 +253,6 @@ window.BackendSettings = window.BackendSettings || {};
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.working_plans_got_updated);
}, 'json')
.fail(GeneralFunctions.ajaxFailureHandler)

View file

@ -37,10 +37,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.settings_saved);
// Update the logo title on the header.

View file

@ -24,7 +24,7 @@
/**
* Get the settings data for the user settings.
*
* @returns {Object} Returns the user settings array.
* @return {Object} Returns the user settings array.
*/
UserSettings.prototype.get = function () {
var user = {
@ -73,10 +73,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.settings_saved);
// Update footer greetings.

View file

@ -131,10 +131,6 @@ window.BackendUsers = window.BackendUsers || {};
key: ''
};
$.post(url, data, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
GlobalVariables.providers = response;
var html = '<div>';
@ -186,10 +182,6 @@ window.BackendUsers = window.BackendUsers || {};
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
if (response == false) {
$input.closest('.form-group').addClass('has-error');
$input.attr('already-exists', 'true');

View file

@ -194,21 +194,20 @@
* then the update operation is going to be executed.
*/
AdminsHelper.prototype.save = function (admin) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_admin';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_admin';
var data = {
csrfToken: GlobalVariables.csrfToken,
admin: JSON.stringify(admin)
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.admin_saved);
this.resetForm();
$('#filter-admins .key').val('');
this.filter('', response.id, true);
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function (response) {
Backend.displayNotification(EALang.admin_saved);
this.resetForm();
$('#filter-admins .key').val('');
this.filter('', response.id, true);
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -217,20 +216,19 @@
* @param {Number} id Record id to be deleted.
*/
AdminsHelper.prototype.delete = function (id) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin';
var data = {
csrfToken: GlobalVariables.csrfToken,
admin_id: id
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.admin_deleted);
this.resetForm();
this.filter($('#filter-admins .key').val());
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function (response) {
Backend.displayNotification(EALang.admin_deleted);
this.resetForm();
this.filter($('#filter-admins .key').val());
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -357,10 +355,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-admins .results').html('');

View file

@ -249,21 +249,20 @@
* then the update operation is going to be executed.
*/
ProvidersHelper.prototype.save = function (provider) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_provider';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_provider';
var data = {
csrfToken: GlobalVariables.csrfToken,
provider: JSON.stringify(provider)
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.provider_saved);
this.resetForm();
$('#filter-providers .key').val('');
this.filter('', response.id, true);
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function (response) {
Backend.displayNotification(EALang.provider_saved);
this.resetForm();
$('#filter-providers .key').val('');
this.filter('', response.id, true);
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -272,20 +271,19 @@
* @param {Number} id Record id to be deleted.
*/
ProvidersHelper.prototype.delete = function (id) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_provider';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_provider';
var data = {
csrfToken: GlobalVariables.csrfToken,
provider_id: id
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.provider_deleted);
this.resetForm();
this.filter($('#filter-providers .key').val());
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function () {
Backend.displayNotification(EALang.provider_deleted);
this.resetForm();
this.filter($('#filter-providers .key').val());
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -456,10 +454,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-providers .results').html('');

View file

@ -207,21 +207,20 @@
* then the update operation is going to be executed.
*/
SecretariesHelper.prototype.save = function (secretary) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary';
var data = {
csrfToken: GlobalVariables.csrfToken,
secretary: JSON.stringify(secretary)
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.secretary_saved);
this.resetForm();
$('#filter-secretaries .key').val('');
this.filter('', response.id, true);
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function (response) {
Backend.displayNotification(EALang.secretary_saved);
this.resetForm();
$('#filter-secretaries .key').val('');
this.filter('', response.id, true);
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -230,20 +229,19 @@
* @param {Number} id Record id to be deleted.
*/
SecretariesHelper.prototype.delete = function (id) {
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary';
var data = {
csrfToken: GlobalVariables.csrfToken,
secretary_id: id
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
Backend.displayNotification(EALang.secretary_deleted);
this.resetForm();
this.filter($('#filter-secretaries .key').val());
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
.done(function () {
Backend.displayNotification(EALang.secretary_deleted);
this.resetForm();
this.filter($('#filter-secretaries .key').val());
}.bind(this))
.fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -381,10 +379,6 @@
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
this.filterResults = response;
$('#filter-secretaries .results').html('');

View file

@ -61,10 +61,6 @@ window.FrontendBookApi = window.FrontendBookApi || {};
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
// The response contains the available hours for the selected provider and
// service. Fill the available hours div with response data.
if (response.length > 0) {
@ -181,11 +177,6 @@ window.FrontendBookApi = window.FrontendBookApi || {};
}
})
.done(function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
$('.captcha-title small').trigger('click');
return false;
}
if (response.captcha_verification === false) {
$('#captcha-hint')
.text(EALang.captcha_is_wrong)
@ -308,11 +299,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
consent: consent
};
$.post(url, data, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data).fail(GeneralFunctions.ajaxFailureHandler);
};
/**
@ -328,10 +315,6 @@ window.FrontendBookApi = window.FrontendBookApi || {};
};
$.post(url, data, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
location.href = GlobalVariables.baseUrl;
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
};

View file

@ -22,14 +22,6 @@ window.GeneralFunctions = window.GeneralFunctions || {};
'use strict';
/**
* General Functions Constants
*/
exports.EXCEPTIONS_TITLE = EALang.unexpected_issues;
exports.EXCEPTIONS_MESSAGE = EALang.unexpected_issues_message;
exports.WARNINGS_TITLE = EALang.unexpected_warnings;
exports.WARNINGS_MESSAGE = EALang.unexpected_warnings_message;
/**
* This functions displays a message box in the admin array. It is useful when user
* decisions or verifications are needed.
@ -39,16 +31,15 @@ window.GeneralFunctions = window.GeneralFunctions || {};
* @param {Array} buttons Contains the dialog buttons along with their functions.
*/
exports.displayMessageBox = function (title, message, buttons) {
// Check arguments integrity.
if (title == undefined || title == '') {
title = '<No Title Given>';
if (title === undefined || title === '') {
title = '- No Title Provided -';
}
if (message == undefined || message == '') {
message = '<No Message Given>';
if (message === undefined || message === '') {
message = '- No Message Provided -';
}
if (buttons == undefined) {
if (buttons === undefined) {
buttons = [
{
text: EALang.close,
@ -61,15 +52,21 @@ window.GeneralFunctions = window.GeneralFunctions || {};
}
// Destroy previous dialog instances.
$('#message_box').dialog('destroy');
$('#message_box').remove();
$('#message_box')
.dialog('destroy')
.remove();
// Create the html of the message box.
$('body').append(
'<div id="message_box" title="' + title + '">' +
'<p>' + message + '</p>' +
'</div>'
);
$('<div/>', {
'id': 'message_box',
'title': title,
'html': [
$('<p/>', {
'html': message
})
]
})
.appendTo('body');
$("#message_box").dialog({
autoOpen: false,
@ -97,7 +94,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$(window).resize(function () {
var elementLeft = ($(window).width() - elementHandle.outerWidth()) / 2;
var elementTop = ($(window).height() - elementHandle.outerHeight()) / 2;
elementTop = (elementTop > 0) ? elementTop : 20;
elementTop = elementTop > 0 ? elementTop : 20;
elementHandle.css({
position: 'absolute',
@ -111,10 +108,10 @@ window.GeneralFunctions = window.GeneralFunctions || {};
/**
* This function retrieves a parameter from a "GET" formed url.
*
* {@link http://www.netlobo.com/url_query_string_javascript.html}
* @link http://www.netlobo.com/url_query_string_javascript.html
*
* @param {String} url The selected url.
* @param {String} name The parameter name.
* @param {String} parameterName The parameter name.
* @return {String} Returns the parameter value.
*/
@ -162,10 +159,10 @@ window.GeneralFunctions = window.GeneralFunctions || {};
/**
* Clone JS Object
*
* This method creates and returns an exact copy of the provided object. It is very useful whenever
* changes need to be made to an object without modifying the original data.
* This method creates and returns an exact copy of the provided object. It is very useful whenever changes need to
* be made to an object without modifying the original data.
*
* {@link http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object}
* @link https://stackoverflow.com/a/728694
*
* @param {Object} originalObject Object to be copied.
@ -211,7 +208,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
* This method validates an email address. If the address is not on the proper
* form then the result is FALSE.
*
* {@link http://badsyntax.co/post/javascript-email-validation-rfc822}
* @link http://badsyntax.co/post/javascript-email-validation-rfc822
*
* @param {String} email The email address to be checked.
@ -258,87 +255,42 @@ window.GeneralFunctions = window.GeneralFunctions || {};
return html;
};
/**
* Parse AJAX Exceptions
*
* This method parse the JSON encoded strings that are fetched by AJAX calls.
*
* @param {Array} exceptions Exception array returned by an ajax call.
*
* @return {Array} Returns the parsed js objects.
*/
exports.parseExceptions = function (exceptions) {
var parsedExceptions = new Array();
$.each(exceptions, function (index, exception) {
parsedExceptions.push($.parseJSON(exception));
});
return parsedExceptions;
};
/**
* Makes the first letter of the string upper case.
*
* @param {String} str The string to be converted.
* @param {String} value The string to be converted.
*
* @return {String} Returns the capitalized string.
*/
exports.ucaseFirstLetter = function (str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
/**
* Handle AJAX Exceptions Callback
*
* All backend js code has the same way of dislaying exceptions that are raised on the
* server during an ajax call.
*
* @param {Object} response Contains the server response. If exceptions or warnings are
* found, user friendly messages are going to be displayed to the user.4
*
* @return {Boolean} Returns whether the the ajax callback should continue the execution or
* stop, due to critical server exceptions.
*/
exports.handleAjaxExceptions = function (response) {
if (response.exceptions) {
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
return false;
}
if (response.warnings) {
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
}
return true;
exports.upperCaseFirstLetter = function (value) {
return value.charAt(0).toUpperCase() + value.slice(1);
};
/**
* Enable Language Selection
*
* Enables the language selection functionality. Must be called on every page has a
* language selection button. This method requires the global variable 'availableLanguages'
* to be initialized before the execution.
* Enables the language selection functionality. Must be called on every page has a language selection button.
* This method requires the global variable 'availableLanguages' to be initialized before the execution.
*
* @param {Object} $element Selected element button for the language selection.
*/
exports.enableLanguageSelection = function ($element) {
// Select Language
var html = '<ul id="language-list">';
$.each(availableLanguages, function () {
html += '<li class="language" data-language="' + this + '">'
+ GeneralFunctions.ucaseFirstLetter(this) + '</li>';
var $languageList = $('<ul/>', {
'id': 'language-list',
'html': availableLanguages.map(function (availableLanguage) {
return $('<li/>', {
'class': 'language',
'data-language': availableLanguage,
'text': GeneralFunctions.upperCaseFirstLetter(availableLanguage)
})
})
});
html += '</ul>';
$element.popover({
placement: 'top',
title: 'Select Language',
content: html,
content: $languageList.html(),
html: true,
container: 'body',
trigger: 'manual'
@ -356,55 +308,60 @@ window.GeneralFunctions = window.GeneralFunctions || {};
$(document).on('click', 'li.language', function () {
// Change language with ajax call and refresh page.
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_change_language';
var postData = {
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_change_language';
var data = {
csrfToken: GlobalVariables.csrfToken,
language: $(this).attr('data-language')
};
$.post(postUrl, postData, function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
document.location.reload(true);
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
$.post(url, data)
done(function () {
document.location.reload(true);
})
.fail(GeneralFunctions.ajaxFailureHandler);
});
};
/**
* AJAX Failure Handler
*
* @param {jqXHR} jqxhr
* @param {jqXHR} jqXHR
* @param {String} textStatus
* @param {Object} errorThrown
*/
exports.ajaxFailureHandler = function (jqxhr, textStatus, errorThrown) {
var exceptions = [
{
message: 'AJAX Error: ' + errorThrown + $(jqxhr.responseText).text()
}
];
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
$('#message_box').append(GeneralFunctions.exceptionsToHtml(exceptions));
exports.ajaxFailureHandler = function (jqXHR, textStatus, errorThrown) {
console.error('Unexpected HTTP Error: ', jqXHR, textStatus, errorThrown);
var response = JSON.parse(jqXHR.responseText);
if (!response) {
return;
}
GeneralFunctions.displayMessageBox(EALang.unexpected_issues, EALang.unexpected_issues_message, []);
$('<div/>', {
'class': 'well',
'text': response.message
})
.appendTo('#message_box');
};
/**
* Escape JS HTML string values for XSS prevention.
*
* @param {String} str String to be escaped.
* @param {String} content String to be escaped.
*
* @return {String} Returns the escaped string.
*/
exports.escapeHtml = function (str) {
return $('<div/>').text(str).html();
exports.escapeHtml = function (content) {
return $('<div/>').text(content).html();
};
/**
* Format a given date according to the date format setting.
*
* @param {Date} date The date to be formatted.
* @param {String} dateFormatSetting The setting provided by PHP must be one of
* the "DMY", "MDY" or "YMD".
* @param {String} dateFormatSetting The setting provided by PHP must be one of the "DMY", "MDY" or "YMD".
* @param {Boolean} addHours (optional) Whether to add hours to the result.
* @return {String} Returns the formatted date string.
@ -431,79 +388,15 @@ 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
* Get the Id of a Weekday using the US week format and day names (Sunday=0) as used in the JS code of the
* application, case insensitive, short and long names supported.
*
* @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).
* @param {String} weekDayName The weekday name among Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
* 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;
};
/**
* Get the Id of a Weekday using the US week format and day names (Sunday=0) as used in the JS code of the appli, case insensitive, short and long names supported.
*
* @param {String} weekDayName The weekday name amongs Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.
* @return {Integer} Returns the ID of the weekday.
* @return {Number} Returns the ID of the weekday.
*/
exports.getWeekDayId = function (weekDayName) {
var result;
@ -555,11 +448,11 @@ window.GeneralFunctions = window.GeneralFunctions || {};
/**
* Get the name in lowercase of a Weekday using its Id.
*
* @param {Integer} weekDayId The Id (From 0 for sunday to 6 for saturday).
* @param {Number} weekDayId The Id (From 0 for sunday to 6 for saturday).
* @return {String} Returns the name of the weekday.
*/
exports.getWeekDayName = function (weekDayId) {
exports.getWeekdayName = function (weekDayId) {
var result;
switch (weekDayId) {
@ -602,21 +495,20 @@ window.GeneralFunctions = window.GeneralFunctions || {};
/**
* 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).
* @param {Object} weekDictionary A dictionary with weekdays as keys.
* @param {Number} 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={};
exports.sortWeekDictionary = function (weekDictionary, startDayId) {
var sortedWeekDictionary={};
for (var i = startDayId; i < startDayId+7; i++)
{
var weekDayname = GeneralFunctions.getWeekDayName(i%7);
sortedWeekDict[weekDayname] = weekDict[weekDayname];
for (var i = startDayId; i < startDayId+7; i++) {
var weekdayName = GeneralFunctions.getWeekdayName(i % 7);
sortedWeekDictionary[weekdayName] = weekDictionary[weekdayName];
}
return sortedWeekDict;
return sortedWeekDictionary;
};
/**
@ -624,7 +516,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
*
* @param {Object} user Should have the address, city, etc properties.
*
* @returns {string} The rendered HTML.
* @return {string} The rendered HTML.
*/
exports.renderMapIcon = function (user) {
var data = [];
@ -670,7 +562,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
*
* @param {String} email
*
* @returns {string} The rendered HTML.
* @return {string} The rendered HTML.
*/
exports.renderMailIcon = function (email) {
return $('<div/>', {
@ -694,7 +586,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
*
* @param {String} phone
*
* @returns {string} The rendered HTML.
* @return {string} The rendered HTML.
*/
exports.renderPhoneIcon = function (phone) {
return $('<div/>', {
@ -712,19 +604,20 @@ window.GeneralFunctions = window.GeneralFunctions || {};
})
.html();
};
/**
* Format a given date according to ISO 8601 date format string yyyy-mm-dd
*
* @param {String} date The date to be formatted.
* @param {String} dateFormatSetting The setting provided by PHP must be one of
* the "DMY", "MDY" or "YMD".
* @returns {String} Returns the formatted date string.
* @param {String} dateFormatSetting The setting provided by PHP must be one of the "DMY", "MDY" or "YMD".
*
* @return {String} Returns the formatted date string.
*/
exports.ISO8601DateString = function (date, dateFormatSetting) {
var dayArray;
// It's necessary to manually parse the date because Date.parse() not support
// some formats tha instead are supported by Easy!Appointments
// The unsupported format is dd/MM/yyyy
// It's necessary to manually parse the date because Date.parse() not support some formats tha instead are
// supported by Easy!Appointments. The unsupported format is dd/MM/yyyy.
switch (dateFormatSetting) {
case 'DMY':
dayArray = date.split('/');
@ -738,7 +631,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
date = date.replace('/','-');
break;
default:
throw new Error('Invalid date format setting provided!', dateFormatSetting);
throw new Error('Invalid date format setting provided:' + dateFormatSetting);
}
return date;
}

View file

@ -46,10 +46,6 @@ $(function () {
dataType: 'json'
})
.done(function (response) {
if (!GeneralFunctions.handleAjaxExceptions(response)) {
return;
}
$alert
.text('Easy!Appointments has been successfully installed!')
.addClass('alert-success')
@ -67,7 +63,7 @@ $(function () {
*
* Use this before executing the installation procedure.
*
* @returns {Boolean} Returns the validation result.
* @return {Boolean} Returns the validation result.
*/
function validate() {
try {

View file

@ -46,7 +46,7 @@
*/
WorkingPlan.prototype.setup = function (workingPlan) {
var fDaynum = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
var workingPlanSorted = GeneralFunctions.sortWeekDict(workingPlan,fDaynum);
var workingPlanSorted = GeneralFunctions.sortWeekDictionary(workingPlan,fDaynum);
$('.working-plan tbody').empty();
$('.breaks tbody').empty();
@ -55,13 +55,13 @@
$.each(workingPlanSorted, function (index, workingDay) {
var day = this.convertValueToDay(index);
var dayTranslatedname = GeneralFunctions.ucaseFirstLetter(day)
var dayTranslatedName = GeneralFunctions.upperCaseFirstLetter(day)
var tr =
'<tr>' +
'<td>' +
'<div class="checkbox">' +
'<label> <input type="checkbox" id="' + index + '">' + dayTranslatedname + '</label>' +
'<label> <input type="checkbox" id="' + index + '">' + dayTranslatedName + '</label>' +
'</div>' +
'</td>' +
'<td><input id="'+index+'-start" class="work-start form-control input-sm"></td>' +
@ -86,7 +86,7 @@
tr =
'<tr>' +
'<td class="break-day editable">' + dayTranslatedname + '</td>' +
'<td class="break-day editable">' + dayTranslatedName + '</td>' +
'<td class="break-start editable">' + Date.parse(brk.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase() + '</td>' +
'<td class="break-end editable">' + Date.parse(brk.end).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase() + '</td>' +
'<td>' +