2016-07-17 15:43:50 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2018-03-27 10:23:09 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2018, Alex Tselegidis
|
2016-07-17 15:43:50 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Backend Calendar Appointments Modal
|
|
|
|
*
|
|
|
|
* This module implements the appointments modal functionality.
|
|
|
|
*
|
|
|
|
* @module BackendCalendarAppointmentsModal
|
|
|
|
*/
|
|
|
|
window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModal || {};
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
(function (exports) {
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function _bindEventHandlers() {
|
|
|
|
/**
|
|
|
|
* Event: Manage Appointments Dialog Cancel Button "Click"
|
|
|
|
*
|
|
|
|
* Closes the dialog without saving any changes to the database.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#manage-appointment #cancel-appointment').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
$('#manage-appointment').modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Manage Appointments Dialog Save Button "Click"
|
|
|
|
*
|
|
|
|
* Stores the appointment changes or inserts a new appointment depending the dialog mode.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#manage-appointment #save-appointment').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
// Before doing anything the appointment data need to be validated.
|
|
|
|
if (!_validateAppointmentForm()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare appointment data for AJAX request.
|
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
|
|
|
|
// ID must exist on the object in order for the model to update the record and not to perform
|
|
|
|
// an insert operation.
|
|
|
|
|
2016-10-24 00:12:19 +03:00
|
|
|
var startDatetime = $dialog.find('#start-datetime').datetimepicker('getDate').toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
var endDatetime = $dialog.find('#end-datetime').datetimepicker('getDate').toString('yyyy-MM-dd HH:mm:ss');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
var appointment = {
|
|
|
|
id_services: $dialog.find('#select-service').val(),
|
|
|
|
id_users_provider: $dialog.find('#select-provider').val(),
|
|
|
|
start_datetime: startDatetime,
|
|
|
|
end_datetime: endDatetime,
|
2019-06-08 17:43:21 +03:00
|
|
|
location: $dialog.find('#appointment-location').val(),
|
2016-07-17 15:43:50 +03:00
|
|
|
notes: $dialog.find('#appointment-notes').val(),
|
|
|
|
is_unavailable: false
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($dialog.find('#appointment-id').val() !== '') {
|
|
|
|
// Set the id value, only if we are editing an appointment.
|
2017-11-02 16:19:54 +03:00
|
|
|
appointment.id = $dialog.find('#appointment-id').val();
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var customer = {
|
|
|
|
first_name: $dialog.find('#first-name').val(),
|
|
|
|
last_name: $dialog.find('#last-name').val(),
|
|
|
|
email: $dialog.find('#email').val(),
|
|
|
|
phone_number: $dialog.find('#phone-number').val(),
|
|
|
|
address: $dialog.find('#address').val(),
|
|
|
|
city: $dialog.find('#city').val(),
|
|
|
|
zip_code: $dialog.find('#zip-code').val(),
|
|
|
|
notes: $dialog.find('#customer-notes').val()
|
|
|
|
};
|
|
|
|
|
|
|
|
if ($dialog.find('#customer-id').val() !== '') {
|
|
|
|
// Set the id value, only if we are editing an appointment.
|
2017-11-02 16:19:54 +03:00
|
|
|
customer.id = $dialog.find('#customer-id').val();
|
|
|
|
appointment.id_users_customer = customer.id;
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define success callback.
|
2018-01-23 12:08:37 +03:00
|
|
|
var successCallback = function (response) {
|
2016-07-17 15:43:50 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
2017-09-11 17:09:15 +03:00
|
|
|
$dialog.find('.modal-message').text(EALang.unexpected_issues_occurred);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-danger').removeClass('hidden');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display success message to the user.
|
2017-09-11 17:09:15 +03:00
|
|
|
$dialog.find('.modal-message').text(EALang.appointment_saved);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-success').removeClass('alert-danger hidden');
|
|
|
|
$dialog.find('.modal-body').scrollTop(0);
|
|
|
|
|
|
|
|
// Close the modal dialog and refresh the calendar appointments after one second.
|
2018-01-23 12:08:37 +03:00
|
|
|
setTimeout(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.alert').addClass('hidden');
|
|
|
|
$dialog.modal('hide');
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
}, 2000);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Define error callback.
|
2018-01-23 12:08:37 +03:00
|
|
|
var errorCallback = function () {
|
2018-03-27 10:19:27 +03:00
|
|
|
$dialog.find('.modal-message').text(EALang.service_communication_error);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-danger').removeClass('hidden');
|
|
|
|
$dialog.find('.modal-body').scrollTop(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Save appointment data.
|
|
|
|
BackendCalendarApi.saveAppointment(appointment, customer, successCallback, errorCallback);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Insert Appointment Button "Click"
|
|
|
|
*
|
|
|
|
* When the user presses this button, the manage appointment dialog opens and lets the user to
|
|
|
|
* create a new appointment.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#insert-appointment').click(function () {
|
2016-07-18 23:22:28 +03:00
|
|
|
BackendCalendarAppointmentsModal.resetAppointmentDialog();
|
2016-07-17 15:43:50 +03:00
|
|
|
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') {
|
2018-06-24 20:42:42 +03:00
|
|
|
var providerId = $('#select-filter-item').val();
|
|
|
|
|
|
|
|
var providers = GlobalVariables.availableProviders.filter(function (provider) {
|
|
|
|
return provider.id == providerId;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (providers.length) {
|
|
|
|
$dialog.find('#select-service').val(providers[0].services[0]).trigger('change');
|
|
|
|
$dialog.find('#select-provider').val(providerId);
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$dialog.find('#select-service option[value="'
|
2018-01-23 12:08:37 +03:00
|
|
|
+ $('#select-filter-item').val() + '"]').prop('selected', true);
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var serviceDuration = 0;
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.availableServices, function (index, service) {
|
2017-11-02 16:19:54 +03:00
|
|
|
if (service.id == $dialog.find('#select-service').val()) {
|
|
|
|
serviceDuration = service.duration;
|
2016-07-17 15:43:50 +03:00
|
|
|
return false; // exit loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var start = new Date();
|
|
|
|
var currentMin = parseInt(start.toString('mm'));
|
|
|
|
|
|
|
|
if (currentMin > 0 && currentMin < 15) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 15});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 15 && currentMin < 30) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 30});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else if (currentMin > 30 && currentMin < 45) {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.set({'minute': 45});
|
2016-07-17 15:43:50 +03:00
|
|
|
} else {
|
2018-01-23 12:08:37 +03:00
|
|
|
start.addHours(1).set({'minute': 0});
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$dialog.find('#start-datetime').val(GeneralFunctions.formatDate(start, GlobalVariables.dateFormat, true));
|
|
|
|
$dialog.find('#end-datetime').val(GeneralFunctions.formatDate(start.addMinutes(serviceDuration),
|
2018-01-23 12:08:37 +03:00
|
|
|
GlobalVariables.dateFormat, true));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Display modal form.
|
2017-09-11 17:09:15 +03:00
|
|
|
$dialog.find('.modal-header h3').text(EALang.new_appointment_title);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.modal('show');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Pick Existing Customer Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#select-customer').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var $list = $('#existing-customers-list');
|
|
|
|
|
|
|
|
if (!$list.is(':visible')) {
|
2017-09-11 17:09:15 +03:00
|
|
|
$(this).text(EALang.hide);
|
2016-07-17 15:43:50 +03:00
|
|
|
$list.empty();
|
|
|
|
$list.slideDown('slow');
|
|
|
|
$('#filter-existing-customers').fadeIn('slow');
|
|
|
|
$('#filter-existing-customers').val('');
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.customers, function (index, c) {
|
2016-07-17 15:43:50 +03:00
|
|
|
$list.append('<div data-id="' + c.id + '">'
|
2018-01-23 12:08:37 +03:00
|
|
|
+ c.first_name + ' ' + c.last_name + '</div>');
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$list.slideUp('slow');
|
|
|
|
$('#filter-existing-customers').fadeOut('slow');
|
2017-09-11 17:09:15 +03:00
|
|
|
$(this).text(EALang.select);
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Select Existing Customer From List "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#manage-appointment').on('click', '#existing-customers-list div', function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var id = $(this).attr('data-id');
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.customers, function (index, c) {
|
2016-07-17 15:43:50 +03:00
|
|
|
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);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-customer').trigger('click'); // hide list
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Existing Customers "Change"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#filter-existing-customers').keyup(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var key = $(this).val().toLowerCase();
|
|
|
|
var $list = $('#existing-customers-list');
|
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_filter_customers';
|
|
|
|
var postData = {
|
|
|
|
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,
|
2018-01-23 12:08:37 +03:00
|
|
|
success: function (response) {
|
2016-07-17 15:43:50 +03:00
|
|
|
$list.empty();
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(response, function (index, c) {
|
2016-07-17 15:43:50 +03:00
|
|
|
$list.append('<div data-id="' + c.id + '">'
|
2018-01-23 12:08:37 +03:00
|
|
|
+ c.first_name + ' ' + c.last_name + '</div>');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Verify if this customer is on the old customer list.
|
|
|
|
var result = $.grep(GlobalVariables.customers,
|
2018-01-23 12:08:37 +03:00
|
|
|
function (e) {
|
|
|
|
return e.id == c.id;
|
|
|
|
});
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Add it to the customer list.
|
2018-01-23 12:08:37 +03:00
|
|
|
if (result.length == 0) {
|
2016-07-17 15:43:50 +03:00
|
|
|
GlobalVariables.customers.push(c);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2018-01-23 12:08:37 +03:00
|
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
2016-07-17 15:43:50 +03:00
|
|
|
// If there is any error on the request, search by the local client database.
|
|
|
|
$list.empty();
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.customers, function (index, c) {
|
2016-07-17 15:43:50 +03:00
|
|
|
if (c.first_name.toLowerCase().indexOf(key) != -1
|
2018-01-23 12:08:37 +03:00
|
|
|
|| 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) {
|
2016-07-17 15:43:50 +03:00
|
|
|
$list.append('<div data-id="' + c.id + '">'
|
2018-01-23 12:08:37 +03:00
|
|
|
+ c.first_name + ' ' + c.last_name + '</div>');
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Selected Service "Change"
|
|
|
|
*
|
|
|
|
* When the user clicks on a service, its available providers should become visible. Also we need to
|
|
|
|
* update the start and end time of the appointment.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#select-service').change(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var sid = $('#select-service').val();
|
|
|
|
$('#select-provider').empty();
|
|
|
|
|
|
|
|
// Automatically update the service duration.
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.availableServices, function (indexService, service) {
|
2016-07-17 15:43:50 +03:00
|
|
|
if (service.id == sid) {
|
2016-10-24 00:12:19 +03:00
|
|
|
var start = $('#start-datetime').datetimepicker('getDate');
|
|
|
|
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + service.duration * 60000));
|
2016-07-17 15:43:50 +03:00
|
|
|
return false; // break loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update the providers select box.
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.availableProviders, function (indexProvider, provider) {
|
|
|
|
$.each(provider.services, function (indexService, serviceId) {
|
2018-07-29 17:08:41 +03:00
|
|
|
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER && parseInt(provider.id) !== GlobalVariables.user.id) {
|
|
|
|
return true; // continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY && GlobalVariables.secretaryProviders.indexOf(provider.id) === -1) {
|
|
|
|
return true; // continue
|
|
|
|
}
|
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
// If the current provider is able to provide the selected service, add him to the listbox.
|
|
|
|
if (serviceId == sid) {
|
2017-11-02 16:19:54 +03:00
|
|
|
var optionHtml = '<option value="' + provider.id + '">'
|
2018-01-23 12:08:37 +03:00
|
|
|
+ provider.first_name + ' ' + provider.last_name
|
|
|
|
+ '</option>';
|
2016-07-17 15:43:50 +03:00
|
|
|
$('#select-provider').append(optionHtml);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-01-17 14:13:41 +03:00
|
|
|
// If the appointment is opened from a link it triggers the previous function to fill the form
|
|
|
|
if (window.location.href.indexOf("backend/index/") > -1) {
|
|
|
|
$('#select-service').change();
|
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
|
|
|
* Event: Enter New Customer Button "Click"
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
$('#new-customer').click(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
2018-01-23 12:08:37 +03:00
|
|
|
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-10 19:29:48 +03:00
|
|
|
* Reset Appointment Dialog
|
2016-07-17 15:43:50 +03:00
|
|
|
*
|
|
|
|
* This method resets the manage appointment dialog modal to its initial state. After that you can make
|
|
|
|
* any modification might be necessary in order to bring the dialog to the desired state.
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.resetAppointmentDialog = function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
|
|
|
|
// Empty form fields.
|
|
|
|
$dialog.find('input, textarea').val('');
|
|
|
|
$dialog.find('.modal-message').fadeOut();
|
|
|
|
|
|
|
|
// Prepare service and provider select boxes.
|
|
|
|
$dialog.find('#select-service').val(
|
2018-01-23 12:08:37 +03:00
|
|
|
$dialog.find('#select-service').eq(0).attr('value'));
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Fill the providers listbox with providers that can serve the appointment's
|
|
|
|
// service and then select the user's provider.
|
|
|
|
$dialog.find('#select-provider').empty();
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.availableProviders, function (index, provider) {
|
2016-07-17 15:43:50 +03:00
|
|
|
var canProvideService = false;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(provider.services, function (index, serviceId) {
|
2016-07-17 15:43:50 +03:00
|
|
|
if (serviceId == $dialog.find('#select-service').val()) {
|
|
|
|
canProvideService = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (canProvideService) { // Add the provider to the listbox.
|
2017-11-02 16:19:54 +03:00
|
|
|
var option = new Option(provider.first_name
|
2018-01-23 12:08:37 +03:00
|
|
|
+ ' ' + provider.last_name, provider.id);
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('#select-provider').append(option);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Close existing customers-filter frame.
|
|
|
|
$('#existing-customers-list').slideUp('slow');
|
|
|
|
$('#filter-existing-customers').fadeOut('slow');
|
2017-09-11 17:09:15 +03:00
|
|
|
$('#select-customer').text(EALang.select);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Setup start and datetimepickers.
|
|
|
|
// Get the selected service duration. It will be needed in order to calculate the appointment end datetime.
|
|
|
|
var serviceDuration = 0;
|
2018-01-23 12:08:37 +03:00
|
|
|
$.each(GlobalVariables.availableServices, function (index, service) {
|
2017-11-02 16:19:54 +03:00
|
|
|
if (service.id == $dialog.find('#select-service').val()) {
|
|
|
|
serviceDuration = service.duration;
|
2016-07-17 15:43:50 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var startDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout);
|
2018-01-23 12:08:37 +03:00
|
|
|
var endDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout).addMinutes(serviceDuration);
|
2016-07-17 15:43:50 +03:00
|
|
|
var dateFormat;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
switch (GlobalVariables.dateFormat) {
|
2016-07-17 15:43:50 +03:00
|
|
|
case 'DMY':
|
|
|
|
dateFormat = 'dd/mm/yy';
|
|
|
|
break;
|
|
|
|
case 'MDY':
|
|
|
|
dateFormat = 'mm/dd/yy';
|
|
|
|
break;
|
|
|
|
case 'YMD':
|
|
|
|
dateFormat = 'yy/mm/dd';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('Invalid GlobalVariables.dateFormat value.');
|
|
|
|
}
|
|
|
|
|
2018-06-29 01:41:17 +03:00
|
|
|
var fDay = GlobalVariables.firstWeekday;
|
|
|
|
var fDaynum = GeneralFunctions.getWeekDayId(fDay);
|
|
|
|
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('#start-datetime').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2018-03-17 20:00:55 +03:00
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm TT' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2017-09-11 17:09:15 +03:00
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.thursday, EALang.friday, EALang.saturday],
|
|
|
|
dayNamesShort: [EALang.sunday.substr(0, 3), EALang.monday.substr(0, 3),
|
|
|
|
EALang.tuesday.substr(0, 3), EALang.wednesday.substr(0, 3),
|
|
|
|
EALang.thursday.substr(0, 3), EALang.friday.substr(0, 3),
|
|
|
|
EALang.saturday.substr(0, 3)],
|
|
|
|
dayNamesMin: [EALang.sunday.substr(0, 2), EALang.monday.substr(0, 2),
|
|
|
|
EALang.tuesday.substr(0, 2), EALang.wednesday.substr(0, 2),
|
|
|
|
EALang.thursday.substr(0, 2), EALang.friday.substr(0, 2),
|
|
|
|
EALang.saturday.substr(0, 2)],
|
2017-09-11 17:09:15 +03:00
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august, EALang.september,
|
|
|
|
EALang.october, EALang.november, EALang.december],
|
2017-09-11 17:09:15 +03:00
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
|
|
|
timeOnlyTitle: EALang.select_time,
|
|
|
|
timeText: EALang.time,
|
|
|
|
hourText: EALang.hour,
|
|
|
|
minuteText: EALang.minutes,
|
2020-03-10 22:44:51 +03:00
|
|
|
firstDay: fDaynum,
|
2018-11-07 19:24:08 +03:00
|
|
|
onClose: function () {
|
2020-03-10 22:44:51 +03:00
|
|
|
var sid = $('#select-service').val();
|
|
|
|
|
|
|
|
// Automatically update the #end-datetime DateTimePicker based on service duration.
|
|
|
|
$.each(GlobalVariables.availableServices, function (indexService, service) {
|
|
|
|
if (service.id == sid) {
|
|
|
|
var start = $('#start-datetime').datetimepicker('getDate');
|
|
|
|
$('#end-datetime').datetimepicker('setDate', new Date(start.getTime() + service.duration * 60000));
|
|
|
|
return false; // break loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
2016-10-24 00:12:19 +03:00
|
|
|
$dialog.find('#start-datetime').datetimepicker('setDate', startDatetime);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
$dialog.find('#end-datetime').datetimepicker({
|
|
|
|
dateFormat: dateFormat,
|
2018-03-17 20:00:55 +03:00
|
|
|
timeFormat: GlobalVariables.timeFormat === 'regular' ? 'h:mm TT' : 'HH:mm',
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Translation
|
2017-09-11 17:09:15 +03:00
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.thursday, EALang.friday, EALang.saturday],
|
|
|
|
dayNamesShort: [EALang.sunday.substr(0, 3), EALang.monday.substr(0, 3),
|
|
|
|
EALang.tuesday.substr(0, 3), EALang.wednesday.substr(0, 3),
|
|
|
|
EALang.thursday.substr(0, 3), EALang.friday.substr(0, 3),
|
|
|
|
EALang.saturday.substr(0, 3)],
|
|
|
|
dayNamesMin: [EALang.sunday.substr(0, 2), EALang.monday.substr(0, 2),
|
|
|
|
EALang.tuesday.substr(0, 2), EALang.wednesday.substr(0, 2),
|
|
|
|
EALang.thursday.substr(0, 2), EALang.friday.substr(0, 2),
|
|
|
|
EALang.saturday.substr(0, 2)],
|
2017-09-11 17:09:15 +03:00
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
2018-01-23 12:08:37 +03:00
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august, EALang.september,
|
|
|
|
EALang.october, EALang.november, EALang.december],
|
2017-09-11 17:09:15 +03:00
|
|
|
prevText: EALang.previous,
|
|
|
|
nextText: EALang.next,
|
|
|
|
currentText: EALang.now,
|
|
|
|
closeText: EALang.close,
|
|
|
|
timeOnlyTitle: EALang.select_time,
|
|
|
|
timeText: EALang.time,
|
|
|
|
hourText: EALang.hour,
|
|
|
|
minuteText: EALang.minutes,
|
2018-06-29 01:41:17 +03:00
|
|
|
firstDay: fDaynum
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
2016-10-24 00:12:19 +03:00
|
|
|
$dialog.find('#end-datetime').datetimepicker('setDate', endDatetime);
|
|
|
|
};
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the manage appointment dialog data. Validation checks need to
|
|
|
|
* run every time the data are going to be saved.
|
|
|
|
*
|
|
|
|
* @returns {Boolean} Returns the validation result.
|
|
|
|
*/
|
|
|
|
function _validateAppointmentForm() {
|
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
|
2016-10-10 19:29:48 +03:00
|
|
|
// Reset previous validation css formatting.
|
2017-11-14 15:52:59 +03:00
|
|
|
$dialog.find('.has-error').removeClass('has-error');
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('hidden');
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Check required fields.
|
|
|
|
var missingRequiredField = false;
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
$dialog.find('.required').each(function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
if ($(this).val() == '' || $(this).val() == null) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$(this).closest('.form-group').addClass('has-error');
|
2016-07-17 15:43:50 +03:00
|
|
|
missingRequiredField = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (missingRequiredField) {
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.fields_are_required;
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check email address.
|
|
|
|
if (!GeneralFunctions.validateEmail($dialog.find('#email').val())) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$dialog.find('#email').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.invalid_email;
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check appointment start and end time.
|
2016-10-24 00:12:19 +03:00
|
|
|
var start = $('#start-datetime').datetimepicker('getDate');
|
|
|
|
var end = $('#end-datetime').datetimepicker('getDate');
|
2016-07-17 15:43:50 +03:00
|
|
|
if (start > end) {
|
2017-11-14 15:52:59 +03:00
|
|
|
$dialog.find('#start-datetime, #end-datetime').closest('.form-group').addClass('has-error');
|
2017-09-11 17:09:15 +03:00
|
|
|
throw EALang.start_date_before_end_error;
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-01-23 12:08:37 +03:00
|
|
|
} catch (exc) {
|
2016-07-17 15:43:50 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-danger').text(exc).removeClass('hidden');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
exports.initialize = function () {
|
2016-07-17 15:43:50 +03:00
|
|
|
_bindEventHandlers();
|
|
|
|
};
|
|
|
|
|
2020-03-10 22:44:51 +03:00
|
|
|
})(window.BackendCalendarAppointmentsModal);
|