mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 14:42:23 +03:00
Performed major javascript refactoring for more consistncy and efficiency in the code base (work in progress)
This commit is contained in:
parent
466a3a3c20
commit
c670c023a7
24 changed files with 1168 additions and 1057 deletions
|
@ -29,39 +29,37 @@ window.BackendCalendar = window.BackendCalendar || {};
|
|||
var $calendarPage = $('#calendar-page');
|
||||
|
||||
$calendarPage.on('click', '#toggle-fullscreen', function () {
|
||||
var $target = $(this);
|
||||
var $toggleFullscreen = $(this);
|
||||
var element = document.documentElement;
|
||||
var isFullScreen = (document.fullScreenElement && document.fullScreenElement !== null)
|
||||
|| document.mozFullScreen
|
||||
|| document.webkitIsFullScreen;
|
||||
var isFullScreen = document.fullScreenElement || document.mozFullScreen || document.webkitIsFullScreen;
|
||||
|
||||
if (isFullScreen) {
|
||||
// Exit fullscreen mode.
|
||||
if (document.exitFullscreen)
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
else if (document.msExitFullscreen)
|
||||
} else if (document.msExitFullscreen) {
|
||||
document.msExitFullscreen();
|
||||
else if (document.mozCancelFullScreen)
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
document.mozCancelFullScreen();
|
||||
else if (document.webkitExitFullscreen)
|
||||
} else if (document.webkitExitFullscreen) {
|
||||
document.webkitExitFullscreen();
|
||||
}
|
||||
|
||||
$target
|
||||
$toggleFullscreen
|
||||
.removeClass('btn-success')
|
||||
.addClass('btn-default');
|
||||
|
||||
} else {
|
||||
// Switch to fullscreen mode.
|
||||
if (element.requestFullscreen)
|
||||
if (element.requestFullscreen) {
|
||||
element.requestFullscreen();
|
||||
else if (element.msRequestFullscreen)
|
||||
} else if (element.msRequestFullscreen) {
|
||||
element.msRequestFullscreen();
|
||||
else if (element.mozRequestFullScreen)
|
||||
} else if (element.mozRequestFullScreen) {
|
||||
element.mozRequestFullScreen();
|
||||
else if (element.webkitRequestFullscreen)
|
||||
} else if (element.webkitRequestFullscreen) {
|
||||
element.webkitRequestFullscreen();
|
||||
|
||||
$target
|
||||
}
|
||||
$toggleFullscreen
|
||||
.removeClass('btn-default')
|
||||
.addClass('btn-success');
|
||||
}
|
||||
|
|
|
@ -29,34 +29,30 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
|
|||
*
|
||||
* @param {Object} appointment Contain the new appointment data. The ID of the appointment MUST be
|
||||
* already included. The rest values must follow the database structure.
|
||||
* @param {Object} customer Optional, contains the customer data.
|
||||
* @param {Function} successCallback Optional, if defined, this function is going to be executed on post success.
|
||||
* @param {Function} errorCallback Optional, if defined, this function is going to be executed on post failure.
|
||||
* @param {Object} [customer] Optional, contains the customer data.
|
||||
* @param {Function} [successCallback] Optional, if defined, this function is going to be executed on post success.
|
||||
* @param {Function} [errorCallback] Optional, if defined, this function is going to be executed on post failure.
|
||||
*/
|
||||
exports.saveAppointment = function (appointment, customer, successCallback, errorCallback) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
if (customer !== undefined) {
|
||||
if (customer) {
|
||||
data.customer_data = JSON.stringify(customer);
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
dataType: 'json'
|
||||
})
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
if (successCallback !== undefined) {
|
||||
if (successCallback) {
|
||||
successCallback(response);
|
||||
}
|
||||
})
|
||||
.fail(function (jqXHR, textStatus, errorThrown) {
|
||||
if (errorCallback !== undefined) {
|
||||
if (errorCallback) {
|
||||
errorCallback();
|
||||
}
|
||||
});
|
||||
|
@ -70,19 +66,16 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
|
|||
* @param {Function} errorCallback The ajax failure callback function.
|
||||
*/
|
||||
exports.saveUnavailable = function (unavailable, successCallback, errorCallback) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable: JSON.stringify(unavailable)
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: postUrl,
|
||||
data: postData,
|
||||
success: successCallback,
|
||||
error: errorCallback
|
||||
});
|
||||
$.post(url, data)
|
||||
.done(successCallback)
|
||||
.fail(errorCallback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -92,19 +85,16 @@ window.BackendCalendarApi = window.BackendCalendarApi || {};
|
|||
* @param {Function} errorCallback The ajax failure callback function.
|
||||
*/
|
||||
exports.saveExtraPeriod = function (extra_periods, successCallback, errorCallback) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_extra_period';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_extra_period';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
extra_period: JSON.stringify(extra_periods)
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: postUrl,
|
||||
data: postData,
|
||||
success: successCallback,
|
||||
error: errorCallback
|
||||
});
|
||||
$.post(url, data)
|
||||
.done(successCallback)
|
||||
.fail(errorCallback);
|
||||
}
|
||||
|
||||
})(window.BackendCalendarApi);
|
||||
|
|
|
@ -26,7 +26,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
var providerId = $('#select-provider').val();
|
||||
|
||||
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
|
||||
return availableProvider.id == providerId;
|
||||
return Number(availableProvider.id) === Number(providerId);
|
||||
}).shift();
|
||||
|
||||
if (provider && provider.timezone) {
|
||||
|
@ -129,11 +129,11 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
var $dialog = $('#manage-appointment');
|
||||
|
||||
// Set the selected filter item and find the next appointment time as the default modal values.
|
||||
if ($('#select-filter-item option:selected').attr('type') == 'provider') {
|
||||
if ($('#select-filter-item option:selected').attr('type') === 'provider') {
|
||||
var providerId = $('#select-filter-item').val();
|
||||
|
||||
var providers = GlobalVariables.availableProviders.filter(function (provider) {
|
||||
return provider.id == providerId;
|
||||
return Number(provider.id) === Number(providerId);
|
||||
});
|
||||
|
||||
if (providers.length) {
|
||||
|
@ -147,7 +147,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
|
||||
var serviceDuration = 0;
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (service.id == $dialog.find('#select-service').val()) {
|
||||
if (Number(service.id) === Number($dialog.find('#select-service').val())) {
|
||||
serviceDuration = service.duration;
|
||||
return false; // exit loop
|
||||
}
|
||||
|
@ -204,17 +204,17 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
$('#manage-appointment').on('click', '#existing-customers-list div', function () {
|
||||
var id = $(this).attr('data-id');
|
||||
|
||||
$.each(GlobalVariables.customers, function (index, c) {
|
||||
if (c.id == id) {
|
||||
$('#customer-id').val(c.id);
|
||||
$('#first-name').val(c.first_name);
|
||||
$('#last-name').val(c.last_name);
|
||||
$('#email').val(c.email);
|
||||
$('#phone-number').val(c.phone_number);
|
||||
$('#address').val(c.address);
|
||||
$('#city').val(c.city);
|
||||
$('#zip-code').val(c.zip_code);
|
||||
$('#customer-notes').val(c.notes);
|
||||
$.each(GlobalVariables.customers, function (index, customer) {
|
||||
if (Number(customer.id) === Number(id)) {
|
||||
$('#customer-id').val(customer.id);
|
||||
$('#first-name').val(customer.first_name);
|
||||
$('#last-name').val(customer.last_name);
|
||||
$('#email').val(customer.email);
|
||||
$('#phone-number').val(customer.phone_number);
|
||||
$('#address').val(customer.address);
|
||||
$('#city').val(customer.city);
|
||||
$('#zip-code').val(customer.zip_code);
|
||||
$('#customer-notes').val(customer.notes);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
@ -228,56 +228,52 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
$('#filter-existing-customers').keyup(function () {
|
||||
var key = $(this).val().toLowerCase();
|
||||
var $list = $('#existing-customers-list');
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
||||
var postData = {
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key
|
||||
};
|
||||
|
||||
// Try to get the updated customer list.
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: postUrl,
|
||||
data: postData,
|
||||
dataType: 'json',
|
||||
timeout: 1000,
|
||||
global: false,
|
||||
success: function (response) {
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
$list.empty();
|
||||
$.each(response, function (index, c) {
|
||||
$list.append('<div data-id="' + c.id + '">'
|
||||
+ c.first_name + ' ' + c.last_name + '</div>');
|
||||
|
||||
response.forEach(function (customer, index) {
|
||||
$list.append('<div data-id="' + customer.id + '">'
|
||||
+ customer.first_name + ' ' + customer.last_name + '</div>');
|
||||
|
||||
// Verify if this customer is on the old customer list.
|
||||
var result = $.grep(GlobalVariables.customers,
|
||||
function (e) {
|
||||
return e.id == c.id;
|
||||
});
|
||||
var result = GlobalVariables.customers.filter(function(globalVariablesCustomer) {
|
||||
return Number(globalVariablesCustomer.id) === Number(customer.id);
|
||||
});
|
||||
|
||||
// Add it to the customer list.
|
||||
if (result.length == 0) {
|
||||
GlobalVariables.customers.push(c);
|
||||
if (!result.length) {
|
||||
GlobalVariables.customers.push(customer);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
})
|
||||
})
|
||||
.fail(function (jqXHR, textStatus, errorThrown) {
|
||||
// If there is any error on the request, search by the local client database.
|
||||
$list.empty();
|
||||
$.each(GlobalVariables.customers, function (index, c) {
|
||||
if (c.first_name.toLowerCase().indexOf(key) != -1
|
||||
|| c.last_name.toLowerCase().indexOf(key) != -1
|
||||
|| c.email.toLowerCase().indexOf(key) != -1
|
||||
|| c.phone_number.toLowerCase().indexOf(key) != -1
|
||||
|| c.address.toLowerCase().indexOf(key) != -1
|
||||
|| c.city.toLowerCase().indexOf(key) != -1
|
||||
|| c.zip_code.toLowerCase().indexOf(key) != -1
|
||||
|| c.notes.toLowerCase().indexOf(key) != -1) {
|
||||
$list.append('<div data-id="' + c.id + '">'
|
||||
+ c.first_name + ' ' + c.last_name + '</div>');
|
||||
|
||||
GlobalVariables.customers.forEach(function(customer, index) {
|
||||
if (customer.first_name.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.last_name.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.email.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.phone_number.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.address.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.city.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.zip_code.toLowerCase().indexOf(key) !== -1
|
||||
|| customer.notes.toLowerCase().indexOf(key) !== -1) {
|
||||
$list.append('<div data-id="' + customer.id + '">'
|
||||
+ customer.first_name + ' ' + customer.last_name + '</div>');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -287,22 +283,22 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
* update the start and end time of the appointment.
|
||||
*/
|
||||
$('#select-service').change(function () {
|
||||
var sid = $('#select-service').val();
|
||||
var serviceId = $('#select-service').val();
|
||||
$('#select-provider').empty();
|
||||
|
||||
// Automatically update the service duration.
|
||||
$.each(GlobalVariables.availableServices, function (indexService, service) {
|
||||
if (service.id == sid) {
|
||||
$.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() + service.duration * 60000));
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + availableService.duration * 60000));
|
||||
return false; // break loop
|
||||
}
|
||||
});
|
||||
|
||||
// Update the providers select box.
|
||||
$.each(GlobalVariables.availableProviders, function (indexProvider, provider) {
|
||||
$.each(provider.services, function (indexService, serviceId) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && parseInt(provider.id) !== GlobalVariables.user.id) {
|
||||
$.each(provider.services, function (indexService, providerServiceId) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && Number(provider.id) !== GlobalVariables.user.id) {
|
||||
return true; // continue
|
||||
}
|
||||
|
||||
|
@ -311,7 +307,7 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
}
|
||||
|
||||
// If the current provider is able to provide the selected service, add him to the listbox.
|
||||
if (serviceId == sid) {
|
||||
if (Number(providerServiceId) === Number(serviceId)) {
|
||||
var optionHtml = '<option value="' + provider.id + '">'
|
||||
+ provider.first_name + ' ' + provider.last_name
|
||||
+ '</option>';
|
||||
|
@ -360,8 +356,10 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
var canProvideService = false;
|
||||
|
||||
$.each(provider.services, function (index, serviceId) {
|
||||
if (serviceId == $dialog.find('#select-service').val()) {
|
||||
var serviceId = $dialog.find('#select-service').val();
|
||||
|
||||
$.each(provider.services, function (index, providerServiceId) {
|
||||
if (Number(providerServiceId) === Number(serviceId)) {
|
||||
canProvideService = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -381,9 +379,10 @@ 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 (service.id == $dialog.find('#select-service').val()) {
|
||||
if (Number(service.id) === Number(serviceId)) {
|
||||
serviceDuration = service.duration;
|
||||
return false;
|
||||
}
|
||||
|
@ -438,13 +437,13 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
minuteText: EALang.minutes,
|
||||
firstDay: firstWeekDayNumber,
|
||||
onClose: function () {
|
||||
var sid = $('#select-service').val();
|
||||
var serviceId = $('#select-service').val();
|
||||
|
||||
// Automatically update the #end-datetime DateTimePicker based on service duration.
|
||||
$.each(GlobalVariables.availableServices, function (indexService, service) {
|
||||
if (service.id == sid) {
|
||||
$.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() + service.duration * 60000));
|
||||
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + availableService.duration * 60000));
|
||||
return false; // break loop
|
||||
}
|
||||
});
|
||||
|
@ -501,20 +500,20 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
var missingRequiredField = false;
|
||||
|
||||
$dialog.find('.required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == null) {
|
||||
if ($(this).val() === '' || $(this).val() === null) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequiredField = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequiredField) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
// Check email address.
|
||||
if (!GeneralFunctions.validateEmail($dialog.find('#email').val())) {
|
||||
$dialog.find('#email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
// Check appointment start and end time.
|
||||
|
@ -522,12 +521,12 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
|||
var end = $('#end-datetime').datetimepicker('getDate');
|
||||
if (start > end) {
|
||||
$dialog.find('#start-datetime, #end-datetime').closest('.form-group').addClass('has-error');
|
||||
throw EALang.start_date_before_end_error;
|
||||
throw new Error(EALang.start_date_before_end_error);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (exc) {
|
||||
$dialog.find('.modal-message').addClass('alert-danger').text(exc).removeClass('hidden');
|
||||
} catch (error) {
|
||||
$dialog.find('.modal-message').addClass('alert-danger').text(error.message).removeClass('hidden');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
|
||||
var $dialog;
|
||||
|
||||
if (lastFocusedEventData.data.is_unavailable == false) {
|
||||
if (lastFocusedEventData.data.is_unavailable === '0') {
|
||||
var appointment = lastFocusedEventData.data;
|
||||
$dialog = $('#manage-appointment');
|
||||
|
||||
|
@ -132,45 +132,54 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$calendarPage.on('click', '.delete-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover.
|
||||
|
||||
var url;
|
||||
var data;
|
||||
|
||||
// If id_role parameter exists the popover is an extra working day.
|
||||
if (lastFocusedEventData.data.hasOwnProperty('id_roles')) {
|
||||
// Do not display confirmation prompt.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
extra_period: lastFocusedEventData.start.format('YYYY-MM-DD'),
|
||||
provider_id: lastFocusedEventData.data.id
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
else if (lastFocusedEventData.data.is_unavailable == false) {
|
||||
else if (lastFocusedEventData.data.is_unavailable === '0') {
|
||||
var buttons = [
|
||||
{
|
||||
text: 'OK',
|
||||
click: function () {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
appointment_id: lastFocusedEventData.data.id,
|
||||
delete_reason: $('#delete-reason').val()
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -189,18 +198,21 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$('#delete-reason').css('width', '100%');
|
||||
} else {
|
||||
// Do not display confirmation prompt.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable_id: lastFocusedEventData.data.id
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -223,7 +235,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
var providerId = $('#select-filter-item').val();
|
||||
|
||||
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
|
||||
return availableProvider.id == providerId;
|
||||
return Number(availableProvider.id) === Number(providerId);
|
||||
}).shift();
|
||||
|
||||
if (provider && provider.timezone) {
|
||||
|
@ -278,10 +290,10 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
|
||||
if ($(this).hasClass('fc-unavailable') || $parent.hasClass('fc-unavailable') || $altParent.hasClass('fc-unavailable')) {
|
||||
displayEdit = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.edit == true)
|
||||
&& GlobalVariables.user.privileges.appointments.edit === true)
|
||||
? '' : 'hide';
|
||||
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.delete == true)
|
||||
&& GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide'; // Same value at the time.
|
||||
|
||||
var notes = '';
|
||||
|
@ -309,7 +321,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
'</center>';
|
||||
} else if ($(this).hasClass('fc-extra') || $parent.hasClass('fc-extra') || $altParent.hasClass('fc-extra')) {
|
||||
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.delete == true)
|
||||
&& GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide'; // Same value at the time.
|
||||
|
||||
var provider = '';
|
||||
|
@ -341,9 +353,9 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
'</center>';
|
||||
|
||||
} else {
|
||||
displayEdit = (GlobalVariables.user.privileges.appointments.edit == true)
|
||||
displayEdit = (GlobalVariables.user.privileges.appointments.edit === true)
|
||||
? '' : 'hide';
|
||||
displayDelete = (GlobalVariables.user.privileges.appointments.delete == true)
|
||||
displayDelete = (GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide';
|
||||
|
||||
html =
|
||||
|
@ -416,7 +428,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* @see updateAppointmentData()
|
||||
*/
|
||||
function _calendarEventResize(event, delta, revertFunc, jsEvent, ui, view) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
||||
revertFunc();
|
||||
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
||||
return;
|
||||
|
@ -428,7 +440,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$('#notification').hide('bind');
|
||||
}
|
||||
|
||||
if (event.data.is_unavailable == false) {
|
||||
if (event.data.is_unavailable === false) {
|
||||
// Prepare appointment data.
|
||||
event.data.end_datetime = Date.parseExact(
|
||||
event.data.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
||||
|
@ -458,10 +470,12 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.appointment_updated, [
|
||||
|
@ -477,7 +491,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
};
|
||||
|
||||
// Update appointment data.
|
||||
BackendCalendarApi.saveAppointment(appointment, undefined, successCallback);
|
||||
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
||||
} else {
|
||||
// Update unavailable time period.
|
||||
var unavailable = {
|
||||
|
@ -499,15 +513,18 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
.toString('yyyy-MM-dd HH:mm:ss');
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable: JSON.stringify(unavailable)
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.unavailable_updated, [
|
||||
|
@ -559,7 +576,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
* on the calendar. We need to update the database with this change. This is done via an ajax call.
|
||||
*/
|
||||
function _calendarEventDrop(event, delta, revertFunc, jsEvent, ui, view) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
||||
revertFunc();
|
||||
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
||||
return;
|
||||
|
@ -569,7 +586,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$('#notification').hide('bind');
|
||||
}
|
||||
|
||||
if (event.data.is_unavailable == false) {
|
||||
if (event.data.is_unavailable === '0') {
|
||||
// Prepare appointment data.
|
||||
var appointment = GeneralFunctions.clone(event.data);
|
||||
|
||||
|
@ -609,15 +626,18 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
event.data.end_datetime = appointment.end_datetime;
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.appointment_updated, [
|
||||
|
@ -631,7 +651,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
};
|
||||
|
||||
// Update appointment data.
|
||||
BackendCalendarApi.saveAppointment(appointment, undefined, successCallback);
|
||||
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
||||
} else {
|
||||
// Update unavailable time period.
|
||||
var unavailable = {
|
||||
|
@ -662,10 +682,12 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
unavailable: JSON.stringify(unavailable)
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.unavailable_updated, [
|
||||
|
@ -744,6 +766,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
*/
|
||||
function _refreshCalendarAppointments($calendar, recordId, filterType, startDate, endDate) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_calendar_appointments';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
record_id: recordId,
|
||||
|
@ -752,232 +775,95 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
filter_type: filterType
|
||||
};
|
||||
|
||||
|
||||
$('#loading').css('visibility', 'hidden');
|
||||
|
||||
return $.post(url, data, function (response) {
|
||||
// Add appointments to calendar.
|
||||
var calendarEvents = [];
|
||||
var $calendar = $('#calendar');
|
||||
return $.post(url, data)
|
||||
.done(function (response) {
|
||||
// Add appointments to calendar.
|
||||
var calendarEvents = [];
|
||||
var $calendar = $('#calendar');
|
||||
|
||||
$.each(response.appointments, function (index, appointment) {
|
||||
var event = {
|
||||
id: appointment.id,
|
||||
title: appointment.service.name + ' - '
|
||||
+ appointment.customer.first_name + ' '
|
||||
+ appointment.customer.last_name,
|
||||
start: moment(appointment.start_datetime),
|
||||
end: moment(appointment.end_datetime),
|
||||
allDay: false,
|
||||
data: appointment // Store appointment data for later use.
|
||||
};
|
||||
$.each(response.appointments, function (index, appointment) {
|
||||
var event = {
|
||||
id: appointment.id,
|
||||
title: appointment.service.name + ' - '
|
||||
+ appointment.customer.first_name + ' '
|
||||
+ appointment.customer.last_name,
|
||||
start: moment(appointment.start_datetime),
|
||||
end: moment(appointment.end_datetime),
|
||||
allDay: false,
|
||||
data: appointment // Store appointment data for later use.
|
||||
};
|
||||
|
||||
calendarEvents.push(event);
|
||||
});
|
||||
calendarEvents.push(event);
|
||||
});
|
||||
|
||||
$calendar.fullCalendar('removeEvents');
|
||||
$calendar.fullCalendar('addEventSource', calendarEvents);
|
||||
$calendar.fullCalendar('removeEvents');
|
||||
$calendar.fullCalendar('addEventSource', calendarEvents);
|
||||
|
||||
var weekDays = [
|
||||
'sunday',
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday'
|
||||
];
|
||||
var weekDays = [
|
||||
'sunday',
|
||||
'monday',
|
||||
'tuesday',
|
||||
'wednesday',
|
||||
'thursday',
|
||||
'friday',
|
||||
'saturday'
|
||||
];
|
||||
|
||||
// :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS
|
||||
var calendarView = $calendar.fullCalendar('getView').name;
|
||||
// :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS
|
||||
var calendarView = $calendar.fullCalendar('getView').name;
|
||||
|
||||
if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
if (provider.id == recordId) {
|
||||
var workingPlan={};
|
||||
var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan);
|
||||
var extraWorkingPlan = jQuery.parseJSON(provider.settings.extra_working_plan);
|
||||
var unavailablePeriod;
|
||||
if (filterType === FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
||||
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
||||
if (Number(provider.id) === Number(recordId)) {
|
||||
var workingPlan={};
|
||||
var workingPlanBulk = jQuery.parseJSON(provider.settings.working_plan);
|
||||
var extraWorkingPlan = jQuery.parseJSON(provider.settings.extra_working_plan);
|
||||
var unavailablePeriod;
|
||||
|
||||
// Sort the working plan starting with the first day as set in General settings to correctly
|
||||
// align breaks in the calendar display.
|
||||
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(GlobalVariables.firstWeekday);
|
||||
workingPlan = GeneralFunctions.sortWeekDictionary(workingPlanBulk, firstWeekdayNumber);
|
||||
// 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')));
|
||||
switch (calendarView) {
|
||||
case 'agendaDay':
|
||||
var selectedDayName = GeneralFunctions
|
||||
.getWeekdayName(parseInt($calendar.fullCalendar('getView').start.format('d')));
|
||||
|
||||
// Add custom unavailable periods.
|
||||
$.each(response.unavailables, function (index, unavailable) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
// Add custom unavailable periods.
|
||||
$.each(response.unavailables, function (index, unavailable) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
|
||||
if (unavailable.notes.length > 30) {
|
||||
notes = unavailable.notes.substring(0, 30) + '...'
|
||||
}
|
||||
if (unavailable.notes.length > 30) {
|
||||
notes = unavailable.notes.substring(0, 30) + '...'
|
||||
}
|
||||
|
||||
var unavailablePeriod = {
|
||||
title: EALang.unavailable + notes,
|
||||
start: moment(unavailable.start_datetime),
|
||||
end: moment(unavailable.end_datetime),
|
||||
allDay: false,
|
||||
color: '#879DB4',
|
||||
editable: true,
|
||||
className: 'fc-unavailable fc-custom',
|
||||
data: unavailable
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
// Non-working day.
|
||||
if (workingPlan[selectedDayName] == null) {
|
||||
// Extra working plan day.
|
||||
var selectedDay = $calendar.fullCalendar('getView').intervalStart.clone();
|
||||
selectedDay.locale('en');
|
||||
if (extraWorkingPlan != null && selectedDay.format() in extraWorkingPlan) {
|
||||
workingPlan[selectedDay.format('dddd').toLowerCase()] = extraWorkingPlan[selectedDay.format('YYYY-MM-DD')];
|
||||
|
||||
var start_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.format('YYYY-MM-DD')].start;
|
||||
var end_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.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'),
|
||||
allDay: true,
|
||||
color: '#879DB4',
|
||||
editable: false,
|
||||
className: 'fc-extra fc-custom',
|
||||
data: provider
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', extraPeriod, false);
|
||||
} else {
|
||||
unavailablePeriod = {
|
||||
title: EALang.not_working,
|
||||
start: $calendar.fullCalendar('getView').intervalStart.clone(),
|
||||
end: $calendar.fullCalendar('getView').intervalEnd.clone(),
|
||||
var unavailablePeriod = {
|
||||
title: EALang.unavailable + notes,
|
||||
start: moment(unavailable.start_datetime),
|
||||
end: moment(unavailable.end_datetime),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
color: '#879DB4',
|
||||
editable: true,
|
||||
className: 'fc-unavailable fc-custom',
|
||||
data: unavailable
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
return; // Go to next loop.
|
||||
}
|
||||
}
|
||||
// Non-working day.
|
||||
if (workingPlan[selectedDayName] === null) {
|
||||
// Extra working plan day.
|
||||
var selectedDay = $calendar.fullCalendar('getView').intervalStart.clone();
|
||||
selectedDay.locale('en');
|
||||
if (extraWorkingPlan && selectedDay.format() in extraWorkingPlan) {
|
||||
workingPlan[selectedDay.format('dddd').toLowerCase()] = extraWorkingPlan[selectedDay.format('YYYY-MM-DD')];
|
||||
|
||||
// Add unavailable period before work starts.
|
||||
var calendarDateStart = moment($calendar.fullCalendar('getView').start.format('YYYY-MM-DD') + ' 00:00:00');
|
||||
var startHour = workingPlan[selectedDayName].start.split(':');
|
||||
var workDateStart = calendarDateStart.clone();
|
||||
workDateStart.hour(parseInt(startHour[0]));
|
||||
workDateStart.minute(parseInt(startHour[1]));
|
||||
|
||||
if (calendarDateStart < workDateStart) {
|
||||
var unavailablePeriodBeforeWorkStarts = {
|
||||
title: EALang.not_working,
|
||||
start: calendarDateStart,
|
||||
end: workDateStart,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriodBeforeWorkStarts, false);
|
||||
}
|
||||
|
||||
// Add unavailable period after work ends.
|
||||
var calendarDateEnd = moment($calendar.fullCalendar('getView').end.format('YYYY-MM-DD') + ' 00:00:00');
|
||||
var endHour = workingPlan[selectedDayName].end.split(':');
|
||||
var workDateEnd = calendarDateStart.clone();
|
||||
|
||||
workDateEnd.hour(parseInt(endHour[0]));
|
||||
workDateEnd.minute(parseInt(endHour[1]));
|
||||
|
||||
if (calendarDateEnd > workDateEnd) {
|
||||
var unavailablePeriodAfterWorkEnds = {
|
||||
title: EALang.not_working,
|
||||
start: workDateEnd,
|
||||
end: calendarDateEnd,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriodAfterWorkEnds, false);
|
||||
}
|
||||
|
||||
// Add unavailable periods for breaks.
|
||||
var breakStart;
|
||||
var breakEnd;
|
||||
|
||||
$.each(workingPlan[selectedDayName].breaks, function (index, currentBreak) {
|
||||
var breakStartString = currentBreak.start.split(':');
|
||||
breakStart = calendarDateStart.clone();
|
||||
breakStart.hour(parseInt(breakStartString[0]));
|
||||
breakStart.minute(parseInt(breakStartString[1]));
|
||||
|
||||
var breakEndString = currentBreak.end.split(':');
|
||||
breakEnd = calendarDateStart.clone();
|
||||
breakEnd.hour(parseInt(breakEndString[0]));
|
||||
breakEnd.minute(parseInt(breakEndString[1]));
|
||||
|
||||
var unavailablePeriod = {
|
||||
title: EALang.break,
|
||||
start: breakStart,
|
||||
end: breakEnd,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable fc-break'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
case 'agendaWeek':
|
||||
var currentDateStart = $calendar.fullCalendar('getView').start.clone();
|
||||
var currentDateEnd = currentDateStart.clone().add(1, 'days');
|
||||
|
||||
// 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) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
|
||||
if (unavailable.notes.length > 30) {
|
||||
notes = unavailable.notes.substring(0, 30) + '...'
|
||||
}
|
||||
|
||||
unavailablePeriod = {
|
||||
title: EALang.unavailable + notes,
|
||||
start: moment(unavailable.start_datetime),
|
||||
end: moment(unavailable.end_datetime),
|
||||
allDay: false,
|
||||
color: '#879DB4',
|
||||
editable: true,
|
||||
className: 'fc-unavailable fc-custom',
|
||||
data: unavailable
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
$.each(workingPlan, function (index, workingDay) {
|
||||
if (workingDay == null) {
|
||||
// Check if the day is an extra working day added to the working plan
|
||||
if (extraWorkingPlan != null && 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 start_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.format('YYYY-MM-DD')].start;
|
||||
var end_extra = selectedDay.format('YYYY-MM-DD') + ' ' + extraWorkingPlan[selectedDay.format('YYYY-MM-DD')].end;
|
||||
|
||||
var extraPeriod = {
|
||||
title: EALang.extra_period,
|
||||
|
@ -992,87 +878,83 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
|
||||
$calendar.fullCalendar('renderEvent', extraPeriod, false);
|
||||
} else {
|
||||
// Add a full day unavailable event.
|
||||
unavailablePeriod = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD')),
|
||||
end: moment(currentDateEnd.format('YYYY-MM-DD')),
|
||||
start: $calendar.fullCalendar('getView').intervalStart.clone(),
|
||||
end: $calendar.fullCalendar('getView').intervalEnd.clone(),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
||||
currentDateStart.add(1, 'days');
|
||||
currentDateEnd.add(1, 'days');
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
|
||||
return; // Go to the next loop.
|
||||
return; // Go to next loop.
|
||||
}
|
||||
}
|
||||
|
||||
var start;
|
||||
var end;
|
||||
|
||||
// Add unavailable period before work starts.
|
||||
var workingDayStartString = workingDay.start.split(':');
|
||||
start = currentDateStart.clone();
|
||||
start.hour(parseInt(workingDayStartString[0]));
|
||||
start.minute(parseInt(workingDayStartString[1]));
|
||||
var calendarDateStart = moment($calendar.fullCalendar('getView').start.format('YYYY-MM-DD') + ' 00:00:00');
|
||||
var startHour = workingPlan[selectedDayName].start.split(':');
|
||||
var workDateStart = calendarDateStart.clone();
|
||||
workDateStart.hour(parseInt(startHour[0]));
|
||||
workDateStart.minute(parseInt(startHour[1]));
|
||||
|
||||
if (currentDateStart < start) {
|
||||
unavailablePeriod = {
|
||||
if (calendarDateStart < workDateStart) {
|
||||
var unavailablePeriodBeforeWorkStarts = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' 00:00:00'),
|
||||
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.start + ':00'),
|
||||
start: calendarDateStart,
|
||||
end: workDateStart,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriodBeforeWorkStarts, false);
|
||||
}
|
||||
|
||||
// Add unavailable period after work ends.
|
||||
var workingDayEndString = workingDay.end.split(':');
|
||||
end = currentDateStart.clone();
|
||||
end.hour(parseInt(workingDayEndString[0]));
|
||||
end.minute(parseInt(workingDayEndString[1]));
|
||||
var calendarDateEnd = moment($calendar.fullCalendar('getView').end.format('YYYY-MM-DD') + ' 00:00:00');
|
||||
var endHour = workingPlan[selectedDayName].end.split(':');
|
||||
var workDateEnd = calendarDateStart.clone();
|
||||
|
||||
if (currentDateEnd > end) {
|
||||
unavailablePeriod = {
|
||||
workDateEnd.hour(parseInt(endHour[0]));
|
||||
workDateEnd.minute(parseInt(endHour[1]));
|
||||
|
||||
if (calendarDateEnd > workDateEnd) {
|
||||
var unavailablePeriodAfterWorkEnds = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.end + ':00'),
|
||||
end: moment(currentDateEnd.format('YYYY-MM-DD') + ' 00:00:00'),
|
||||
start: workDateEnd,
|
||||
end: calendarDateEnd,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriodAfterWorkEnds, false);
|
||||
}
|
||||
|
||||
// Add unavailable periods during day breaks.
|
||||
// Add unavailable periods for breaks.
|
||||
var breakStart;
|
||||
var breakEnd;
|
||||
|
||||
$.each(workingDay.breaks, function (index, currentBreak) {
|
||||
$.each(workingPlan[selectedDayName].breaks, function (index, currentBreak) {
|
||||
var breakStartString = currentBreak.start.split(':');
|
||||
breakStart = currentDateStart.clone();
|
||||
breakStart = calendarDateStart.clone();
|
||||
breakStart.hour(parseInt(breakStartString[0]));
|
||||
breakStart.minute(parseInt(breakStartString[1]));
|
||||
|
||||
var breakEndString = currentBreak.end.split(':');
|
||||
breakEnd = currentDateStart.clone();
|
||||
breakEnd = calendarDateStart.clone();
|
||||
breakEnd.hour(parseInt(breakEndString[0]));
|
||||
breakEnd.minute(parseInt(breakEndString[1]));
|
||||
|
||||
var unavailablePeriod = {
|
||||
title: EALang.break,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.start),
|
||||
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.end),
|
||||
start: breakStart,
|
||||
end: breakEnd,
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
|
@ -1082,16 +964,157 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
currentDateStart.add(1, 'days');
|
||||
currentDateEnd.add(1, 'days');
|
||||
});
|
||||
break;
|
||||
|
||||
break;
|
||||
case 'agendaWeek':
|
||||
var currentDateStart = $calendar.fullCalendar('getView').start.clone();
|
||||
var currentDateEnd = currentDateStart.clone().add(1, 'days');
|
||||
|
||||
// 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) {
|
||||
var notes = unavailable.notes ? ' - ' + unavailable.notes : '';
|
||||
|
||||
if (unavailable.notes.length > 30) {
|
||||
notes = unavailable.notes.substring(0, 30) + '...'
|
||||
}
|
||||
|
||||
unavailablePeriod = {
|
||||
title: EALang.unavailable + notes,
|
||||
start: moment(unavailable.start_datetime),
|
||||
end: moment(unavailable.end_datetime),
|
||||
allDay: false,
|
||||
color: '#879DB4',
|
||||
editable: true,
|
||||
className: 'fc-unavailable fc-custom',
|
||||
data: unavailable
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
$.each(workingPlan, function (index, workingDay) {
|
||||
if (workingDay === null) {
|
||||
// Check if the day is an extra working day added to the working plan
|
||||
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 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'),
|
||||
allDay: true,
|
||||
color: '#879DB4',
|
||||
editable: false,
|
||||
className: 'fc-extra fc-custom',
|
||||
data: provider
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', extraPeriod, false);
|
||||
} else {
|
||||
// Add a full day unavailable event.
|
||||
unavailablePeriod = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD')),
|
||||
end: moment(currentDateEnd.format('YYYY-MM-DD')),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
||||
currentDateStart.add(1, 'days');
|
||||
currentDateEnd.add(1, 'days');
|
||||
|
||||
return; // Go to the next loop.
|
||||
}
|
||||
}
|
||||
|
||||
var start;
|
||||
var end;
|
||||
|
||||
// Add unavailable period before work starts.
|
||||
var workingDayStartString = workingDay.start.split(':');
|
||||
start = currentDateStart.clone();
|
||||
start.hour(parseInt(workingDayStartString[0]));
|
||||
start.minute(parseInt(workingDayStartString[1]));
|
||||
|
||||
if (currentDateStart < start) {
|
||||
unavailablePeriod = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' 00:00:00'),
|
||||
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.start + ':00'),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
||||
}
|
||||
|
||||
// Add unavailable period after work ends.
|
||||
var workingDayEndString = workingDay.end.split(':');
|
||||
end = currentDateStart.clone();
|
||||
end.hour(parseInt(workingDayEndString[0]));
|
||||
end.minute(parseInt(workingDayEndString[1]));
|
||||
|
||||
if (currentDateEnd > end) {
|
||||
unavailablePeriod = {
|
||||
title: EALang.not_working,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + workingDay.end + ':00'),
|
||||
end: moment(currentDateEnd.format('YYYY-MM-DD') + ' 00:00:00'),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
}
|
||||
|
||||
// Add unavailable periods during day breaks.
|
||||
var breakStart;
|
||||
var breakEnd;
|
||||
|
||||
$.each(workingDay.breaks, function (index, currentBreak) {
|
||||
var breakStartString = currentBreak.start.split(':');
|
||||
breakStart = currentDateStart.clone();
|
||||
breakStart.hour(parseInt(breakStartString[0]));
|
||||
breakStart.minute(parseInt(breakStartString[1]));
|
||||
|
||||
var breakEndString = currentBreak.end.split(':');
|
||||
breakEnd = currentDateStart.clone();
|
||||
breakEnd.hour(parseInt(breakEndString[0]));
|
||||
breakEnd.minute(parseInt(breakEndString[1]));
|
||||
|
||||
var unavailablePeriod = {
|
||||
title: EALang.break,
|
||||
start: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.start),
|
||||
end: moment(currentDateStart.format('YYYY-MM-DD') + ' ' + currentBreak.end),
|
||||
allDay: false,
|
||||
color: '#BEBEBE',
|
||||
editable: false,
|
||||
className: 'fc-unavailable fc-break'
|
||||
};
|
||||
|
||||
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
||||
});
|
||||
|
||||
currentDateStart.add(1, 'days');
|
||||
currentDateEnd.add(1, 'days');
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 'json')
|
||||
});
|
||||
}
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler)
|
||||
.always(function() {
|
||||
$('#loading').css('visibility', '')
|
||||
|
@ -1168,18 +1191,20 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$('#insert-appointment').trigger('click');
|
||||
|
||||
// Preselect service & provider.
|
||||
var service;
|
||||
|
||||
if ($('#select-filter-item option:selected').attr('type') === FILTER_TYPE_SERVICE) {
|
||||
var service = GlobalVariables.availableServices.find(function (service) {
|
||||
return service.id == $('#select-filter-item').val()
|
||||
service = GlobalVariables.availableServices.find(function (service) {
|
||||
return Number(service.id) === Number($('#select-filter-item').val());
|
||||
});
|
||||
$('#select-service').val(service.id).trigger('change');
|
||||
|
||||
} else {
|
||||
var provider = GlobalVariables.availableProviders.find(function (provider) {
|
||||
return provider.id == $('#select-filter-item').val();
|
||||
return Number(provider.id) === Number($('#select-filter-item').val());
|
||||
});
|
||||
|
||||
var service = GlobalVariables.availableServices.find(function (service) {
|
||||
service = GlobalVariables.availableServices.find(function (service) {
|
||||
return provider.services.indexOf(service.id) !== -1
|
||||
});
|
||||
|
||||
|
@ -1268,24 +1293,24 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
}
|
||||
|
||||
// Check permissions.
|
||||
if (GlobalVariables.user.role_slug == Backend.DB_SLUG_PROVIDER) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER) {
|
||||
$('#select-filter-item optgroup:eq(0)')
|
||||
.find('option[value="' + GlobalVariables.user.id + '"]')
|
||||
.prop('selected', true);
|
||||
$('#select-filter-item').prop('disabled', true);
|
||||
}
|
||||
|
||||
if (GlobalVariables.user.role_slug == Backend.DB_SLUG_SECRETARY) {
|
||||
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY) {
|
||||
$('#select-filter-item optgroup:eq(1)').remove();
|
||||
}
|
||||
|
||||
if (GlobalVariables.user.role_slug == Backend.DB_SLUG_SECRETARY) {
|
||||
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, id) {
|
||||
if ($(option).val() == id) {
|
||||
$.each(GlobalVariables.secretaryProviders, function (index, secretaryProviderId) {
|
||||
if (Number($(option).val()) === Number(secretaryProviderId)) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -1296,7 +1321,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
}
|
||||
});
|
||||
|
||||
if ($('#select-filter-item option[type="provider"]').length == 0) {
|
||||
if (!$('#select-filter-item option[type="provider"]').length) {
|
||||
$('#select-filter-item optgroup[type="providers-group"]').remove();
|
||||
}
|
||||
}
|
||||
|
@ -1307,7 +1332,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
$('#select-filter-item').trigger('change');
|
||||
|
||||
// Display the edit dialog if an appointment hash is provided.
|
||||
if (GlobalVariables.editAppointment != null) {
|
||||
if (GlobalVariables.editAppointment) {
|
||||
var $dialog = $('#manage-appointment');
|
||||
var appointment = GlobalVariables.editAppointment;
|
||||
BackendCalendarAppointmentsModal.resetAppointmentDialog();
|
||||
|
@ -1361,7 +1386,7 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
|||
}
|
||||
});
|
||||
|
||||
if ($('#select-filter-item option').length == 0) {
|
||||
if (!$('#select-filter-item option').length) {
|
||||
$('#calendar-actions button').prop('disabled', true);
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
// becomes "undefined" and when it comes back to the redirect URL it changes back. So check
|
||||
// whether the variable is undefined to avoid javascript errors.
|
||||
try {
|
||||
if (windowHandle.document !== undefined) {
|
||||
if (windowHandle.document) {
|
||||
if (windowHandle.document.URL.indexOf(redirectUrl) !== -1) {
|
||||
// The user has granted access to his data.
|
||||
windowHandle.close();
|
||||
|
@ -61,21 +61,24 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
// Display the calendar selection dialog. First we will get a list of the available
|
||||
// user's calendars and then we will display a selection modal so the user can select
|
||||
// the sync calendar.
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_google_calendars';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_google_calendars';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
provider_id: $('#select-filter-item').val()
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
$('#google-calendar').empty();
|
||||
$.each(response, function () {
|
||||
var option = '<option value="' + this.id + '">' + this.summary + '</option>';
|
||||
$('#google-calendar').append(option);
|
||||
});
|
||||
$.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);
|
||||
});
|
||||
|
||||
$('#select-google-calendar').modal('show');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$('#select-google-calendar').modal('show');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
}
|
||||
} catch (Error) {
|
||||
|
@ -90,7 +93,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
// 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 (provider.id == $('#select-filter-item').val()) {
|
||||
if (Number(provider.id) === Number($('#select-filter-item').val())) {
|
||||
provider.settings.google_sync = '0';
|
||||
provider.settings.google_token = null;
|
||||
|
||||
|
@ -112,6 +115,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
*/
|
||||
$('#select-calendar').click(function () {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_select_google_calendar';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
provider_id: $('#select-filter-item').val(),
|
||||
|
@ -166,6 +170,7 @@ window.BackendCalendarGoogleSync = window.BackendCalendarGoogleSync || {};
|
|||
// Make an ajax call to the server in order to disable the setting
|
||||
// from the database.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_disable_provider_sync';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
provider_id: providerId
|
||||
|
|
|
@ -145,7 +145,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
|
||||
var $dialog;
|
||||
|
||||
if (lastFocusedEventData.data.is_unavailable == false) {
|
||||
if (lastFocusedEventData.data.is_unavailable === '0') {
|
||||
var appointment = lastFocusedEventData.data;
|
||||
$dialog = $('#manage-appointment');
|
||||
|
||||
|
@ -210,44 +210,53 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
$calendar.on('click', '.delete-popover', function () {
|
||||
$(this).parents().eq(2).remove(); // Hide the popover.
|
||||
|
||||
var url;
|
||||
var data;
|
||||
|
||||
// If id_role parameter exists the popover is an extra working day.
|
||||
if (lastFocusedEventData.data.hasOwnProperty('id_roles')) {
|
||||
// Do not display confirmation prompt.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
extra_period: lastFocusedEventData.start.format('YYYY-MM-DD'),
|
||||
provider_id: lastFocusedEventData.data.id
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
} else if (lastFocusedEventData.data.is_unavailable == false) {
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
} else if (lastFocusedEventData.data.is_unavailable === '0') {
|
||||
var buttons = [
|
||||
{
|
||||
text: 'OK',
|
||||
click: function () {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
appointment_id: lastFocusedEventData.data.id,
|
||||
delete_reason: $('#delete-reason').val()
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -266,18 +275,21 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
$('#delete-reason').css('width', '100%');
|
||||
} else {
|
||||
// Do not display confirmation prompt.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
||||
var data = {
|
||||
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
||||
|
||||
data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable_id: lastFocusedEventData.data.id
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
$('#message_box').dialog('close');
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#message_box').dialog('close');
|
||||
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Refresh calendar event items.
|
||||
$('#select-filter-item').trigger('change');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -763,7 +775,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
var end = view.end.clone();
|
||||
var selDayName = start.toDate().toString('dddd').toLowerCase();
|
||||
|
||||
if (workingPlan[selDayName] == null) {
|
||||
if (workingPlan[selDayName] === null) {
|
||||
var nonWorkingDay = {
|
||||
title: EALang.not_working,
|
||||
start: start,
|
||||
|
@ -982,10 +994,10 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
|
||||
if ($(this).hasClass('fc-unavailable') || $parent.hasClass('fc-unavailable') || $altParent.hasClass('fc-unavailable')) {
|
||||
displayEdit = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.edit == true)
|
||||
&& GlobalVariables.user.privileges.appointments.edit === true)
|
||||
? '' : 'hide';
|
||||
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.delete == true)
|
||||
&& GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide'; // Same value at the time.
|
||||
|
||||
var notes = '';
|
||||
|
@ -1013,7 +1025,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
'</center>';
|
||||
} else if ($(this).hasClass('fc-extra') || $parent.hasClass('fc-extra') || $altParent.hasClass('fc-extra')) {
|
||||
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
||||
&& GlobalVariables.user.privileges.appointments.delete == true)
|
||||
&& GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide'; // Same value at the time.
|
||||
|
||||
var provider = '';
|
||||
|
@ -1045,9 +1057,9 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
'</center>';
|
||||
|
||||
} else {
|
||||
displayEdit = (GlobalVariables.user.privileges.appointments.edit == true)
|
||||
displayEdit = (GlobalVariables.user.privileges.appointments.edit === true)
|
||||
? '' : 'hide';
|
||||
displayDelete = (GlobalVariables.user.privileges.appointments.delete == true)
|
||||
displayDelete = (GlobalVariables.user.privileges.appointments.delete === true)
|
||||
? '' : 'hide';
|
||||
|
||||
html =
|
||||
|
@ -1120,7 +1132,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* @see updateAppointmentData()
|
||||
*/
|
||||
function onEventResize(event, delta, revertFunc, jsEvent, ui, view) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
||||
revertFunc();
|
||||
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
||||
return;
|
||||
|
@ -1132,7 +1144,9 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
$('#notification').hide('bind');
|
||||
}
|
||||
|
||||
if (event.data.is_unavailable == false) {
|
||||
var successCallback;
|
||||
|
||||
if (event.data.is_unavailable === '0') {
|
||||
// Prepare appointment data.
|
||||
event.data.end_datetime = Date.parseExact(
|
||||
event.data.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
||||
|
@ -1147,7 +1161,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
delete appointment.service;
|
||||
|
||||
// Success callback
|
||||
var successCallback = function () {
|
||||
successCallback = function () {
|
||||
// Display success notification to user.
|
||||
var undoFunction = function () {
|
||||
appointment.end_datetime = event.data.end_datetime = Date.parseExact(
|
||||
|
@ -1162,10 +1176,12 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
$.post(url, data, function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.appointment_updated, [
|
||||
|
@ -1181,7 +1197,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
};
|
||||
|
||||
// Update appointment data.
|
||||
BackendCalendarApi.saveAppointment(appointment, undefined, successCallback);
|
||||
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
||||
} else {
|
||||
// Update unavailable time period.
|
||||
var unavailable = {
|
||||
|
@ -1194,7 +1210,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
event.data.end_datetime = unavailable.end_datetime;
|
||||
|
||||
// Define success callback function.
|
||||
var successCallback = function () {
|
||||
successCallback = function () {
|
||||
// Display success notification to user.
|
||||
var undoFunction = function () {
|
||||
unavailable.end_datetime = event.data.end_datetime = Date.parseExact(
|
||||
|
@ -1203,15 +1219,18 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
.toString('yyyy-MM-dd HH:mm:ss');
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable: JSON.stringify(unavailable)
|
||||
};
|
||||
|
||||
$.post(url, data, function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.unavailable_updated, [
|
||||
|
@ -1237,8 +1256,8 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
* This event handler is triggered whenever the user drags and drops an event into a different position
|
||||
* on the calendar. We need to update the database with this change. This is done via an ajax call.
|
||||
*/
|
||||
function onEventDrop(event, delta, revertFunc, jsEvent, ui, view) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
||||
function onEventDrop(event, delta, revertFunc) {
|
||||
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
||||
revertFunc();
|
||||
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
||||
return;
|
||||
|
@ -1250,7 +1269,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
|
||||
var successCallback;
|
||||
|
||||
if (event.data.is_unavailable == false) {
|
||||
if (event.data.is_unavailable === '0') {
|
||||
// Prepare appointment data.
|
||||
var appointment = GeneralFunctions.clone(event.data);
|
||||
|
||||
|
@ -1290,15 +1309,18 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
event.data.end_datetime = appointment.end_datetime;
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
appointment_data: JSON.stringify(appointment)
|
||||
};
|
||||
|
||||
$.post(url, data, function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.appointment_updated, [
|
||||
|
@ -1312,7 +1334,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
};
|
||||
|
||||
// Update appointment data.
|
||||
BackendCalendarApi.saveAppointment(appointment, undefined, successCallback);
|
||||
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
||||
} else {
|
||||
// Update unavailable time period.
|
||||
var unavailable = {
|
||||
|
@ -1338,15 +1360,18 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
event.data.end_datetime = unavailable.end_datetime;
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
unavailable: JSON.stringify(unavailable)
|
||||
};
|
||||
|
||||
$.post(url, data, function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
$('#notification').hide('blind');
|
||||
revertFunc();
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
Backend.displayNotification(EALang.unavailable_updated, [
|
||||
|
@ -1405,6 +1430,7 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|||
*/
|
||||
function getCalendarEvents(startDate, endDate) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_calendar_events';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
startDate: startDate.toString('yyyy-MM-dd'),
|
||||
|
|
|
@ -169,41 +169,44 @@
|
|||
* @param {Boolean} display Optional (false), if true then the selected record will be displayed on the form.
|
||||
*/
|
||||
CategoriesHelper.prototype.filter = function (key, selectId, display) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-categories .results').html('');
|
||||
$.each(response, function (index, category) {
|
||||
var html = this.getFilterHtml(category);
|
||||
$('#filter-categories .results').append(html);
|
||||
}.bind(this));
|
||||
$('#filter-categories .results').html('');
|
||||
$.each(response, function (index, category) {
|
||||
var html = this.getFilterHtml(category);
|
||||
$('#filter-categories .results').append(html);
|
||||
}.bind(this));
|
||||
|
||||
if (response.length === 0) {
|
||||
$('#filter-categories .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-categories .results');
|
||||
}
|
||||
if (response.length === 0) {
|
||||
$('#filter-categories .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-categories .results');
|
||||
}
|
||||
|
||||
if (selectId !== undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -212,19 +215,22 @@
|
|||
* @param {Object} category Contains the category data.
|
||||
*/
|
||||
CategoriesHelper.prototype.save = function (category) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_service_category';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_service_category';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
category: JSON.stringify(category)
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.service_category_saved);
|
||||
this.resetForm();
|
||||
$('#filter-categories .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
BackendServices.updateAvailableCategories();
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
Backend.displayNotification(EALang.service_category_saved);
|
||||
this.resetForm();
|
||||
$('#filter-categories .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
BackendServices.updateAvailableCategories();
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -233,19 +239,22 @@
|
|||
* @param Number} id Record ID to be deleted.
|
||||
*/
|
||||
CategoriesHelper.prototype.delete = function (id) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_service_category';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_service_category';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
category_id: id
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.service_category_deleted);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.service_category_deleted);
|
||||
|
||||
this.resetForm();
|
||||
this.filter($('#filter-categories .key').val());
|
||||
BackendServices.updateAvailableCategories();
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
this.resetForm();
|
||||
this.filter($('#filter-categories .key').val());
|
||||
BackendServices.updateAvailableCategories();
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -271,18 +280,18 @@
|
|||
var missingRequired = false;
|
||||
|
||||
$('#categories .required').each(function () {
|
||||
if ($(this).val() === '' || $(this).val() === undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -333,7 +342,7 @@
|
|||
$('#filter-categories .selected').removeClass('selected');
|
||||
|
||||
$('#filter-categories .category-row').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if ($(this).attr('data-id') === id) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -341,7 +350,7 @@
|
|||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, category) {
|
||||
if (category.id == id) {
|
||||
if (category.id === id) {
|
||||
this.display(category);
|
||||
$('#edit-category, #delete-category').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
var customerId = $(this).attr('data-id');
|
||||
var customer = {};
|
||||
$.each(instance.filterResults, function (index, item) {
|
||||
if (item.id == customerId) {
|
||||
if (Number(item.id) === Number(customerId)) {
|
||||
customer = item;
|
||||
return false;
|
||||
}
|
||||
|
@ -91,11 +91,11 @@
|
|||
var appointmentId = $(this).attr('data-id');
|
||||
var appointment = {};
|
||||
|
||||
$.each(instance.filterResults, function (index, c) {
|
||||
if (c.id === customerId) {
|
||||
$.each(c.appointments, function (index, a) {
|
||||
if (a.id == appointmentId) {
|
||||
appointment = a;
|
||||
$.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;
|
||||
}
|
||||
});
|
||||
|
@ -137,7 +137,7 @@
|
|||
$('#cancel-customer').click(function () {
|
||||
var id = $('#customer-id').val();
|
||||
instance.resetForm();
|
||||
if (id != '') {
|
||||
if (id) {
|
||||
instance.select(id, true);
|
||||
}
|
||||
});
|
||||
|
@ -158,7 +158,7 @@
|
|||
timezone: $('#timezone').val()
|
||||
};
|
||||
|
||||
if ($('#customer-id').val() != '') {
|
||||
if ($('#customer-id').val()) {
|
||||
customer.id = $('#customer-id').val();
|
||||
}
|
||||
|
||||
|
@ -201,18 +201,21 @@
|
|||
* @param {Object} customer Contains the customer data.
|
||||
*/
|
||||
CustomersHelper.prototype.save = function (customer) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_customer';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_customer';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
customer: JSON.stringify(customer)
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.customer_saved);
|
||||
this.resetForm();
|
||||
$('#filter-customers .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
Backend.displayNotification(EALang.customer_saved);
|
||||
this.resetForm();
|
||||
$('#filter-customers .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -221,17 +224,20 @@
|
|||
* @param {Number} id Record id to be deleted.
|
||||
*/
|
||||
CustomersHelper.prototype.delete = function (id) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_customer';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_customer';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
customer_id: id
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.customer_deleted);
|
||||
this.resetForm();
|
||||
this.filter($('#filter-customers .key').val());
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.customer_deleted);
|
||||
this.resetForm();
|
||||
this.filter($('#filter-customers .key').val());
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -248,27 +254,27 @@
|
|||
var missingRequired = false;
|
||||
|
||||
$('.required').each(function () {
|
||||
if ($(this).val() == '') {
|
||||
if ($(this).val() === '') {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
// Validate email address.
|
||||
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
||||
$('#email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
} catch (error) {
|
||||
$('#form-message')
|
||||
.addClass('alert-danger')
|
||||
.text(message)
|
||||
.text(error.message)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
|
@ -347,42 +353,45 @@
|
|||
CustomersHelper.prototype.filter = function (key, selectId, display) {
|
||||
display = display || false;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-customers .results').html('');
|
||||
$.each(response, function (index, customer) {
|
||||
var html = this.getFilterHtml(customer);
|
||||
$('#filter-customers .results').append(html);
|
||||
}.bind(this));
|
||||
$('#filter-customers .results').html('');
|
||||
$.each(response, function (index, customer) {
|
||||
var html = this.getFilterHtml(customer);
|
||||
$('#filter-customers .results').append(html);
|
||||
}.bind(this));
|
||||
|
||||
if (response.length == 0) {
|
||||
$('#filter-customers .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-customers .results');
|
||||
}
|
||||
if (!response.length) {
|
||||
$('#filter-customers .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-customers .results');
|
||||
}
|
||||
|
||||
if (selectId != undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -395,8 +404,7 @@
|
|||
CustomersHelper.prototype.getFilterHtml = function (customer) {
|
||||
var name = customer.first_name + ' ' + customer.last_name;
|
||||
var info = customer.email;
|
||||
info = (customer.phone_number != '' && customer.phone_number != null)
|
||||
? info + ', ' + customer.phone_number : info;
|
||||
info = customer.phone_number ? info + ', ' + customer.phone_number : info;
|
||||
|
||||
var html =
|
||||
'<div class="entry" data-id="' + customer.id + '">' +
|
||||
|
@ -424,7 +432,7 @@
|
|||
$('#filter-customers .selected').removeClass('selected');
|
||||
|
||||
$('#filter-customers .entry').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -432,7 +440,7 @@
|
|||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, customer) {
|
||||
if (customer.id == id) {
|
||||
if (Number(customer.id) === Number(id)) {
|
||||
this.display(customer);
|
||||
$('#edit-customer, #delete-customer').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -92,20 +92,23 @@ window.BackendServices = window.BackendServices || {};
|
|||
*/
|
||||
exports.updateAvailableCategories = function () {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_service_categories';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: ''
|
||||
};
|
||||
|
||||
$.post(url, data, 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);
|
||||
});
|
||||
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.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);
|
||||
});
|
||||
$select.append(new Option('- ' + EALang.no_category + ' -', null)).val('null');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
})(window.BackendServices);
|
||||
|
|
|
@ -190,18 +190,21 @@
|
|||
* then the update operation is going to be executed.
|
||||
*/
|
||||
ServicesHelper.prototype.save = function (service) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_service';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_service';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
service: JSON.stringify(service)
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.service_saved);
|
||||
this.resetForm();
|
||||
$('#filter-services .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
Backend.displayNotification(EALang.service_saved);
|
||||
this.resetForm();
|
||||
$('#filter-services .key').val('');
|
||||
this.filter('', response.id, true);
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -210,18 +213,21 @@
|
|||
* @param {Number} id Record ID to be deleted.
|
||||
*/
|
||||
ServicesHelper.prototype.delete = function (id) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_service';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_service';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
service_id: id
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.service_deleted);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.service_deleted);
|
||||
|
||||
this.resetForm();
|
||||
this.filter($('#filter-services .key').val());
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
this.resetForm();
|
||||
this.filter($('#filter-services .key').val());
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -237,18 +243,18 @@
|
|||
var missingRequired = false;
|
||||
|
||||
$('#services .required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (exc) {
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -301,41 +307,44 @@
|
|||
ServicesHelper.prototype.filter = function (key, selectId, display) {
|
||||
display = display || false;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_services';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_services';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-services .results').html('');
|
||||
$.each(response, function (index, service) {
|
||||
var html = ServicesHelper.prototype.getFilterHtml(service);
|
||||
$('#filter-services .results').append(html);
|
||||
});
|
||||
$('#filter-services .results').html('');
|
||||
$.each(response, function (index, service) {
|
||||
var html = ServicesHelper.prototype.getFilterHtml(service);
|
||||
$('#filter-services .results').append(html);
|
||||
});
|
||||
|
||||
if (response.length === 0) {
|
||||
$('#filter-services .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-services .results');
|
||||
}
|
||||
if (response.length === 0) {
|
||||
$('#filter-services .results').html('<em>' + EALang.no_records_found + '</em>');
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-services .results');
|
||||
}
|
||||
|
||||
if (selectId !== undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -371,7 +380,7 @@
|
|||
$('#filter-services .selected').removeClass('selected');
|
||||
|
||||
$('#filter-services .service-row').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -379,7 +388,7 @@
|
|||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, service) {
|
||||
if (service.id == id) {
|
||||
if (Number(service.id) === Number(id)) {
|
||||
this.display(service);
|
||||
$('#edit-service, #delete-service').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -126,7 +126,7 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
$('#password, #retype-password').val('');
|
||||
$('#calendar-view').val(GlobalVariables.settings.user.settings.calendar_view);
|
||||
|
||||
if (GlobalVariables.settings.user.settings.notifications == true) {
|
||||
if (GlobalVariables.settings.user.settings.notifications === true) {
|
||||
$('#user-notifications').addClass('active');
|
||||
} else {
|
||||
$('#user-notifications').removeClass('active');
|
||||
|
@ -142,12 +142,12 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
}
|
||||
|
||||
// Apply Privileges
|
||||
if (GlobalVariables.user.privileges.system_settings.edit == false) {
|
||||
if (GlobalVariables.user.privileges.system_settings.edit === false) {
|
||||
$('#general, #business-logic').find('select, input, textarea').prop('readonly', true);
|
||||
$('#general, #business-logic').find('button').prop('disabled', true);
|
||||
}
|
||||
|
||||
if (GlobalVariables.user.privileges.user_settings.edit == false) {
|
||||
if (GlobalVariables.user.privileges.user_settings.edit === false) {
|
||||
$('#user').find('select, input, textarea').prop('readonly', true);
|
||||
$('#user').find('button').prop('disabled', true);
|
||||
}
|
||||
|
@ -214,27 +214,30 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
$('#username').focusout(function () {
|
||||
var $input = $(this);
|
||||
|
||||
if ($input.prop('readonly') == true || $input.val() == '') {
|
||||
if ($input.prop('readonly') === true || $input.val() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
username: $input.val(),
|
||||
user_id: $input.parents().eq(2).find('#user-id').val()
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
if (response == false) {
|
||||
$input.closest('.form-group').addClass('has-error');
|
||||
Backend.displayNotification(EALang.username_already_exists);
|
||||
$input.attr('already-exists', 'true');
|
||||
} else {
|
||||
$input.closest('.form-group').removeClass('has-error');
|
||||
$input.attr('already-exists', 'false');
|
||||
}
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
if (response === 'false') {
|
||||
$input.closest('.form-group').addClass('has-error');
|
||||
Backend.displayNotification(EALang.username_already_exists);
|
||||
$input.attr('already-exists', 'true');
|
||||
} else {
|
||||
$input.closest('.form-group').removeClass('has-error');
|
||||
$input.attr('already-exists', 'false');
|
||||
}
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -245,16 +248,17 @@ window.BackendSettings = window.BackendSettings || {};
|
|||
{
|
||||
text: 'OK',
|
||||
click: function() {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_apply_global_working_plan';
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_apply_global_working_plan';
|
||||
|
||||
var postData = {
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
working_plan: JSON.stringify(exports.wp.get()),
|
||||
working_plan: JSON.stringify(exports.wp.get())
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.working_plans_got_updated);
|
||||
}, 'json')
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.working_plans_got_updated);
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler)
|
||||
.always(function() {
|
||||
$('#message_box').dialog('close');
|
||||
|
|
|
@ -29,28 +29,31 @@
|
|||
* @param {Array} settings Contains the system settings data.
|
||||
*/
|
||||
SystemSettings.prototype.save = function (settings) {
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_settings';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_settings';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
settings: JSON.stringify(settings),
|
||||
type: BackendSettings.SETTINGS_SYSTEM
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.settings_saved);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.settings_saved);
|
||||
|
||||
// Update the logo title on the header.
|
||||
$('#header-logo span').text($('#company-name').val());
|
||||
// Update the logo title on the header.
|
||||
$('#header-logo span').text($('#company-name').val());
|
||||
|
||||
// Update variables also used in other setting tabs
|
||||
GlobalVariables.timeFormat = $('#time-format').val();
|
||||
GlobalVariables.firstWeekday = $('#first-weekday').val();
|
||||
// Update variables also used in other setting tabs
|
||||
GlobalVariables.timeFormat = $('#time-format').val();
|
||||
GlobalVariables.firstWeekday = $('#first-weekday').val();
|
||||
|
||||
// We need to refresh the working plan.
|
||||
var workingPlan = BackendSettings.wp.get();
|
||||
BackendSettings.wp.setup(workingPlan);
|
||||
BackendSettings.wp.timepickers(false);
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// We need to refresh the working plan.
|
||||
var workingPlan = BackendSettings.wp.get();
|
||||
BackendSettings.wp.setup(workingPlan);
|
||||
BackendSettings.wp.timepickers(false);
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -151,25 +154,25 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#general .required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
// Validate company email address.
|
||||
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
||||
$('#company-email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
Backend.displayNotification(message);
|
||||
} catch (error) {
|
||||
Backend.displayNotification(error.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
}
|
||||
};
|
||||
|
||||
if ($('#password').val() != '') {
|
||||
if ($('#password').val()) {
|
||||
user.settings.password = $('#password').val();
|
||||
}
|
||||
|
||||
|
@ -65,20 +65,22 @@
|
|||
return; // Validation failed, do not proceed.
|
||||
}
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_settings';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_settings';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
type: BackendSettings.SETTINGS_USER,
|
||||
settings: JSON.stringify(settings)
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
Backend.displayNotification(EALang.settings_saved);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
Backend.displayNotification(EALang.settings_saved);
|
||||
|
||||
// Update footer greetings.
|
||||
$('#footer-user-display-name').text('Hello, ' + $('#first-name').val() + ' ' + $('#last-name').val() + '!');
|
||||
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
// Update footer greetings.
|
||||
$('#footer-user-display-name').text('Hello, ' + $('#first-name').val() + ' ' + $('#last-name').val() + '!');
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -95,36 +97,36 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#user .required').each(function () {
|
||||
if ($(this).val() === '' || $(this).val() === undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
// Validate passwords (if provided).
|
||||
if ($('#password').val() != $('#retype-password').val()) {
|
||||
if ($('#password').val() !== $('#retype-password').val()) {
|
||||
$('#password, #retype-password').closest('.form-group').addClass('has-error');
|
||||
throw EALang.passwords_mismatch;
|
||||
throw new Error(EALang.passwords_mismatch);
|
||||
}
|
||||
|
||||
// Validate user email.
|
||||
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
||||
$('#email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
if ($('#username').attr('already-exists') === 'true') {
|
||||
$('#username').closest('.form-group').addClass('has-error');
|
||||
throw EALang.username_already_exists;
|
||||
throw new Error(EALang.username_already_exists);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (exc) {
|
||||
Backend.displayNotification(exc);
|
||||
} catch (error) {
|
||||
Backend.displayNotification(exc.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -126,27 +126,31 @@ window.BackendUsers = window.BackendUsers || {};
|
|||
|
||||
// Update the list with the all the available providers.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: ''
|
||||
};
|
||||
$.post(url, data, function (response) {
|
||||
GlobalVariables.providers = response;
|
||||
|
||||
var html = '<div>';
|
||||
$.each(GlobalVariables.providers, function (index, provider) {
|
||||
html +=
|
||||
'<div class="checkbox">' +
|
||||
'<label class="checkbox">' +
|
||||
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
||||
provider.first_name + ' ' + provider.last_name +
|
||||
'</label>' +
|
||||
'</div>';
|
||||
});
|
||||
html += '</div>';
|
||||
$('#secretary-providers').html(html);
|
||||
$('#secretary-providers input:checkbox').prop('disabled', true);
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
GlobalVariables.providers = response;
|
||||
|
||||
var html = '<div>';
|
||||
$.each(GlobalVariables.providers, function (index, provider) {
|
||||
html +=
|
||||
'<div class="checkbox">' +
|
||||
'<label class="checkbox">' +
|
||||
'<input type="checkbox" data-id="' + provider.id + '" />' +
|
||||
provider.first_name + ' ' + provider.last_name +
|
||||
'</label>' +
|
||||
'</div>';
|
||||
});
|
||||
html += '</div>';
|
||||
$('#secretary-providers').html(html);
|
||||
$('#secretary-providers input:checkbox').prop('disabled', true);
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
}
|
||||
|
||||
helper.resetForm();
|
||||
|
@ -164,37 +168,40 @@ window.BackendUsers = window.BackendUsers || {};
|
|||
$('#admin-username, #provider-username, #secretary-username').focusout(function () {
|
||||
var $input = $(this);
|
||||
|
||||
if ($input.prop('readonly') == true || $input.val() == '') {
|
||||
if ($input.prop('readonly') === true || $input.val() === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
var userId = $input.parents().eq(2).find('.record-id').val();
|
||||
|
||||
if (userId == undefined) {
|
||||
if (!userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_validate_username';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
username: $input.val(),
|
||||
user_id: userId
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
if (response == false) {
|
||||
$input.closest('.form-group').addClass('has-error');
|
||||
$input.attr('already-exists', 'true');
|
||||
$input.parents().eq(3).find('.form-message').text(EALang.username_already_exists);
|
||||
$input.parents().eq(3).find('.form-message').show();
|
||||
} else {
|
||||
$input.closest('.form-group').removeClass('has-error');
|
||||
$input.attr('already-exists', 'false');
|
||||
if ($input.parents().eq(3).find('.form-message').text() == EALang.username_already_exists) {
|
||||
$input.parents().eq(3).find('.form-message').hide();
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
if (response === 'false') {
|
||||
$input.closest('.form-group').addClass('has-error');
|
||||
$input.attr('already-exists', 'true');
|
||||
$input.parents().eq(3).find('.form-message').text(EALang.username_already_exists);
|
||||
$input.parents().eq(3).find('.form-message').show();
|
||||
} else {
|
||||
$input.closest('.form-group').removeClass('has-error');
|
||||
$input.attr('already-exists', 'false');
|
||||
if ($input.parents().eq(3).find('.form-message').text() === EALang.username_already_exists) {
|
||||
$input.parents().eq(3).find('.form-message').hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@
|
|||
$('#admins').on('click', '#cancel-admin', function () {
|
||||
var id = $('#admin-id').val();
|
||||
this.resetForm();
|
||||
if (id != '') {
|
||||
if (id) {
|
||||
this.select(id, true);
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -195,6 +195,7 @@
|
|||
*/
|
||||
AdminsHelper.prototype.save = function (admin) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_admin';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
admin: JSON.stringify(admin)
|
||||
|
@ -217,6 +218,7 @@
|
|||
*/
|
||||
AdminsHelper.prototype.delete = function (id) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_admin';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
admin_id: id
|
||||
|
@ -244,45 +246,45 @@
|
|||
var missingRequired = false;
|
||||
|
||||
$('#admins .required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw 'Fields with * are required.';
|
||||
throw new Error('Fields with * are required.');
|
||||
}
|
||||
|
||||
// Validate passwords.
|
||||
if ($('#admin-password').val() != $('#admin-password-confirm').val()) {
|
||||
if ($('#admin-password').val() !== $('#admin-password-confirm').val()) {
|
||||
$('#admin-password, #admin-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw EALang.passwords_mismatch;
|
||||
throw new Error(EALang.passwords_mismatch);
|
||||
}
|
||||
|
||||
if ($('#admin-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
||||
&& $('#admin-password').val() != '') {
|
||||
&& $('#admin-password').val() !== '') {
|
||||
$('#admin-password, #admin-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw EALang.password_length_notice.replace('$number', BackendUsers.MIN_PASSWORD_LENGTH);
|
||||
throw new Error(EALang.password_length_notice.replace('$number', BackendUsers.MIN_PASSWORD_LENGTH));
|
||||
}
|
||||
|
||||
// Validate user email.
|
||||
if (!GeneralFunctions.validateEmail($('#admin-email').val())) {
|
||||
$('#admin-email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
// Check if username exists
|
||||
if ($('#admin-username').attr('already-exists') == 'true') {
|
||||
if ($('#admin-username').attr('already-exists') === 'true') {
|
||||
$('#admin-username').closest('.form-group').addClass('has-error');
|
||||
throw EALang.username_already_exists;
|
||||
throw new Error(EALang.username_already_exists);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
} catch (error) {
|
||||
$('#admins .form-message')
|
||||
.addClass('alert-danger')
|
||||
.text(message)
|
||||
.text(error.message)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
|
@ -328,7 +330,7 @@
|
|||
|
||||
$('#admin-username').val(admin.settings.username);
|
||||
$('#admin-calendar-view').val(admin.settings.calendar_view);
|
||||
if (admin.settings.notifications == true) {
|
||||
if (admin.settings.notifications === true) {
|
||||
$('#admin-notifications').addClass('active');
|
||||
} else {
|
||||
$('#admin-notifications').removeClass('active');
|
||||
|
@ -347,41 +349,44 @@
|
|||
AdminsHelper.prototype.filter = function (key, selectId, display) {
|
||||
display = display || false;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_admins';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_admins';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-admins .results').html('');
|
||||
$.each(response, function (index, admin) {
|
||||
var html = this.getFilterHtml(admin);
|
||||
$('#filter-admins .results').append(html);
|
||||
}.bind(this));
|
||||
$('#filter-admins .results').html('');
|
||||
$.each(response, function (index, admin) {
|
||||
var html = this.getFilterHtml(admin);
|
||||
$('#filter-admins .results').append(html);
|
||||
}.bind(this));
|
||||
|
||||
if (response.length == 0) {
|
||||
$('#filter-admins .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-admins .results');
|
||||
}
|
||||
if (!response.length) {
|
||||
$('#filter-admins .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-admins .results');
|
||||
}
|
||||
|
||||
if (selectId != undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -395,11 +400,9 @@
|
|||
var name = admin.first_name + ' ' + admin.last_name;
|
||||
var info = admin.email;
|
||||
|
||||
info = (admin.mobile_number != '' && admin.mobile_number != null)
|
||||
? info + ', ' + admin.mobile_number : info;
|
||||
info = admin.mobile_number ? info + ', ' + admin.mobile_number : info;
|
||||
|
||||
info = (admin.phone_number != '' && admin.phone_number != null)
|
||||
? info + ', ' + admin.phone_number : info;
|
||||
info = admin.phone_number ? info + ', ' + admin.phone_number : info;
|
||||
|
||||
var html =
|
||||
'<div class="admin-row entry" data-id="' + admin.id + '">' +
|
||||
|
@ -424,7 +427,7 @@
|
|||
$('#filter-admins .selected').removeClass('selected');
|
||||
|
||||
$('.admin-row').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -432,7 +435,7 @@
|
|||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, admin) {
|
||||
if (admin.id == id) {
|
||||
if (Number(admin.id) === Number(id)) {
|
||||
this.display(admin);
|
||||
$('#edit-admin, #delete-admin').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -203,7 +203,7 @@
|
|||
$('#providers').on('click', '#cancel-provider', function () {
|
||||
var id = $('#filter-providers .selected').attr('data-id');
|
||||
this.resetForm();
|
||||
if (id != '') {
|
||||
if (id) {
|
||||
this.select(id, true);
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -298,44 +298,44 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#providers .required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
if (missingRequired) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
// Validate passwords.
|
||||
if ($('#provider-password').val() != $('#provider-password-confirm').val()) {
|
||||
if ($('#provider-password').val() !== $('#provider-password-confirm').val()) {
|
||||
$('#provider-password, #provider-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw EALang.passwords_mismatch;
|
||||
throw new Error(EALang.passwords_mismatch);
|
||||
}
|
||||
|
||||
if ($('#provider-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
||||
&& $('#provider-password').val() != '') {
|
||||
&& $('#provider-password').val() !== '') {
|
||||
$('#provider-password, #provider-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw EALang.password_length_notice.replace('$number', BackendUsers.MIN_PASSWORD_LENGTH);
|
||||
throw new Error(EALang.password_length_notice.replace('$number', BackendUsers.MIN_PASSWORD_LENGTH));
|
||||
}
|
||||
|
||||
// Validate user email.
|
||||
if (!GeneralFunctions.validateEmail($('#provider-email').val())) {
|
||||
$('#provider-email').closest('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
// Check if username exists
|
||||
if ($('#provider-username').attr('already-exists') == 'true') {
|
||||
if ($('#provider-username').attr('already-exists') === 'true') {
|
||||
$('#provider-username').closest('.form-group').addClass('has-error');
|
||||
throw EALang.username_already_exists;
|
||||
throw new Error(EALang.username_already_exists);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
} catch (error) {
|
||||
$('#providers .form-message')
|
||||
.addClass('alert-danger')
|
||||
.text(message)
|
||||
.text(error.message)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
|
@ -395,7 +395,7 @@
|
|||
|
||||
$('#provider-username').val(provider.settings.username);
|
||||
$('#provider-calendar-view').val(provider.settings.calendar_view);
|
||||
if (provider.settings.notifications == true) {
|
||||
if (provider.settings.notifications === '1') {
|
||||
$('#provider-notifications').addClass('active');
|
||||
} else {
|
||||
$('#provider-notifications').removeClass('active');
|
||||
|
@ -414,7 +414,7 @@
|
|||
$('#provider-services input:checkbox').prop('checked', false);
|
||||
$.each(provider.services, function (index, serviceId) {
|
||||
$('#provider-services input:checkbox').each(function () {
|
||||
if ($(this).attr('data-id') == serviceId) {
|
||||
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)
|
||||
|
@ -446,41 +446,43 @@
|
|||
ProvidersHelper.prototype.filter = function (key, selectId, display) {
|
||||
display = display || false;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_providers';
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-providers .results').html('');
|
||||
$.each(response, function (index, provider) {
|
||||
var html = this.getFilterHtml(provider);
|
||||
$('#filter-providers .results').append(html);
|
||||
}.bind(this));
|
||||
$('#filter-providers .results').html('');
|
||||
$.each(response, function (index, provider) {
|
||||
var html = this.getFilterHtml(provider);
|
||||
$('#filter-providers .results').append(html);
|
||||
}.bind(this));
|
||||
|
||||
if (response.length == 0) {
|
||||
$('#filter-providers .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-providers .results');
|
||||
}
|
||||
if (!response.length) {
|
||||
$('#filter-providers .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-providers .results');
|
||||
}
|
||||
|
||||
if (selectId != undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -494,11 +496,9 @@
|
|||
var name = provider.first_name + ' ' + provider.last_name,
|
||||
info = provider.email;
|
||||
|
||||
info = (provider.mobile_number != '' && provider.mobile_number != null)
|
||||
? info + ', ' + provider.mobile_number : info;
|
||||
info = provider.mobile_number ? info + ', ' + provider.mobile_number : info;
|
||||
|
||||
info = (provider.phone_number != '' && provider.phone_number != null)
|
||||
? info + ', ' + provider.phone_number : info;
|
||||
info = provider.phone_number ? info + ', ' + provider.phone_number : info;
|
||||
|
||||
var html =
|
||||
'<div class="provider-row entry" data-id="' + provider.id + '">' +
|
||||
|
@ -587,7 +587,7 @@
|
|||
|
||||
// Select record in filter results.
|
||||
$('#filter-providers .provider-row').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -596,7 +596,7 @@
|
|||
// Display record in form (if display = true).
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, provider) {
|
||||
if (provider.id == id) {
|
||||
if (Number(provider.id) === Number(id)) {
|
||||
this.display(provider);
|
||||
$('#edit-provider, #delete-provider').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -194,7 +194,7 @@
|
|||
$('#secretaries').on('click', '#cancel-secretary', function () {
|
||||
var id = $('#secretary-id').val();
|
||||
this.resetForm();
|
||||
if (id != '') {
|
||||
if (id) {
|
||||
this.select(id, true);
|
||||
}
|
||||
}.bind(this));
|
||||
|
@ -208,6 +208,7 @@
|
|||
*/
|
||||
SecretariesHelper.prototype.save = function (secretary) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_secretary';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
secretary: JSON.stringify(secretary)
|
||||
|
@ -230,6 +231,7 @@
|
|||
*/
|
||||
SecretariesHelper.prototype.delete = function (id) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_secretary';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
secretary_id: id
|
||||
|
@ -257,45 +259,45 @@
|
|||
// Validate required fields.
|
||||
var missingRequired = false;
|
||||
$('#secretaries .required').each(function () {
|
||||
if ($(this).val() == '' || $(this).val() == undefined) {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
if (missingRequired) {
|
||||
throw 'Fields with * are required.';
|
||||
throw new Error('Fields with * are required.');
|
||||
}
|
||||
|
||||
// Validate passwords.
|
||||
if ($('#secretary-password').val() != $('#secretary-password-confirm').val()) {
|
||||
if ($('#secretary-password').val() !== $('#secretary-password-confirm').val()) {
|
||||
$('#secretary-password, #secretary-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw 'Passwords mismatch!';
|
||||
throw new Error('Passwords mismatch!');
|
||||
}
|
||||
|
||||
if ($('#secretary-password').val().length < BackendUsers.MIN_PASSWORD_LENGTH
|
||||
&& $('#secretary-password').val() != '') {
|
||||
&& $('#secretary-password').val() !== '') {
|
||||
$('#secretary-password, #secretary-password-confirm').closest('.form-group').addClass('has-error');
|
||||
throw 'Password must be at least ' + BackendUsers.MIN_PASSWORD_LENGTH
|
||||
+ ' characters long.';
|
||||
throw new Error('Password must be at least ' + BackendUsers.MIN_PASSWORD_LENGTH
|
||||
+ ' characters long.');
|
||||
}
|
||||
|
||||
// Validate user email.
|
||||
if (!GeneralFunctions.validateEmail($('#secretary-email').val())) {
|
||||
$('#secretary-email').closest('.form-group').addClass('has-error');
|
||||
throw 'Invalid email address!';
|
||||
throw new Error('Invalid email address!');
|
||||
}
|
||||
|
||||
// Check if username exists
|
||||
if ($('#secretary-username').attr('already-exists') == 'true') {
|
||||
if ($('#secretary-username').attr('already-exists') === 'true') {
|
||||
$('#secretary-username').closest('.form-group').addClass('has-error');
|
||||
throw 'Username already exists.';
|
||||
throw new Error('Username already exists.');
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (message) {
|
||||
} catch (error) {
|
||||
$('#secretaries .form-message')
|
||||
.addClass('alert-danger')
|
||||
.text(message)
|
||||
.text(error.message)
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
|
@ -344,7 +346,7 @@
|
|||
|
||||
$('#secretary-username').val(secretary.settings.username);
|
||||
$('#secretary-calendar-view').val(secretary.settings.calendar_view);
|
||||
if (secretary.settings.notifications == true) {
|
||||
if (secretary.settings.notifications === '1') {
|
||||
$('#secretary-notifications').addClass('active');
|
||||
} else {
|
||||
$('#secretary-notifications').removeClass('active');
|
||||
|
@ -353,7 +355,7 @@
|
|||
$('#secretary-providers input:checkbox').prop('checked', false);
|
||||
$.each(secretary.providers, function (index, providerId) {
|
||||
$('#secretary-providers input:checkbox').each(function () {
|
||||
if ($(this).attr('data-id') == providerId) {
|
||||
if (Number($(this).attr('data-id')) === Number(providerId)) {
|
||||
$(this).prop('checked', true);
|
||||
}
|
||||
});
|
||||
|
@ -371,41 +373,44 @@
|
|||
SecretariesHelper.prototype.filter = function (key, selectId, display) {
|
||||
display = display || false;
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_secretaries';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_secretaries';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
key: key,
|
||||
limit: this.filterLimit
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
this.filterResults = response;
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
this.filterResults = response;
|
||||
|
||||
$('#filter-secretaries .results').html('');
|
||||
$.each(response, function (index, secretary) {
|
||||
var html = this.getFilterHtml(secretary);
|
||||
$('#filter-secretaries .results').append(html);
|
||||
}.bind(this));
|
||||
$('#filter-secretaries .results').html('');
|
||||
$.each(response, function (index, secretary) {
|
||||
var html = this.getFilterHtml(secretary);
|
||||
$('#filter-secretaries .results').append(html);
|
||||
}.bind(this));
|
||||
|
||||
if (response.length == 0) {
|
||||
$('#filter-secretaries .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-secretaries .results');
|
||||
}
|
||||
if (!response.length) {
|
||||
$('#filter-secretaries .results').html('<em>' + EALang.no_records_found + '</em>')
|
||||
} else if (response.length === this.filterLimit) {
|
||||
$('<button/>', {
|
||||
'type': 'button',
|
||||
'class': 'well btn-block load-more text-center',
|
||||
'text': EALang.load_more,
|
||||
'click': function () {
|
||||
this.filterLimit += 20;
|
||||
this.filter(key, selectId, display);
|
||||
}.bind(this)
|
||||
})
|
||||
.appendTo('#filter-secretaries .results');
|
||||
}
|
||||
|
||||
if (selectId != undefined) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
if (selectId) {
|
||||
this.select(selectId, display);
|
||||
}
|
||||
}.bind(this))
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -419,11 +424,9 @@
|
|||
var name = secretary.first_name + ' ' + secretary.last_name;
|
||||
var info = secretary.email;
|
||||
|
||||
info = (secretary.mobile_number != '' && secretary.mobile_number != null)
|
||||
? info + ', ' + secretary.mobile_number : info;
|
||||
info = secretary.mobile_number ? info + ', ' + secretary.mobile_number : info;
|
||||
|
||||
info = (secretary.phone_number != '' && secretary.phone_number != null)
|
||||
? info + ', ' + secretary.phone_number : info;
|
||||
info = secretary.phone_number ? info + ', ' + secretary.phone_number : info;
|
||||
|
||||
var html =
|
||||
'<div class="secretary-row entry" data-id="' + secretary.id + '">' +
|
||||
|
@ -447,7 +450,7 @@
|
|||
$('#filter-secretaries .selected').removeClass('selected');
|
||||
|
||||
$('#filter-secretaries .secretary-row').each(function () {
|
||||
if ($(this).attr('data-id') == id) {
|
||||
if (Number($(this).attr('data-id')) === Number(id)) {
|
||||
$(this).addClass('selected');
|
||||
return false;
|
||||
}
|
||||
|
@ -455,7 +458,7 @@
|
|||
|
||||
if (display) {
|
||||
$.each(this.filterResults, function (index, admin) {
|
||||
if (admin.id == id) {
|
||||
if (Number(admin.id) === Number(id)) {
|
||||
this.display(admin);
|
||||
$('#edit-secretary, #delete-secretary').prop('disabled', false);
|
||||
return false;
|
||||
|
|
|
@ -57,7 +57,7 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
bindEventHandlers = bindEventHandlers || true;
|
||||
manageMode = manageMode || false;
|
||||
|
||||
if (window.console === undefined) {
|
||||
if (window.console) {
|
||||
window.console = function () {
|
||||
}; // IE compatibility
|
||||
}
|
||||
|
@ -230,14 +230,13 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
* become visible.
|
||||
*/
|
||||
$('#select-service').change(function () {
|
||||
var currServiceId = $('#select-service').val();
|
||||
var serviceId = $('#select-service').val();
|
||||
$('#select-provider').empty();
|
||||
|
||||
$.each(GlobalVariables.availableProviders, function (indexProvider, provider) {
|
||||
$.each(provider.services, function (indexService, serviceId) {
|
||||
// If the current provider is able to provide the selected service,
|
||||
// add him to the listbox.
|
||||
if (serviceId == currServiceId) {
|
||||
$.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>';
|
||||
|
@ -266,15 +265,15 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
$('.button-next').click(function () {
|
||||
// If we are on the first step and there is not provider selected do not continue
|
||||
// with the next step.
|
||||
if ($(this).attr('data-step_index') === '1' && $('#select-provider').val() == null) {
|
||||
if ($(this).attr('data-step_index') === '1' && !$('#select-provider').val()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are on the 2nd tab then the user should have an appointment hour
|
||||
// selected.
|
||||
if ($(this).attr('data-step_index') === '2') {
|
||||
if ($('.selected-hour').length == 0) {
|
||||
if ($('#select-hour-prompt').length == 0) {
|
||||
if (!$('.selected-hour').length) {
|
||||
if (!$('#select-hour-prompt').length) {
|
||||
$('#available-hours').append('<br><br>'
|
||||
+ '<span id="select-hour-prompt" class="text-danger">'
|
||||
+ EALang.appointment_hour_missing
|
||||
|
@ -466,37 +465,37 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
// Validate required fields.
|
||||
var missingRequiredField = false;
|
||||
$('.required').each(function () {
|
||||
if ($(this).val() == '') {
|
||||
if (!$(this).val()) {
|
||||
$(this).parents('.form-group').addClass('has-error');
|
||||
missingRequiredField = true;
|
||||
}
|
||||
});
|
||||
if (missingRequiredField) {
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
var $acceptToTermsAndConditions = $('#accept-to-terms-and-conditions');
|
||||
if ($acceptToTermsAndConditions.length && !$acceptToTermsAndConditions.prop('checked')) {
|
||||
$acceptToTermsAndConditions.parents('label').addClass('text-danger');
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
var $acceptToPrivacyPolicy = $('#accept-to-privacy-policy');
|
||||
if ($acceptToPrivacyPolicy.length && !$acceptToPrivacyPolicy.prop('checked')) {
|
||||
$acceptToPrivacyPolicy.parents('label').addClass('text-danger');
|
||||
throw EALang.fields_are_required;
|
||||
throw new Error(EALang.fields_are_required);
|
||||
}
|
||||
|
||||
|
||||
// Validate email address.
|
||||
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
||||
$('#email').parents('.form-group').addClass('has-error');
|
||||
throw EALang.invalid_email;
|
||||
throw new Error(EALang.invalid_email);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (exc) {
|
||||
$('#form-message').text(exc);
|
||||
} catch (error) {
|
||||
$('#form-message').text(error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +516,12 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
selectedDate = GeneralFunctions.formatDate(selectedDate, GlobalVariables.dateFormat);
|
||||
}
|
||||
|
||||
var selServiceId = $('#select-service').val();
|
||||
var serviceId = $('#select-service').val();
|
||||
var servicePrice = '';
|
||||
var serviceCurrency = '';
|
||||
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (service.id == selServiceId && service.price != '' && service.price != null && service.price != '0.00' && service.price != '0,00') {
|
||||
if (Number(service.id) === Number(serviceId) && Number(service.price) > 0) {
|
||||
servicePrice = '<br>' + service.price;
|
||||
serviceCurrency = service.currency;
|
||||
return false; // break loop
|
||||
|
@ -568,9 +567,9 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
|
||||
// Update appointment form data for submission to server when the user confirms
|
||||
// the appointment.
|
||||
var postData = {};
|
||||
var data = {};
|
||||
|
||||
postData.customer = {
|
||||
data.customer = {
|
||||
last_name: $('#last-name').val(),
|
||||
first_name: $('#first-name').val(),
|
||||
email: $('#email').val(),
|
||||
|
@ -581,7 +580,7 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
timezone: $('#select-timezone').val()
|
||||
};
|
||||
|
||||
postData.appointment = {
|
||||
data.appointment = {
|
||||
start_datetime: $('#select-date').datepicker('getDate').toString('yyyy-MM-dd')
|
||||
+ ' ' + Date.parse($('.selected-hour').text()).toString('HH:mm') + ':00',
|
||||
end_datetime: _calcEndDatetime(),
|
||||
|
@ -591,14 +590,14 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
id_services: $('#select-service').val()
|
||||
};
|
||||
|
||||
postData.manage_mode = FrontendBook.manageMode;
|
||||
data.manage_mode = FrontendBook.manageMode;
|
||||
|
||||
if (FrontendBook.manageMode) {
|
||||
postData.appointment.id = GlobalVariables.appointmentData.id;
|
||||
postData.customer.id = GlobalVariables.customerData.id;
|
||||
data.appointment.id = GlobalVariables.appointmentData.id;
|
||||
data.customer.id = GlobalVariables.customerData.id;
|
||||
}
|
||||
$('input[name="csrfToken"]').val(GlobalVariables.csrfToken);
|
||||
$('input[name="post_data"]').val(JSON.stringify(postData));
|
||||
$('input[name="post_data"]').val(JSON.stringify(data));
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -609,12 +608,13 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
*/
|
||||
function _calcEndDatetime() {
|
||||
// Find selected service duration.
|
||||
var selServiceDuration = undefined;
|
||||
var serviceId = $('#select-service').val();
|
||||
var serviceDuration;
|
||||
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (service.id == $('#select-service').val()) {
|
||||
selServiceDuration = service.duration;
|
||||
return false; // Stop searching ...
|
||||
if (Number(service.id) === Number(serviceId)) {
|
||||
serviceDuration = service.duration;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -622,10 +622,10 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
var startDatetime = $('#select-date').datepicker('getDate').toString('dd-MM-yyyy')
|
||||
+ ' ' + Date.parse($('.selected-hour').text()).toString('HH:mm');
|
||||
startDatetime = Date.parseExact(startDatetime, 'dd-MM-yyyy HH:mm');
|
||||
var endDatetime = undefined;
|
||||
var endDatetime;
|
||||
|
||||
if (selServiceDuration !== undefined && startDatetime !== null) {
|
||||
endDatetime = startDatetime.add({'minutes': parseInt(selServiceDuration)});
|
||||
if (serviceDuration && startDatetime) {
|
||||
endDatetime = startDatetime.add({'minutes': parseInt(serviceDuration)});
|
||||
} else {
|
||||
endDatetime = new Date();
|
||||
}
|
||||
|
@ -687,22 +687,22 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
var html = '';
|
||||
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (service.id == serviceId) { // Just found the service.
|
||||
if (Number(service.id) === Number(serviceId)) {
|
||||
html = '<strong>' + service.name + ' </strong>';
|
||||
|
||||
if (service.description != '' && service.description != null) {
|
||||
if (service.description) {
|
||||
html += '<br>' + service.description + '<br>';
|
||||
}
|
||||
|
||||
if (service.duration != '' && service.duration != null) {
|
||||
if (service.duration) {
|
||||
html += '[' + EALang.duration + ' ' + service.duration + ' ' + EALang.minutes + ']';
|
||||
}
|
||||
|
||||
if (service.price != '' && service.price != null && service.price != '0.00' && service.price != '0,00') {
|
||||
if (Number(service.price) > 0) {
|
||||
html += '[' + EALang.price + ' ' + service.price + ' ' + service.currency + ']';
|
||||
}
|
||||
|
||||
if (service.location != '' && service.location != null) {
|
||||
if (service.location) {
|
||||
html += '[' + EALang.location + ' ' + service.location + ']';
|
||||
}
|
||||
|
||||
|
@ -712,13 +712,9 @@ window.FrontendBook = window.FrontendBook || {};
|
|||
}
|
||||
});
|
||||
|
||||
$div.html(html);
|
||||
|
||||
if (html != '') {
|
||||
$div.show();
|
||||
} else {
|
||||
$div.hide();
|
||||
}
|
||||
$div
|
||||
.html(html)
|
||||
.toggle(html);
|
||||
}
|
||||
|
||||
})(window.FrontendBook);
|
||||
|
|
|
@ -37,90 +37,101 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
exports.getAvailableHours = function (selDate) {
|
||||
$('#available-hours').empty();
|
||||
|
||||
// Find the selected service duration (it is going to be send within the "postData" object).
|
||||
var selServiceDuration = 15; // Default value of duration (in minutes).
|
||||
$.each(GlobalVariables.availableServices, function (index, service) {
|
||||
if (service.id == $('#select-service').val()) {
|
||||
selServiceDuration = service.duration;
|
||||
}
|
||||
});
|
||||
// Find the selected service duration (it is going to be send within the "data" object).
|
||||
var serviceId = $('#select-service').val();
|
||||
|
||||
// Default value of duration (in minutes).
|
||||
var serviceDuration = 15;
|
||||
|
||||
var service = GlobalVariables.availableServices.filter(function(availableService) {
|
||||
return Number(availableService.id) === Number(serviceId);
|
||||
}).shift();
|
||||
|
||||
if (service) {
|
||||
serviceDuration = service.duration;
|
||||
}
|
||||
|
||||
// If the manage mode is true then the appointment's start date should return as available too.
|
||||
var appointmentId = FrontendBook.manageMode ? GlobalVariables.appointmentData.id : undefined;
|
||||
var appointmentId = FrontendBook.manageMode ? GlobalVariables.appointmentData.id : null;
|
||||
|
||||
// Make ajax post request and get the available hours.
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_hours';
|
||||
var postData = {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_hours';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
service_id: $('#select-service').val(),
|
||||
provider_id: $('#select-provider').val(),
|
||||
selected_date: selDate,
|
||||
service_duration: selServiceDuration,
|
||||
service_duration: serviceDuration,
|
||||
manage_mode: FrontendBook.manageMode,
|
||||
appointment_id: appointmentId
|
||||
};
|
||||
|
||||
$.post(postUrl, postData, function (response) {
|
||||
// The response contains the available hours for the selected provider and
|
||||
// service. Fill the available hours div with response data.
|
||||
if (response.length > 0) {
|
||||
var providerId = $('#select-provider').val();
|
||||
$.post(url, data)
|
||||
.done(function (response) {
|
||||
// The response contains the available hours for the selected provider and
|
||||
// service. Fill the available hours div with response data.
|
||||
if (response.length > 0) {
|
||||
var providerId = $('#select-provider').val();
|
||||
|
||||
if (providerId === 'any-provider') {
|
||||
providerId = GlobalVariables.availableProviders[0].id; // Use first available provider.
|
||||
}
|
||||
|
||||
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
|
||||
return providerId == availableProvider.id;
|
||||
}).shift();
|
||||
|
||||
if (!provider) {
|
||||
throw new Error('Could not find provider.');
|
||||
}
|
||||
|
||||
var providerTimezone = provider.timezone;
|
||||
|
||||
var selectedTimezone = $('#select-timezone').val();
|
||||
|
||||
var currColumn = 1;
|
||||
|
||||
$('#available-hours').html('<div style="width:80px; float:left;"></div>');
|
||||
|
||||
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm a' : 'HH:mm';
|
||||
|
||||
$.each(response, function (index, availableHour) {
|
||||
if ((currColumn * 10) < (index + 1)) {
|
||||
currColumn++;
|
||||
$('#available-hours').append('<div style="width:80px; float:left;"></div>');
|
||||
if (providerId === 'any-provider') {
|
||||
providerId = GlobalVariables.availableProviders[0].id; // Use first available provider.
|
||||
}
|
||||
|
||||
var availableHourMoment = moment
|
||||
.tz(selDate + ' ' + availableHour + ':00', providerTimezone)
|
||||
.tz(selectedTimezone);
|
||||
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
|
||||
return Number(providerId) === Number(availableProvider.id);
|
||||
}).shift();
|
||||
|
||||
$('#available-hours div:eq(' + (currColumn - 1) + ')').append(
|
||||
'<span class="available-hour">' + availableHourMoment.format(timeFormat) + '</span><br/>');
|
||||
});
|
||||
if (!provider) {
|
||||
throw new Error('Could not find provider.');
|
||||
}
|
||||
|
||||
var providerTimezone = provider.timezone;
|
||||
|
||||
var selectedTimezone = $('#select-timezone').val();
|
||||
|
||||
var currColumn = 1;
|
||||
|
||||
$('#available-hours').html('<div style="width:80px; float:left;"></div>');
|
||||
|
||||
var timeFormat = GlobalVariables.timeFormat === 'regular' ? 'h:mm a' : 'HH:mm';
|
||||
|
||||
response.forEach(function (availableHour, index) {
|
||||
if ((currColumn * 10) < (index + 1)) {
|
||||
currColumn++;
|
||||
$('#available-hours').append('<div style="width:80px; float:left;"></div>');
|
||||
}
|
||||
|
||||
var availableHourMoment = moment
|
||||
.tz(selDate + ' ' + availableHour + ':00', providerTimezone)
|
||||
.tz(selectedTimezone);
|
||||
|
||||
$('#available-hours div:eq(' + (currColumn - 1) + ')').append(
|
||||
'<span class="available-hour">' + availableHourMoment.format(timeFormat) + '</span><br/>');
|
||||
});
|
||||
|
||||
if (FrontendBook.manageMode) {
|
||||
// Set the appointment's start time as the default selection.
|
||||
$('.available-hour')
|
||||
.removeClass('selected-hour')
|
||||
.filter(function () {
|
||||
return $(this).text() === Date.parseExact(
|
||||
GlobalVariables.appointmentData.start_datetime,
|
||||
'yyyy-MM-dd HH:mm:ss').toString(timeFormat);
|
||||
})
|
||||
.addClass('selected-hour');
|
||||
} else {
|
||||
// Set the first available hour as the default selection.
|
||||
$('.available-hour:eq(0)').addClass('selected-hour');
|
||||
}
|
||||
|
||||
FrontendBook.updateConfirmFrame();
|
||||
|
||||
if (FrontendBook.manageMode) {
|
||||
// Set the appointment's start time as the default selection.
|
||||
$('.available-hour').removeClass('selected-hour');
|
||||
$('.available-hour').filter(function () {
|
||||
return $(this).text() === Date.parseExact(
|
||||
GlobalVariables.appointmentData.start_datetime,
|
||||
'yyyy-MM-dd HH:mm:ss').toString(timeFormat);
|
||||
}).addClass('selected-hour');
|
||||
} else {
|
||||
// Set the first available hour as the default selection.
|
||||
$('.available-hour:eq(0)').addClass('selected-hour');
|
||||
$('#available-hours').text(EALang.no_available_hours);
|
||||
}
|
||||
|
||||
FrontendBook.updateConfirmFrame();
|
||||
|
||||
} else {
|
||||
$('#available-hours').text(EALang.no_available_hours);
|
||||
}
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -141,26 +152,27 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
}
|
||||
|
||||
var formData = jQuery.parseJSON($('input[name="post_data"]').val());
|
||||
var postData = {
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
post_data: formData
|
||||
};
|
||||
|
||||
if ($captchaText.length > 0) {
|
||||
postData.captcha = $captchaText.val();
|
||||
data.captcha = $captchaText.val();
|
||||
}
|
||||
|
||||
if (GlobalVariables.manageMode) {
|
||||
postData.exclude_appointment_id = GlobalVariables.appointmentData.id;
|
||||
data.exclude_appointment_id = GlobalVariables.appointmentData.id;
|
||||
}
|
||||
|
||||
var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_register_appointment';
|
||||
var url = GlobalVariables.baseUrl + '/index.php/appointments/ajax_register_appointment';
|
||||
|
||||
var $layer = $('<div/>');
|
||||
|
||||
$.ajax({
|
||||
url: postUrl,
|
||||
url: url,
|
||||
method: 'post',
|
||||
data: postData,
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
beforeSend: function (jqxhr, settings) {
|
||||
$layer
|
||||
|
@ -221,9 +233,10 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
return;
|
||||
}
|
||||
|
||||
var appointmentId = FrontendBook.manageMode ? GlobalVariables.appointmentData.id : undefined;
|
||||
var appointmentId = FrontendBook.manageMode ? GlobalVariables.appointmentData.id : null;
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_unavailable_dates';
|
||||
|
||||
var data = {
|
||||
provider_id: providerId,
|
||||
service_id: serviceId,
|
||||
|
@ -279,7 +292,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
// Grey out unavailable dates.
|
||||
$('#select-date .ui-datepicker-calendar td:not(.ui-datepicker-other-month)').each(function (index, td) {
|
||||
selectedDate.set({day: index + 1});
|
||||
if ($.inArray(selectedDate.toString('yyyy-MM-dd'), unavailableDates) != -1) {
|
||||
if (unavailableDates.indexOf(selectedDate.toString('yyyy-MM-dd')) !== -1) {
|
||||
$(td).addClass('ui-datepicker-unselectable ui-state-disabled');
|
||||
}
|
||||
});
|
||||
|
@ -294,6 +307,7 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
*/
|
||||
exports.saveConsent = function (consent) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/consents/ajax_save_consent';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
consent: consent
|
||||
|
@ -309,14 +323,17 @@ window.FrontendBookApi = window.FrontendBookApi || {};
|
|||
*/
|
||||
exports.deletePersonalInformation = function (customerToken) {
|
||||
var url = GlobalVariables.baseUrl + '/index.php/privacy/ajax_delete_personal_information';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
customer_token: customerToken
|
||||
};
|
||||
|
||||
$.post(url, data, function (response) {
|
||||
location.href = GlobalVariables.baseUrl;
|
||||
}, 'json').fail(GeneralFunctions.ajaxFailureHandler);
|
||||
$.post(url, data)
|
||||
.done(function () {
|
||||
location.href = GlobalVariables.baseUrl;
|
||||
})
|
||||
.fail(GeneralFunctions.ajaxFailureHandler);
|
||||
};
|
||||
|
||||
})(window.FrontendBookApi);
|
||||
|
|
|
@ -37,7 +37,7 @@ $(document).ready(function () {
|
|||
function handleAuthResult(authResult) {
|
||||
try {
|
||||
if (authResult.error) {
|
||||
throw 'Could not authorize user.';
|
||||
throw new Error('Could not authorize user.');
|
||||
}
|
||||
|
||||
// The user has granted access, add the appointment to his calendar.
|
||||
|
@ -79,7 +79,7 @@ $(document).ready(function () {
|
|||
|
||||
request.execute(function (response) {
|
||||
if (response.error) {
|
||||
throw 'Could not add the event to Google Calendar.';
|
||||
throw new Error('Could not add the event to Google Calendar.');
|
||||
}
|
||||
|
||||
$('#success-frame').append(
|
||||
|
@ -98,14 +98,14 @@ $(document).ready(function () {
|
|||
$('#add-to-google-calendar').hide();
|
||||
});
|
||||
});
|
||||
} catch (exc) {
|
||||
} catch (error) {
|
||||
// The user denied access or something else happened, display corresponding message on the screen.
|
||||
$('#success-frame').append(
|
||||
'<div class="alert alert-danger col-xs-12">' +
|
||||
'<h4>' + EALang.oops_something_went_wrong + '</h4>' +
|
||||
'<p>' +
|
||||
EALang.could_not_add_to_google_calendar +
|
||||
'<pre>' + exc + '</pre>' +
|
||||
'<pre>' + error.message + '</pre>' +
|
||||
'</p>' +
|
||||
'</div>');
|
||||
}
|
||||
|
|
|
@ -31,15 +31,15 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
* @param {Array} buttons Contains the dialog buttons along with their functions.
|
||||
*/
|
||||
exports.displayMessageBox = function (title, message, buttons) {
|
||||
if (title === undefined || title === '') {
|
||||
if (!title) {
|
||||
title = '- No Title Provided -';
|
||||
}
|
||||
|
||||
if (message === undefined || message === '') {
|
||||
if (!message) {
|
||||
message = '- No Message Provided -';
|
||||
}
|
||||
|
||||
if (buttons === undefined) {
|
||||
if (!buttons) {
|
||||
buttons = [
|
||||
{
|
||||
text: EALang.close,
|
||||
|
@ -170,19 +170,22 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
*/
|
||||
exports.clone = function (originalObject) {
|
||||
// Handle the 3 simple types, and null or undefined
|
||||
if (null == originalObject || 'object' != typeof originalObject)
|
||||
if (!originalObject || typeof originalObject !== 'object') {
|
||||
return originalObject;
|
||||
}
|
||||
|
||||
var copy;
|
||||
|
||||
// Handle Date
|
||||
if (originalObject instanceof Date) {
|
||||
var copy = new Date();
|
||||
copy = new Date();
|
||||
copy.setTime(originalObject.getTime());
|
||||
return copy;
|
||||
}
|
||||
|
||||
// Handle Array
|
||||
if (originalObject instanceof Array) {
|
||||
var copy = [];
|
||||
copy = [];
|
||||
for (var i = 0, len = originalObject.length; i < len; i++) {
|
||||
copy[i] = GeneralFunctions.clone(originalObject[i]);
|
||||
}
|
||||
|
@ -191,7 +194,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
|
||||
// Handle Object
|
||||
if (originalObject instanceof Object) {
|
||||
var copy = {};
|
||||
copy = {};
|
||||
for (var attr in originalObject) {
|
||||
if (originalObject.hasOwnProperty(attr))
|
||||
copy[attr] = GeneralFunctions.clone(originalObject[attr]);
|
||||
|
@ -309,10 +312,12 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
$(document).on('click', 'li.language', function () {
|
||||
// Change language with ajax call and refresh page.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_change_language';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
language: $(this).attr('data-language')
|
||||
};
|
||||
|
||||
$.post(url, data)
|
||||
done(function () {
|
||||
document.location.reload(true);
|
||||
|
|
|
@ -14,6 +14,7 @@ $(function () {
|
|||
|
||||
var MIN_PASSWORD_LENGTH = 7;
|
||||
|
||||
var $install = $('#install');
|
||||
var $alert = $('.alert');
|
||||
|
||||
$(document).ajaxStart(function () {
|
||||
|
@ -27,12 +28,13 @@ $(function () {
|
|||
/**
|
||||
* Event: Install Easy!Appointments Button "Click"
|
||||
*/
|
||||
$('#install').click(function () {
|
||||
$install.click(function () {
|
||||
if (!validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/installation/ajax_install';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
admin: getAdminData(),
|
||||
|
@ -75,45 +77,45 @@ $(function () {
|
|||
// Check for empty fields.
|
||||
var missingRequired = false;
|
||||
$('input').each(function () {
|
||||
if ($(this).val() == '') {
|
||||
if (!$(this).val()) {
|
||||
$(this).closest('.form-group').addClass('has-error');
|
||||
missingRequired = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (missingRequired) {
|
||||
throw 'All the page fields are required.';
|
||||
throw new Error('All the page fields are required.');
|
||||
}
|
||||
|
||||
// Validate Passwords
|
||||
if ($('#password').val() != $('#retype-password').val()) {
|
||||
if ($('#password').val() !== $('#retype-password').val()) {
|
||||
$('#password').closest('.form-group').addClass('has-error');
|
||||
$('#retype-password').closest('.form-group').addClass('has-error');
|
||||
throw 'Passwords do not match!';
|
||||
throw new Error('Passwords do not match!');
|
||||
}
|
||||
|
||||
if ($('#password').val().length < MIN_PASSWORD_LENGTH) {
|
||||
$('#password').closest('.form-group').addClass('has-error');
|
||||
$('#retype-password').closest('.form-group').addClass('has-error');
|
||||
throw 'The password must be at least ' + MIN_PASSWORD_LENGTH + ' characters long.';
|
||||
throw new Error('The password must be at least ' + MIN_PASSWORD_LENGTH + ' characters long.');
|
||||
}
|
||||
|
||||
// Validate Email
|
||||
if (!GeneralFunctions.validateEmail($('#email').val())) {
|
||||
$('#email').closest('.form-group').addClass('has-error');
|
||||
throw 'The email address is invalid!';
|
||||
throw new Error('The email address is invalid!');
|
||||
}
|
||||
|
||||
if (!GeneralFunctions.validateEmail($('#company-email').val())) {
|
||||
$('#company-email').closest('.form-group').addClass('has-error');
|
||||
throw 'The email address is invalid!';
|
||||
throw new Error('The email address is invalid!');
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
$alert
|
||||
.addClass('alert-danger')
|
||||
.text(error)
|
||||
.text(error.message)
|
||||
.show();
|
||||
|
||||
return false;
|
||||
|
@ -126,7 +128,7 @@ $(function () {
|
|||
* @return {Object}
|
||||
*/
|
||||
function getAdminData() {
|
||||
var admin = {
|
||||
return {
|
||||
first_name: $('#first-name').val(),
|
||||
last_name: $('#last-name').val(),
|
||||
email: $('#email').val(),
|
||||
|
@ -134,8 +136,6 @@ $(function () {
|
|||
username: $('#username').val(),
|
||||
password: $('#password').val()
|
||||
};
|
||||
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -144,20 +144,18 @@ $(function () {
|
|||
* @return {Object}
|
||||
*/
|
||||
function getCompanyData() {
|
||||
var company = {
|
||||
return {
|
||||
company_name: $('#company-name').val(),
|
||||
company_email: $('#company-email').val(),
|
||||
company_link: $('#company-link').val()
|
||||
};
|
||||
|
||||
return company;
|
||||
}
|
||||
|
||||
// Validate the base URL setting (must not contain any trailing slash).
|
||||
if (GlobalVariables.baseUrl.slice(-1) === '/') {
|
||||
GeneralFunctions.displayMessageBox('Misconfiguration Detected', 'Please remove any trailing slashes from your '
|
||||
+ 'BASE_URL setting of the root config.php file and try again.');
|
||||
$('#install')
|
||||
GeneralFunctions.displayMessageBox('Misconfiguration Detected', 'Please remove any trailing '
|
||||
+ 'slashes from your BASE_URL setting of the root config.php file and try again.');
|
||||
$install
|
||||
.prop('disabled', true)
|
||||
.fadeTo('0.4');
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ $(function () {
|
|||
event.preventDefault();
|
||||
|
||||
var url = GlobalVariables.baseUrl + '/index.php/user/ajax_check_login';
|
||||
|
||||
var data = {
|
||||
'csrfToken': GlobalVariables.csrfToken,
|
||||
'username': $('#username').val(),
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
|
||||
$('.working-plan tbody').append(tr);
|
||||
|
||||
if (workingDay != null) {
|
||||
if (workingDay) {
|
||||
$('#' + index).prop('checked', true);
|
||||
$('#' + index + '-start').val(Date.parse(workingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
$('#' + index + '-end').val(Date.parse(workingDay.end).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
|
@ -125,7 +125,7 @@
|
|||
*/
|
||||
WorkingPlan.prototype.setupExtraPeriods = function (extraWorkingPlan) {
|
||||
$.each(extraWorkingPlan, function (index, extraWorkingDay) {
|
||||
if (extraWorkingDay != null) {
|
||||
if (extraWorkingDay) {
|
||||
|
||||
$('#' + index).prop('checked', true);
|
||||
$('#' + index + '-start').val(Date.parse(extraWorkingDay.start).toString(GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm').toUpperCase());
|
||||
|
@ -245,10 +245,10 @@
|
|||
*
|
||||
* Enable or disable the time selection for each day.
|
||||
*/
|
||||
$('.working-plan tbody').on( "click", "input:checkbox", function (event) {
|
||||
$('.working-plan tbody').on( "click", "input:checkbox", function () {
|
||||
var id = $(this).attr('id');
|
||||
|
||||
if ($(this).prop('checked') == true) {
|
||||
if ($(this).prop('checked') === true) {
|
||||
$('#' + id + '-start').prop('disabled', false).val('9:00 AM');
|
||||
$('#' + id + '-end').prop('disabled', false).val('6:00 PM');
|
||||
} else {
|
||||
|
@ -303,7 +303,7 @@
|
|||
// Reset previous editable tds
|
||||
var $previousEdt = $(this).closest('table').find('.editable').get();
|
||||
$.each($previousEdt, function (index, editable) {
|
||||
if (editable.reset !== undefined) {
|
||||
if (editable.reset) {
|
||||
editable.reset();
|
||||
}
|
||||
});
|
||||
|
@ -436,7 +436,7 @@
|
|||
// Reset previous editable tds
|
||||
var $previousEdt = $(this).closest('table').find('.editable').get();
|
||||
$.each($previousEdt, function (index, editable) {
|
||||
if (editable.reset !== undefined) {
|
||||
if (editable.reset) {
|
||||
editable.reset();
|
||||
}
|
||||
});
|
||||
|
@ -565,7 +565,7 @@
|
|||
var workingPlan = {};
|
||||
$('.working-plan input:checkbox').each(function (index, checkbox) {
|
||||
var id = $(checkbox).attr('id');
|
||||
if ($(checkbox).prop('checked') == true) {
|
||||
if ($(checkbox).prop('checked') === true) {
|
||||
workingPlan[id] = {
|
||||
start: Date.parse($('#' + id + '-start').val()).toString('HH:mm'),
|
||||
end: Date.parse($('#' + id + '-end').val()).toString('HH:mm'),
|
||||
|
@ -575,7 +575,7 @@
|
|||
$('.breaks tr').each(function (index, tr) {
|
||||
var day = this.convertDayToValue($(tr).find('.break-day').text());
|
||||
|
||||
if (day == id) {
|
||||
if (day === id) {
|
||||
var start = $(tr).find('.break-start').text();
|
||||
var end = $(tr).find('.break-end').text();
|
||||
|
||||
|
@ -626,12 +626,12 @@
|
|||
/**
|
||||
* Enables or disables the timepicker functionality from the working plan input text fields.
|
||||
*
|
||||
* @param {Boolean} disabled (OPTIONAL = false) If true then the timepickers will be disabled.
|
||||
* @param {Boolean} [disabled] If true then the timepickers will be disabled.
|
||||
*/
|
||||
WorkingPlan.prototype.timepickers = function (disabled) {
|
||||
disabled = disabled || false;
|
||||
|
||||
if (disabled == false) {
|
||||
if (disabled === false) {
|
||||
// Set timepickers where needed.
|
||||
$('.working-plan input:text').timepicker({
|
||||
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm tt' : 'HH:mm',
|
||||
|
|
Loading…
Reference in a new issue