2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
/**
|
|
|
|
* This namespace contains functions that are used by the backend calendar page.
|
|
|
|
*
|
2013-06-13 19:25:34 +03:00
|
|
|
* @namespace BackendCalendar
|
2013-06-12 18:31:16 +03:00
|
|
|
*/
|
|
|
|
var BackendCalendar = {
|
2013-07-06 03:00:04 +03:00
|
|
|
// :: CONSTANTS
|
2013-07-03 20:27:00 +03:00
|
|
|
FILTER_TYPE_PROVIDER: 'provider',
|
|
|
|
FILTER_TYPE_SERVICE: 'service',
|
2013-06-13 19:25:34 +03:00
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
// :: VALIABLES
|
2013-07-03 20:27:00 +03:00
|
|
|
lastFocusedEventData: undefined, // Contain event data for later use.
|
2013-06-13 19:25:34 +03:00
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
/**
|
|
|
|
* This function makes the necessary initialization for the default backend
|
|
|
|
* calendar page. If this namespace is used in another page then this function
|
|
|
|
* might not be needed.
|
|
|
|
*
|
|
|
|
* @param {bool} defaultEventHandlers (OPTIONAL = TRUE) Determines whether the
|
|
|
|
* default event handlers will be set for the current page.
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
initialize: function(defaultEventHandlers) {
|
2013-06-12 18:31:16 +03:00
|
|
|
if (defaultEventHandlers === undefined) defaultEventHandlers = true;
|
|
|
|
|
2013-09-13 16:21:03 +03:00
|
|
|
// Initialize page calendar
|
2013-06-12 18:31:16 +03:00
|
|
|
$('#calendar').fullCalendar({
|
2013-07-03 20:27:00 +03:00
|
|
|
'defaultView': 'agendaWeek',
|
|
|
|
'height': BackendCalendar.getCalendarHeight(),
|
|
|
|
'editable': true,
|
2013-10-17 18:31:43 +03:00
|
|
|
'firstDay': 1, // Monday
|
2013-07-03 20:27:00 +03:00
|
|
|
'slotMinutes': 30,
|
2013-11-23 21:10:31 +02:00
|
|
|
'snapMinutes': 15,
|
2013-07-10 16:57:24 +03:00
|
|
|
'axisFormat': 'HH:mm',
|
|
|
|
'timeFormat': 'HH:mm{ - HH:mm}',
|
2013-12-20 19:44:44 +02:00
|
|
|
'allDayText': EALang['all_day'],
|
2013-07-03 20:27:00 +03:00
|
|
|
'columnFormat': {
|
|
|
|
'month': 'ddd',
|
|
|
|
'week': 'ddd d/M',
|
|
|
|
'day': 'dddd d/M'
|
2013-06-13 19:25:34 +03:00
|
|
|
},
|
2013-07-03 20:27:00 +03:00
|
|
|
'titleFormat': {
|
|
|
|
'month': 'MMMM yyyy',
|
|
|
|
'week': "MMMM d[ yyyy]{ '—'[ MMM] d, yyyy}",
|
2013-12-23 18:55:42 +02:00
|
|
|
'day': 'dddd, MMMM d, yyyy'
|
2013-06-13 19:25:34 +03:00
|
|
|
},
|
2013-07-03 20:27:00 +03:00
|
|
|
'header': {
|
|
|
|
'left': 'prev,next today',
|
|
|
|
'center': 'title',
|
|
|
|
'right': 'agendaDay,agendaWeek,month'
|
2013-06-13 19:25:34 +03:00
|
|
|
},
|
2013-12-23 18:55:42 +02:00
|
|
|
|
|
|
|
// Translations
|
|
|
|
'monthNames': [EALang['january'], EALang['february'], EALang['march'], EALang['april'],
|
|
|
|
EALang['may'], EALang['june'], EALang['july'], EALang['august'],
|
|
|
|
EALang['september'],EALang['october'], EALang['november'],
|
|
|
|
EALang['december']],
|
|
|
|
'monthNamesShort': [EALang['january'].substr(0,3), EALang['february'].substr(0,3),
|
|
|
|
EALang['march'].substr(0,3), EALang['april'].substr(0,3),
|
|
|
|
EALang['may'].substr(0,3), EALang['june'].substr(0,3),
|
|
|
|
EALang['july'].substr(0,3), EALang['august'].substr(0,3),
|
|
|
|
EALang['september'].substr(0,3),EALang['october'].substr(0,3),
|
|
|
|
EALang['november'].substr(0,3), EALang['december'].substr(0,3)],
|
|
|
|
'dayNames': [EALang['sunday'], EALang['monday'], EALang['tuesday'], EALang['wednesday'],
|
|
|
|
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)],
|
|
|
|
'buttonText': {
|
|
|
|
'today': EALang['today'],
|
|
|
|
'day': EALang['day'],
|
|
|
|
'week': EALang['week'],
|
|
|
|
'month': EALang['month']
|
|
|
|
},
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
// Calendar events need to be declared on initialization.
|
2013-07-03 20:27:00 +03:00
|
|
|
'windowResize': BackendCalendar.calendarWindowResize,
|
|
|
|
'viewDisplay': BackendCalendar.calendarViewDisplay,
|
|
|
|
'dayClick': BackendCalendar.calendarDayClick,
|
|
|
|
'eventClick': BackendCalendar.calendarEventClick,
|
|
|
|
'eventResize': BackendCalendar.calendarEventResize,
|
2013-10-27 19:41:37 +02:00
|
|
|
'eventDrop': BackendCalendar.calendarEventDrop,
|
|
|
|
'eventAfterAllRender': function(view) {
|
|
|
|
BackendCalendar.convertTitlesToHtml();
|
2013-11-21 23:58:51 +02:00
|
|
|
}
|
2013-06-12 18:31:16 +03:00
|
|
|
});
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
// Trigger once to set the proper footer position after calendar
|
|
|
|
// initialization.
|
|
|
|
BackendCalendar.calendarWindowResize();
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
// Fill the select listboxes of the page.
|
2013-10-17 18:31:43 +03:00
|
|
|
if (GlobalVariables.availableProviders.length > 0) {
|
2014-01-10 16:09:20 +02:00
|
|
|
var optgroupHtml = '<optgroup label="' + EALang['providers'] + '" type="providers-group">';
|
2013-10-17 18:31:43 +03:00
|
|
|
$.each(GlobalVariables.availableProviders, function(index, provider) {
|
|
|
|
var hasGoogleSync = (provider['settings']['google_sync'] === '1')
|
|
|
|
? 'true' : 'false';
|
|
|
|
|
|
|
|
optgroupHtml += '<option value="' + provider['id'] + '" '
|
|
|
|
+ 'type="' + BackendCalendar.FILTER_TYPE_PROVIDER + '" '
|
|
|
|
+ 'google-sync="' + hasGoogleSync + '">'
|
|
|
|
+ provider['first_name'] + ' ' + provider['last_name']
|
|
|
|
+ '</option>';
|
|
|
|
});
|
|
|
|
optgroupHtml += '</optgroup>';
|
|
|
|
$('#select-filter-item').append(optgroupHtml);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GlobalVariables.availableServices.length > 0) {
|
2014-01-10 16:09:20 +02:00
|
|
|
optgroupHtml = '<optgroup label="' + EALang['services'] + '" type="services-group">';
|
2013-10-17 18:31:43 +03:00
|
|
|
$.each(GlobalVariables.availableServices, function(index, service) {
|
|
|
|
optgroupHtml += '<option value="' + service['id'] + '" ' +
|
|
|
|
'type="' + BackendCalendar.FILTER_TYPE_SERVICE + '">' +
|
|
|
|
service['name'] + '</option>';
|
|
|
|
});
|
|
|
|
optgroupHtml += '</optgroup>';
|
|
|
|
$('#select-filter-item').append(optgroupHtml);
|
|
|
|
}
|
2013-06-12 18:31:16 +03:00
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
// Privileges Checks
|
2013-09-27 15:49:29 +03:00
|
|
|
if (GlobalVariables.user.role_slug == Backend.DB_SLUG_PROVIDER) {
|
2013-10-20 19:45:46 +03:00
|
|
|
$('#select-filter-item optgroup:eq(0)')
|
|
|
|
.find('option[value="' + GlobalVariables.user.id + '"]').prop('selected', true);
|
2013-09-27 15:49:29 +03:00
|
|
|
$('#select-filter-item').prop('disabled', true);
|
|
|
|
}
|
|
|
|
|
2013-10-18 17:56:12 +03:00
|
|
|
if (GlobalVariables.user.role_slug == Backend.DB_SLUG_SECRETARY) {
|
|
|
|
$('#select-filter-item optgroup:eq(1)').remove();
|
|
|
|
}
|
|
|
|
|
2013-10-10 19:50:33 +03:00
|
|
|
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) {
|
|
|
|
found = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
$(option).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($('#select-filter-item option[type="provider"]').length == 0) {
|
|
|
|
$('#select-filter-item optgroup[type="providers-group"]').remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
// :: BIND THE DEFAULT EVENT HANDLERS (IF NEEDED)
|
2013-06-12 18:31:16 +03:00
|
|
|
if (defaultEventHandlers === true) {
|
|
|
|
BackendCalendar.bindEventHandlers();
|
2013-06-13 19:25:34 +03:00
|
|
|
$('#select-filter-item').trigger('change');
|
2013-06-12 18:31:16 +03:00
|
|
|
}
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
// :: DISPLAY EDIT DIALOG IF APPOINTMENT HASH IS PROVIDED
|
|
|
|
if (GlobalVariables.editAppointment != null) {
|
2013-07-15 10:32:19 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
var appointment = GlobalVariables.editAppointment;
|
|
|
|
BackendCalendar.resetAppointmentDialog();
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-header h3').text(EALang['edit_appointment_title']);
|
2013-07-15 10:32:19 +03:00
|
|
|
$dialog.find('#appointment-id').val(appointment['id']);
|
2013-12-05 23:53:27 +02:00
|
|
|
$dialog.find('#select-service').val(appointment['id_services']).change();
|
2013-07-15 10:32:19 +03:00
|
|
|
$dialog.find('#select-provider').val(appointment['id_users_provider']);
|
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
|
|
|
var startDatetime = Date.parseExact(appointment['start_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss').toString('dd/MM/yyyy HH:mm');
|
|
|
|
$dialog.find('#start-datetime').val(startDatetime);
|
|
|
|
|
|
|
|
var endDatetime = Date.parseExact(appointment['end_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss').toString('dd/MM/yyyy HH:mm');
|
|
|
|
$dialog.find('#end-datetime').val(endDatetime);
|
|
|
|
|
|
|
|
var customer = appointment['customer'];
|
|
|
|
$dialog.find('#customer-id').val(appointment['id_users_customer']);
|
|
|
|
$dialog.find('#first-name').val(customer['first_name']);
|
|
|
|
$dialog.find('#last-name').val(customer['last_name']);
|
|
|
|
$dialog.find('#email').val(customer['email']);
|
|
|
|
$dialog.find('#phone-number').val(customer['phone_number']);
|
|
|
|
$dialog.find('#address').val(customer['address']);
|
|
|
|
$dialog.find('#city').val(customer['city']);
|
|
|
|
$dialog.find('#zip-code').val(customer['zip_code']);
|
2013-11-24 17:45:44 +02:00
|
|
|
$dialog.find('#appointment-notes').val(appointment['notes']);
|
|
|
|
$dialog.find('#customer-notes').val(customer['notes']);
|
2013-07-15 10:32:19 +03:00
|
|
|
|
|
|
|
$dialog.modal('show');
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2013-10-18 17:56:12 +03:00
|
|
|
|
|
|
|
// Apply qtip to control tooltips.
|
|
|
|
$('#calendar-toolbar button').qtip({
|
|
|
|
position: {
|
|
|
|
my: 'top center',
|
|
|
|
at: 'bottom center'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
classes: 'qtip-green qtip-shadow custom-qtip'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-filter-item').qtip({
|
|
|
|
position: {
|
|
|
|
my: 'middle left',
|
|
|
|
at: 'middle right'
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
classes: 'qtip-green qtip-shadow custom-qtip'
|
|
|
|
}
|
|
|
|
});
|
2013-10-27 14:53:51 +02:00
|
|
|
|
|
|
|
// Fine tune the footer's position only for this page.
|
|
|
|
if (window.innerHeight < 700) {
|
|
|
|
$('#footer').css('position', 'static');
|
|
|
|
}
|
2013-11-23 21:10:31 +02:00
|
|
|
|
|
|
|
if ($('#select-filter-item option').length == 0)
|
|
|
|
$('#calendar-actions button').prop('disabled', true);
|
2013-06-12 18:31:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method binds the default event handlers for the backend calendar
|
|
|
|
* page. If you do not need the default handlers then initialize the page
|
|
|
|
* by setting the "defaultEventHandlers" argument to "false".
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
bindEventHandlers: function() {
|
2013-06-13 19:25:34 +03:00
|
|
|
/**
|
2013-06-18 19:06:34 +03:00
|
|
|
* Event: Calendar Filter Item "Change"
|
2013-06-13 19:25:34 +03:00
|
|
|
*
|
|
|
|
* Load the appointments that correspond to the select filter item and
|
|
|
|
* display them on the calendar.
|
|
|
|
*/
|
|
|
|
$('#select-filter-item').change(function() {
|
|
|
|
BackendCalendar.refreshCalendarAppointments(
|
|
|
|
$('#calendar'),
|
|
|
|
$('#select-filter-item').val(),
|
|
|
|
$('#select-filter-item option:selected').attr('type'),
|
|
|
|
$('#calendar').fullCalendar('getView').visStart,
|
|
|
|
$('#calendar').fullCalendar('getView').visEnd);
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
// If current value is service, then the sync buttons must be
|
|
|
|
// disabled.
|
|
|
|
if ($('#select-filter-item option:selected').attr('type')
|
|
|
|
=== BackendCalendar.FILTER_TYPE_SERVICE) {
|
2013-07-05 11:39:52 +03:00
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-unavailable')
|
|
|
|
.prop('disabled', true);
|
2013-06-18 19:06:34 +03:00
|
|
|
} else {
|
2013-07-05 11:39:52 +03:00
|
|
|
|
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-unavailable')
|
|
|
|
.prop('disabled', false);
|
2013-06-19 22:29:00 +03:00
|
|
|
// If the user has already the sync enabled then apply the proper
|
|
|
|
// style changes.
|
2013-07-05 11:39:52 +03:00
|
|
|
if ($('#select-filter-item option:selected').attr('google-sync') === 'true') {
|
2015-08-13 21:33:47 +03:00
|
|
|
$('#enable-sync').addClass('btn-danger enabled');
|
2015-07-27 23:29:20 +03:00
|
|
|
$('#enable-sync span:eq(1)').text(EALang['disable_sync']);
|
2013-06-19 22:29:00 +03:00
|
|
|
$('#google-sync').prop('disabled', false);
|
|
|
|
} else {
|
|
|
|
$('#enable-sync').removeClass('btn-success enabled');
|
2015-07-27 23:29:20 +03:00
|
|
|
$('#enable-sync span:eq(1)').text(EALang['enable_sync']);
|
2013-06-19 22:29:00 +03:00
|
|
|
$('#google-sync').prop('disabled', true);
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
}
|
2013-06-13 19:25:34 +03:00
|
|
|
});
|
|
|
|
|
2013-07-15 10:32:19 +03:00
|
|
|
/**
|
|
|
|
* Event: Google Sync Button "Click"
|
|
|
|
*
|
|
|
|
* Trigger the synchronization algorithm.
|
|
|
|
*/
|
|
|
|
$('#google-sync').click(function() {
|
2015-05-20 23:26:11 +03:00
|
|
|
var getUrl = GlobalVariables.baseUrl + '/index.php/google/sync/' + $('#select-filter-item').val();
|
2013-07-15 10:32:19 +03:00
|
|
|
$.ajax({
|
|
|
|
'type': 'GET',
|
|
|
|
'url': getUrl,
|
|
|
|
'dataType': 'json',
|
|
|
|
'success': function(response) {
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
console.log('Google Sync Response:', response);
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-12-25 03:22:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE,
|
|
|
|
GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-15 10:32:19 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-12-25 03:22:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE,
|
|
|
|
GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-15 10:32:19 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
2013-12-25 03:22:37 +02:00
|
|
|
Backend.displayNotification(EALang['google_sync_completed']);
|
2013-07-15 10:32:19 +03:00
|
|
|
$('#reload-appointments').trigger('click');
|
|
|
|
},
|
|
|
|
'error': function(jqXHR, textStatus, errorThrown) {
|
2013-12-25 03:22:37 +02:00
|
|
|
Backend.displayNotification(EALang['google_sync_failed']);
|
2013-07-15 10:32:19 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-24 12:52:23 +03:00
|
|
|
/**
|
|
|
|
* Event: Reload Button "Click"
|
|
|
|
*
|
|
|
|
* When the user clicks the reload button an the calendar items need to
|
|
|
|
* be refreshed.
|
|
|
|
*/
|
|
|
|
$('#reload-appointments').click(function() {
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
});
|
|
|
|
|
2013-06-13 19:25:34 +03:00
|
|
|
/**
|
2013-06-18 19:06:34 +03:00
|
|
|
* Event: Popover Close Button "Click"
|
2013-06-13 19:25:34 +03:00
|
|
|
*
|
|
|
|
* Hides the open popover element.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.close-popover', function() {
|
|
|
|
$(this).parents().eq(2).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2013-06-18 19:06:34 +03:00
|
|
|
* Event: Popover Edit Button "Click"
|
2013-06-13 19:25:34 +03:00
|
|
|
*
|
|
|
|
* Enables the edit dialog of the selected calendar event.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.edit-popover', function() {
|
|
|
|
$(this).parents().eq(2).remove(); // Hide the popover
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
var $dialog;
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (BackendCalendar.lastFocusedEventData.data.is_unavailable == false) {
|
|
|
|
var appointment = BackendCalendar.lastFocusedEventData.data;
|
|
|
|
$dialog = $('#manage-appointment');
|
|
|
|
|
|
|
|
BackendCalendar.resetAppointmentDialog();
|
|
|
|
|
|
|
|
// :: APPLY APPOINTMENT DATA AND SHOW TO MODAL DIALOG
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-header h3').text(EALang['edit_appointment_title']);
|
2013-07-10 16:57:24 +03:00
|
|
|
$dialog.find('#appointment-id').val(appointment['id']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('#select-service').val(appointment['id_services']).trigger('change');
|
2013-07-10 16:57:24 +03:00
|
|
|
$dialog.find('#select-provider').val(appointment['id_users_provider']);
|
|
|
|
|
2013-07-15 10:32:19 +03:00
|
|
|
// Set the start and end datetime of the appointment.
|
2013-07-10 16:57:24 +03:00
|
|
|
var startDatetime = Date.parseExact(appointment['start_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss').toString('dd/MM/yyyy HH:mm');
|
|
|
|
$dialog.find('#start-datetime').val(startDatetime);
|
|
|
|
|
|
|
|
var endDatetime = Date.parseExact(appointment['end_datetime'],
|
|
|
|
'yyyy-MM-dd HH:mm:ss').toString('dd/MM/yyyy HH:mm');
|
|
|
|
$dialog.find('#end-datetime').val(endDatetime);
|
|
|
|
|
|
|
|
var customer = appointment['customer'];
|
|
|
|
$dialog.find('#customer-id').val(appointment['id_users_customer']);
|
|
|
|
$dialog.find('#first-name').val(customer['first_name']);
|
|
|
|
$dialog.find('#last-name').val(customer['last_name']);
|
|
|
|
$dialog.find('#email').val(customer['email']);
|
|
|
|
$dialog.find('#phone-number').val(customer['phone_number']);
|
|
|
|
$dialog.find('#address').val(customer['address']);
|
|
|
|
$dialog.find('#city').val(customer['city']);
|
|
|
|
$dialog.find('#zip-code').val(customer['zip_code']);
|
2013-11-24 17:45:44 +02:00
|
|
|
$dialog.find('#appointment-notes').val(appointment['notes']);
|
|
|
|
$dialog.find('#customer-notes').val(customer['notes']);
|
2013-07-10 16:57:24 +03:00
|
|
|
} else {
|
|
|
|
var unavailable = BackendCalendar.lastFocusedEventData.data;
|
|
|
|
|
|
|
|
// Replace string date values with actual date objects.
|
|
|
|
unavailable.start_datetime = GeneralFunctions.clone(BackendCalendar.lastFocusedEventData.start);
|
|
|
|
unavailable.end_datetime = GeneralFunctions.clone(BackendCalendar.lastFocusedEventData.end);
|
|
|
|
|
|
|
|
$dialog = $('#manage-unavailable');
|
|
|
|
BackendCalendar.resetUnavailableDialog();
|
|
|
|
|
|
|
|
// :: APPLY UNAVAILABLE DATA TO DIALOG
|
|
|
|
$dialog.find('.modal-header h3').text('Edit Unavailable Period');
|
|
|
|
$dialog.find('#unavailable-id').val(unavailable.id);
|
|
|
|
$dialog.find('#unavailable-start').val(unavailable.start_datetime.toString('dd/MM/yyyy HH:mm'));
|
|
|
|
$dialog.find('#unavailable-end').val(unavailable.end_datetime.toString('dd/MM/yyyy HH:mm'));
|
|
|
|
$dialog.find('#unavailable-notes').val(unavailable.notes);
|
|
|
|
}
|
2013-06-13 19:25:34 +03:00
|
|
|
|
2013-07-15 10:32:19 +03:00
|
|
|
// :: DISPLAY EDIT DIALOG
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.modal('show');
|
2013-06-13 19:25:34 +03:00
|
|
|
});
|
2013-06-12 18:31:16 +03:00
|
|
|
|
2013-06-19 22:29:00 +03:00
|
|
|
/**
|
2013-06-28 17:23:17 +03:00
|
|
|
* Event: Popover Delete Button "Click"
|
2013-06-19 22:29:00 +03:00
|
|
|
*
|
|
|
|
* Displays a prompt on whether the user wants the appoinmtent to be
|
|
|
|
* deleted. If he confirms the deletion then an ajax call is made to
|
|
|
|
* the server and deletes the appointment from the database.
|
|
|
|
*/
|
|
|
|
$(document).on('click', '.delete-popover', function() {
|
|
|
|
$(this).parents().eq(2).remove(); // Hide the popover
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (BackendCalendar.lastFocusedEventData.data.is_unavailable == false) {
|
2013-12-19 18:28:19 +02:00
|
|
|
var messageButtons = {};
|
|
|
|
messageButtons['OK'] = function() {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
2013-12-19 18:28:19 +02:00
|
|
|
|
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-12-19 18:28:19 +02:00
|
|
|
'appointment_id' : BackendCalendar.lastFocusedEventData.data['id'],
|
|
|
|
'delete_reason': $('#delete-reason').val()
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
console.log('Delete Appointment Response :', response);
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-24 09:04:30 +03:00
|
|
|
$('#message_box').dialog('close');
|
2013-12-19 18:28:19 +02:00
|
|
|
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh calendar event items.
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
}, 'json');
|
2013-07-10 16:57:24 +03:00
|
|
|
};
|
2013-12-19 18:28:19 +02:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
messageButtons[EALang['cancel']] = function() {
|
2013-12-19 18:28:19 +02:00
|
|
|
$('#message_box').dialog('close');
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
GeneralFunctions.displayMessageBox(EALang['delete_appointment_title'],
|
|
|
|
EALang['write_appointment_removal_reason'], messageButtons);
|
2013-10-18 17:56:12 +03:00
|
|
|
$('#message_box').append('<textarea id="delete-reason" rows="3"></textarea>');
|
|
|
|
$('#delete-reason').css('width', '353px');
|
2013-07-10 16:57:24 +03:00
|
|
|
} else {
|
|
|
|
// Do not display confirmation promt.
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-07-10 16:57:24 +03:00
|
|
|
'unavailable_id' : BackendCalendar.lastFocusedEventData.data.id
|
|
|
|
};
|
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
console.log('Delete Unavailable Response :', response);
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
2013-06-19 22:29:00 +03:00
|
|
|
$('#message_box').dialog('close');
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresh calendar event items.
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
}, 'json');
|
|
|
|
}
|
2013-06-19 22:29:00 +03:00
|
|
|
});
|
|
|
|
|
2013-06-13 19:25:34 +03:00
|
|
|
/**
|
2013-06-18 19:06:34 +03:00
|
|
|
* Event: Manage Appointments Dialog Cancel Button "Click"
|
2013-06-13 19:25:34 +03:00
|
|
|
*
|
2013-06-29 00:54:12 +03:00
|
|
|
* Closes the dialog without saving any changes to the database.
|
2013-06-13 19:25:34 +03:00
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#manage-appointment #cancel-appointment').click(function() {
|
2013-06-13 19:25:34 +03:00
|
|
|
$('#manage-appointment').modal('hide');
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2013-06-18 19:06:34 +03:00
|
|
|
* Event: Manage Appointments Dialog Save Button "Click"
|
2013-06-13 19:25:34 +03:00
|
|
|
*
|
2013-06-29 00:54:12 +03:00
|
|
|
* Stores the appointment changes or inserts a new appointment depending the dialog
|
|
|
|
* mode.
|
2013-06-13 19:25:34 +03:00
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#manage-appointment #save-appointment').click(function() {
|
2013-06-29 00:54:12 +03:00
|
|
|
// Before doing anything the appointment data need to be validated.
|
|
|
|
if (!BackendCalendar.validateAppointmentForm()) {
|
|
|
|
return; // validation failed
|
|
|
|
}
|
|
|
|
|
2013-06-13 19:25:34 +03:00
|
|
|
// :: PREPARE APPOINTMENT DATA FOR AJAX CALL
|
2013-07-06 03:00:04 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
2013-06-18 19:06:34 +03:00
|
|
|
|
|
|
|
// Id must exist on the object in order for the model to update
|
|
|
|
// the record and not to perform an insert operation.
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
var startDatetime = Date.parseExact($dialog.find('#start-datetime').val(),
|
2013-06-18 19:06:34 +03:00
|
|
|
'dd/MM/yyyy HH:mm').toString('yyyy-MM-dd HH:mm:ss');
|
2013-07-06 03:00:04 +03:00
|
|
|
var endDatetime = Date.parseExact($dialog.find('#end-datetime').val(),
|
2013-06-18 19:06:34 +03:00
|
|
|
'dd/MM/yyyy HH:mm').toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
var appointment = {
|
|
|
|
'id_services': $dialog.find('#select-service').val(),
|
|
|
|
'id_users_provider': $dialog.find('#select-provider').val(),
|
2013-07-03 20:27:00 +03:00
|
|
|
'start_datetime': startDatetime,
|
|
|
|
'end_datetime': endDatetime,
|
2013-11-24 17:45:44 +02:00
|
|
|
'notes': $dialog.find('#appointment-notes').val(),
|
2013-09-13 16:21:03 +03:00
|
|
|
'is_unavailable': false
|
2013-06-18 19:06:34 +03:00
|
|
|
};
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
if ($dialog.find('#appointment-id').val() !== '') {
|
2013-06-29 00:54:12 +03:00
|
|
|
// Set the id value, only if we are editing an appointment.
|
2013-07-06 03:00:04 +03:00
|
|
|
appointment['id'] = $dialog.find('#appointment-id').val();
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
|
2013-07-06 03:00:04 +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(),
|
2013-11-24 17:45:44 +02:00
|
|
|
'zip_code': $dialog.find('#zip-code').val(),
|
|
|
|
'notes': $dialog.find('#customer-notes').val()
|
2013-06-18 19:06:34 +03:00
|
|
|
};
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
if ($dialog.find('#customer-id').val() !== '') {
|
2013-06-29 00:54:12 +03:00
|
|
|
// Set the id value, only if we are editing an appointment.
|
2013-07-06 03:00:04 +03:00
|
|
|
customer['id'] = $dialog.find('#customer-id').val();
|
|
|
|
appointment['id_users_customer'] = customer['id'];
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
// :: DEFINE SUCCESS EVENT CALLBACK
|
2013-10-27 19:41:37 +02:00
|
|
|
var successCallback = function(response) {
|
2013-12-05 23:53:27 +02:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) {
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['unexpected_issues_occurred']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2014-01-11 02:07:25 +02:00
|
|
|
return false;
|
2013-06-18 19:06:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display success message to the user.
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['appointment_saved']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-success').removeClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2013-10-27 19:41:37 +02:00
|
|
|
$dialog.find('.modal-body').scrollTop(0);
|
2013-06-18 19:06:34 +03:00
|
|
|
|
|
|
|
// Close the modal dialog and refresh the calendar appointments
|
|
|
|
// after one second.
|
|
|
|
setTimeout(function() {
|
2013-11-23 21:10:31 +02:00
|
|
|
$dialog.find('.alert').fadeOut();
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.modal('hide');
|
2013-06-18 19:06:34 +03:00
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
}, 2000);
|
|
|
|
};
|
|
|
|
|
2013-07-03 20:27:00 +03:00
|
|
|
// :: DEFINE AJAX ERROR EVENT CALLBACK
|
2013-06-18 19:06:34 +03:00
|
|
|
var errorCallback = function() {
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['server_communication_error']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2013-10-27 19:41:37 +02:00
|
|
|
$dialog.find('.modal-body').scrollTop(0);
|
2013-06-18 19:06:34 +03:00
|
|
|
};
|
2013-06-13 19:25:34 +03:00
|
|
|
|
|
|
|
// :: CALL THE UPDATE APPOINTMENT METHOD
|
2013-07-09 17:46:48 +03:00
|
|
|
BackendCalendar.saveAppointment(appointment, customer,
|
2013-06-18 19:06:34 +03:00
|
|
|
successCallback, errorCallback);
|
|
|
|
});
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
/**
|
|
|
|
* Event: Manage Unavailable Dialog Save Button "Click"
|
|
|
|
*
|
|
|
|
* Stores the unavailable period changes or inserts a new record.
|
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#manage-unavailable #save-unavailable').click(function() {
|
|
|
|
var $dialog = $('#manage-unavailable');
|
|
|
|
|
|
|
|
var start = Date.parseExact($dialog.find('#unavailable-start').val(), 'dd/MM/yyyy HH:mm');
|
|
|
|
var end = Date.parseExact($dialog.find('#unavailable-end').val(), 'dd/MM/yyyy HH:mm');
|
|
|
|
|
|
|
|
if (start > end) {
|
|
|
|
// Start time is after end time - display message to user.
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['start_date_before_end_error']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2013-07-09 17:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unavailable period records go to the appointments table.
|
|
|
|
var unavailable = {
|
|
|
|
'start_datetime': start.toString('yyyy-MM-dd HH:mm'),
|
|
|
|
'end_datetime': end.toString('yyyy-MM-dd HH:mm'),
|
|
|
|
'notes': $dialog.find('#unavailable-notes').val(),
|
|
|
|
'id_users_provider': $('#select-filter-item').val() // curr provider
|
|
|
|
};
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if ($dialog.find('#unavailable-id').val() !== '') {
|
|
|
|
// Set the id value, only if we are editing an appointment.
|
|
|
|
unavailable.id = $dialog.find('#unavailable-id').val();
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
var successCallback = function(response) {
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
console.log('Save Unavailable Time Period Response:', response);
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
2013-07-10 16:57:24 +03:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['unexpected_issues_occurred']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
// Display success message to the user.
|
2013-12-26 15:32:25 +02:00
|
|
|
$dialog.find('.modal-message').text(EALang['unavailable_saved']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').removeClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').addClass('alert-success');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
// Close the modal dialog and refresh the calendar appointments
|
|
|
|
// after one second.
|
|
|
|
setTimeout(function() {
|
2013-11-23 21:10:31 +02:00
|
|
|
$dialog.find('.alert').fadeOut();
|
2013-07-10 16:57:24 +03:00
|
|
|
$dialog.modal('hide');
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
}, 2000);
|
2013-07-09 17:46:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
var errorCallback = function(jqXHR, textStatus, errorThrown) {
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
console.log('Save Unavailable Error:', jqXHR, textStatus, errorThrown);
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
GeneralFunctions.displayMessageBox('Communication Error', 'Unfortunately ' +
|
|
|
|
'the operation could not complete due to server communication errors.');
|
2013-07-10 16:57:24 +03:00
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-message').txt(EALang['service_communication_error']);
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error');
|
|
|
|
$dialog.find('.modal-message').fadeIn();
|
2013-07-09 17:46:48 +03:00
|
|
|
};
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
BackendCalendar.saveUnavailable(unavailable, successCallback, errorCallback);
|
2013-07-09 17:46:48 +03:00
|
|
|
});
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
/**
|
|
|
|
* Event: Manage Unavailable Dialog Cancel Button "Click"
|
|
|
|
*
|
|
|
|
* Closes the dialog without saveing any changes to the database.
|
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
$('#manage-unavailable #cancel-unavailable').click(function() {
|
|
|
|
$('#manage-unavailable').modal('hide');
|
|
|
|
});
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
/**
|
2013-06-19 22:29:00 +03:00
|
|
|
* Event: Enable - Disable Synchronization Button "Click"
|
2013-06-18 19:06:34 +03:00
|
|
|
*
|
|
|
|
* When the user clicks on the "Enable Sync" button, a popup should appear
|
|
|
|
* that is going to follow the web server authorization flow of OAuth.
|
|
|
|
*/
|
|
|
|
$('#enable-sync').click(function() {
|
2013-06-19 22:29:00 +03:00
|
|
|
if ($('#enable-sync').hasClass('enabled') === false) {
|
|
|
|
// :: ENABLE SYNCHRONIZATION FOR SELECTED PROVIDER
|
2015-05-20 23:26:11 +03:00
|
|
|
var authUrl = GlobalVariables.baseUrl + '/index.php/google/oauth/'
|
2013-06-19 22:29:00 +03:00
|
|
|
+ $('#select-filter-item').val();
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var redirectUrl = GlobalVariables.baseUrl + '/index.php/google/oauth_callback';
|
2013-06-19 22:29:00 +03:00
|
|
|
|
|
|
|
var windowHandle = window.open(authUrl, 'Authorize Easy!Appointments',
|
|
|
|
'width=800, height=600');
|
|
|
|
|
|
|
|
var authInterval = window.setInterval(function() {
|
|
|
|
// When the browser redirects to the google user consent page the
|
|
|
|
// "window.document" variable 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.
|
|
|
|
if (windowHandle.document !== undefined) {
|
|
|
|
if (windowHandle.document.URL.indexOf(redirectUrl) !== -1) {
|
|
|
|
// The user has granted access to his data.
|
|
|
|
windowHandle.close();
|
|
|
|
window.clearInterval(authInterval);
|
2015-08-13 21:33:47 +03:00
|
|
|
$('#enable-sync').addClass('btn-danger enabled');
|
2015-07-27 23:29:20 +03:00
|
|
|
$('#enable-sync span:eq(1)').text(EALang['disable_sync']);
|
2013-06-19 22:29:00 +03:00
|
|
|
$('#google-sync').prop('disabled', false);
|
2013-11-07 13:25:59 +02:00
|
|
|
$('#select-filter-item option:selected').attr('google-sync', 'true');
|
2013-12-25 03:22:37 +02:00
|
|
|
|
2013-12-26 02:57:59 +02:00
|
|
|
// 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.
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_google_calendars';
|
2013-12-26 02:57:59 +02:00
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-12-26 02:57:59 +02:00
|
|
|
'provider_id': $('#select-filter-item').val()
|
|
|
|
};
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
console.log('Get Available Google Calendars Response', response);
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
|
|
|
|
|
|
|
$('#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');
|
2013-06-19 22:29:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// :: DISABLE SYNCHRONIZATION FOR SELECTED PROVIDER
|
|
|
|
// Update page elements and make an ajax call to remove the google
|
|
|
|
// sync setting of the selected provider.
|
|
|
|
$.each(GlobalVariables.availableProviders, function(index, provider) {
|
|
|
|
if (provider['id'] == $('#select-filter-item').val()) {
|
|
|
|
provider['settings']['google_sync'] = '0';
|
|
|
|
provider['settings']['google_token'] = null;
|
|
|
|
|
|
|
|
BackendCalendar.disableProviderSync(provider['id']);
|
|
|
|
|
|
|
|
$('#enable-sync').removeClass('btn-success enabled');
|
2015-07-27 23:29:20 +03:00
|
|
|
$('#enable-sync span:eq(1)').text(EALang['enable_sync']);
|
2013-06-19 22:29:00 +03:00
|
|
|
$('#google-sync').prop('disabled', true);
|
2013-11-07 13:25:59 +02:00
|
|
|
$('#select-filter-item option:selected').attr('google-sync', 'false');
|
2013-06-19 22:29:00 +03:00
|
|
|
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
2013-06-19 22:29:00 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
});
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
/**
|
2013-07-03 20:27:00 +03:00
|
|
|
* Event: Insert Appointment Button "Click"
|
2013-06-29 00:54:12 +03:00
|
|
|
*
|
|
|
|
* When the user presses this button, the manage appointment dialog opens and lets
|
|
|
|
* the user to create a new appointment.
|
|
|
|
*/
|
|
|
|
$('#insert-appointment').click(function() {
|
|
|
|
BackendCalendar.resetAppointmentDialog();
|
2013-07-06 03:00:04 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
2013-11-22 18:19:52 +02:00
|
|
|
|
|
|
|
// 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') {
|
|
|
|
var $providerOption = $dialog.find('#select-provider option[value="'
|
|
|
|
+ $('#select-filter-item').val() + '"]');
|
|
|
|
if ($providerOption.length == 0) { // Change the services until you find the correct.
|
|
|
|
$.each($dialog.find('#select-service option'), function() {
|
|
|
|
$(this).prop('selected', true).parent().change();
|
|
|
|
if ($providerOption.length > 0)
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$providerOption.prop('selected', true);
|
|
|
|
} else {
|
|
|
|
$dialog.find('#select-service option[value="'
|
|
|
|
+ $('#select-filter-item').val() + '"]').prop('selected', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
var serviceDuration = 0;
|
|
|
|
$.each(GlobalVariables.availableServices, function(index, service) {
|
|
|
|
if (service['id'] == $dialog.find('#select-service').val()) {
|
|
|
|
serviceDuration = service['duration'];
|
|
|
|
return false; // exit loop
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var start = new Date();
|
|
|
|
var currentMin = parseInt(start.toString('mm'));
|
|
|
|
|
|
|
|
if (currentMin > 0 && currentMin < 15)
|
|
|
|
start.set({ 'minute': 15 });
|
|
|
|
else if (currentMin > 15 && currentMin < 30)
|
|
|
|
start.set({ 'minute': 30 });
|
|
|
|
else if (currentMin > 30 && currentMin < 45)
|
|
|
|
start.set({ 'minute': 45 });
|
|
|
|
else
|
|
|
|
start.addHours(1).set({ 'minute': 0 });
|
|
|
|
|
|
|
|
$dialog.find('#start-datetime').val(start.toString('dd/MM/yyyy HH:mm'));
|
|
|
|
$dialog.find('#end-datetime').val(start.addMinutes(serviceDuration).toString('dd/MM/yyyy HH:mm'));
|
|
|
|
|
|
|
|
// Display modal form.
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-header h3').text(EALang['new_appointment_title']);
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.modal('show');
|
2013-06-29 00:54:12 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event : Insert Unavailable Time Period Button "Click"
|
|
|
|
*
|
|
|
|
* When the user clicks this button a popup dialog appears and the use can set
|
|
|
|
* a time period where he cannot accept any appointments.
|
|
|
|
*/
|
|
|
|
$('#insert-unavailable').click(function() {
|
2013-07-09 17:46:48 +03:00
|
|
|
BackendCalendar.resetUnavailableDialog();
|
|
|
|
var $dialog = $('#manage-unavailable');
|
2013-11-23 21:10:31 +02:00
|
|
|
|
|
|
|
// Set the default datetime values.
|
|
|
|
var start = new Date();
|
|
|
|
var currentMin = parseInt(start.toString('mm'));
|
|
|
|
|
|
|
|
if (currentMin > 0 && currentMin < 15)
|
|
|
|
start.set({ 'minute': 15 });
|
|
|
|
else if (currentMin > 15 && currentMin < 30)
|
|
|
|
start.set({ 'minute': 30 });
|
|
|
|
else if (currentMin > 30 && currentMin < 45)
|
|
|
|
start.set({ 'minute': 45 });
|
|
|
|
else
|
|
|
|
start.addHours(1).set({ 'minute': 0 });
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-start').val(start.toString('dd/MM/yyyy HH:mm'));
|
|
|
|
$dialog.find('#unavailable-end').val(start.addHours(1).toString('dd/MM/yyyy HH:mm'));
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
$dialog.find('.modal-header h3').text(EALang['new_unavailable_title']);
|
2013-07-09 17:46:48 +03:00
|
|
|
$dialog.modal('show');
|
2013-06-29 00:54:12 +03:00
|
|
|
});
|
2013-09-26 19:06:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Pick Existing Customer Button "Click"
|
|
|
|
*/
|
|
|
|
$('#select-customer').click(function() {
|
|
|
|
var $list = $('#existing-customers-list');
|
|
|
|
|
|
|
|
if (!$list.is(':visible')) {
|
2013-12-20 19:44:44 +02:00
|
|
|
$(this).text(EALang['hide']);
|
2013-09-26 19:06:57 +03:00
|
|
|
$list.empty();
|
|
|
|
$list.slideDown('slow');
|
|
|
|
$('#filter-existing-customers').fadeIn('slow');
|
|
|
|
$('#filter-existing-customers').val('');
|
|
|
|
$.each(GlobalVariables.customers, function(index, c) {
|
|
|
|
$list.append('<div data-id="' + c.id + '">'
|
|
|
|
+ c.first_name + ' ' + c.last_name + '</div>');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$list.slideUp('slow');
|
|
|
|
$('#filter-existing-customers').fadeOut('slow');
|
2013-12-20 19:44:44 +02:00
|
|
|
$(this).text(EALang['select']);
|
2013-09-26 19:06:57 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Select Existing Customer From List "Click"
|
|
|
|
*/
|
|
|
|
$(document).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);
|
2014-01-11 02:07:25 +02:00
|
|
|
$('#customer-notes').val(c.notes);
|
2013-09-26 19:06:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-customer').trigger('click'); // hide list
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Filter Existing Customers "Change"
|
|
|
|
*/
|
|
|
|
$('#filter-existing-customers').keyup(function() {
|
2013-11-22 18:19:52 +02:00
|
|
|
var key = $(this).val().toLowerCase();
|
2013-09-26 19:06:57 +03:00
|
|
|
var $list = $('#existing-customers-list');
|
|
|
|
$list.empty();
|
|
|
|
$.each(GlobalVariables.customers, function(index, c) {
|
2013-11-22 18:19:52 +02:00
|
|
|
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) {
|
2013-09-26 19:06:57 +03:00
|
|
|
$list.append('<div data-id="' + c.id + '">'
|
|
|
|
+ c.first_name + ' ' + c.last_name + '</div>');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Selected Service "Change"
|
|
|
|
*
|
|
|
|
* When the user clicks on a service, its available providers should
|
|
|
|
* become visible.
|
|
|
|
*/
|
|
|
|
$('#select-service').change(function() {
|
|
|
|
var sid = $('#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 == sid) {
|
|
|
|
var optionHtml = '<option value="' + provider['id'] + '">'
|
2013-11-22 18:19:52 +02:00
|
|
|
+ provider['first_name'] + ' ' + provider['last_name']
|
2013-09-26 19:06:57 +03:00
|
|
|
+ '</option>';
|
|
|
|
$('#select-provider').append(optionHtml);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-09-27 15:49:29 +03:00
|
|
|
/**
|
|
|
|
* Event: Enter New Customer Button "Click"
|
|
|
|
*/
|
|
|
|
$('#new-customer').click(function() {
|
|
|
|
$('#manage-appointment').find('#customer-id, #first-name, #last-name, #email, '
|
2013-11-24 17:45:44 +02:00
|
|
|
+ '#phone-number, #address, #city, #zip-code, #customer-notes').val('');
|
2013-09-27 15:49:29 +03:00
|
|
|
});
|
2013-12-26 02:57:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Select Google Calendar "Click"
|
|
|
|
*/
|
|
|
|
$('#select-calendar').click(function() {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_select_google_calendar';
|
2013-12-26 02:57:59 +02:00
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-12-26 02:57:59 +02:00
|
|
|
'provider_id': $('#select-filter-item').val(),
|
|
|
|
'calendar_id': $('#google-calendar').val()
|
|
|
|
};
|
|
|
|
$.post(postUrl, postData, function(response){
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
console.log('Select Google Calendar Response', response);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
|
|
|
Backend.displayNotification(EALang['google_calendar_selected']);
|
|
|
|
$('#select-google-calendar').modal('hide');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Close Google Calendar "Click"
|
|
|
|
*/
|
|
|
|
$('#close-calendar').click(function() {
|
|
|
|
$('#select-google-calendar').modal('hide');
|
|
|
|
});
|
2013-06-12 18:31:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method calculates the proper calendar height, in order to be displayed
|
|
|
|
* correctly, even when the browser window is resizing.
|
|
|
|
*
|
|
|
|
* @return {int} Returns the calendar element height in pixels.
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
getCalendarHeight: function () {
|
2013-06-12 18:31:16 +03:00
|
|
|
var result = window.innerHeight - $('#footer').height() - $('#header').height()
|
2013-10-17 18:31:43 +03:00
|
|
|
- $('#calendar-toolbar').height() - 50; // 80 for fine tuning
|
2013-06-12 18:31:16 +03:00
|
|
|
return (result > 500) ? result : 500; // Minimum height is 500px
|
2013-06-13 19:25:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method reloads the registered appointments for the selected date period
|
|
|
|
* and filter type.
|
|
|
|
*
|
2013-07-06 03:00:04 +03:00
|
|
|
* @param {object} $calendar The calendar jQuery object.
|
2013-06-13 19:25:34 +03:00
|
|
|
* @param {int} recordId The selected record id.
|
|
|
|
* @param {string} filterType The filter type, could be either FILTER_TYPE_PROVIDER
|
2014-01-15 17:48:58 +02:00
|
|
|
* or FILTER_TYPE_SERVICE.
|
2013-06-13 19:25:34 +03:00
|
|
|
* @param {date} startDate Visible start date of the calendar.
|
|
|
|
* @param {type} endDate Visible end date of the calendar.
|
|
|
|
*/
|
2013-10-20 19:45:46 +03:00
|
|
|
refreshCalendarAppointments: function($calendar, recordId, filterType, startDate, endDate) {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_calendar_appointments';
|
2013-06-13 19:25:34 +03:00
|
|
|
var postData = {
|
2015-05-28 00:42:40 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-07-03 20:27:00 +03:00
|
|
|
'record_id': recordId,
|
|
|
|
'start_date': startDate.toString('yyyy-MM-dd'),
|
|
|
|
'end_date': endDate.toString('yyyy-MM-dd'),
|
|
|
|
'filter_type': filterType
|
2013-06-13 19:25:34 +03:00
|
|
|
};
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
$.post(postUrl, postData, function(response) {
|
2013-06-13 19:25:34 +03:00
|
|
|
////////////////////////////////////////////////////////////////////
|
2013-10-20 19:45:46 +03:00
|
|
|
console.log('Refresh Calendar Appointments Response :', response);
|
2013-06-13 19:25:34 +03:00
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-10-20 19:45:46 +03:00
|
|
|
if (!GeneralFunctions.handleAjaxExceptions(response)) return;
|
2013-07-05 11:39:52 +03:00
|
|
|
|
2013-07-05 19:20:33 +03:00
|
|
|
// :: ADD APPOINTMENTS TO CALENDAR
|
2013-07-06 03:00:04 +03:00
|
|
|
var calendarEvents = [];
|
2013-07-10 16:57:24 +03:00
|
|
|
var $calendar = $('#calendar');
|
2013-06-13 19:25:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$.each(response.appointments, function(index, appointment){
|
2013-06-13 19:25:34 +03:00
|
|
|
var event = {
|
2013-07-03 20:27:00 +03:00
|
|
|
'id': appointment['id'],
|
|
|
|
'title': appointment['service']['name'] + ' - '
|
|
|
|
+ appointment['customer']['first_name'] + ' '
|
|
|
|
+ appointment['customer']['last_name'],
|
|
|
|
'start': appointment['start_datetime'],
|
|
|
|
'end': appointment['end_datetime'],
|
|
|
|
'allDay': false,
|
|
|
|
'data': appointment // Store appointment data for later use.
|
2013-06-13 19:25:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
calendarEvents.push(event);
|
|
|
|
});
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
$calendar.fullCalendar('removeEvents');
|
|
|
|
$calendar.fullCalendar('addEventSource', calendarEvents);
|
2013-07-05 11:39:52 +03:00
|
|
|
|
2013-07-05 19:20:33 +03:00
|
|
|
// :: ADD PROVIDER'S UNAVAILABLE TIME PERIODS
|
2013-07-10 16:57:24 +03:00
|
|
|
var calendarView = $calendar.fullCalendar('getView').name;
|
|
|
|
|
2013-10-20 19:45:46 +03:00
|
|
|
if (filterType === BackendCalendar.FILTER_TYPE_PROVIDER && calendarView !== 'month') {
|
2013-07-05 19:20:33 +03:00
|
|
|
$.each(GlobalVariables.availableProviders, function(index, provider) {
|
|
|
|
if (provider['id'] == recordId) {
|
2013-10-20 19:45:46 +03:00
|
|
|
var workingPlan = jQuery.parseJSON(provider.settings.working_plan);
|
2013-07-05 19:20:33 +03:00
|
|
|
var unavailablePeriod;
|
|
|
|
|
|
|
|
switch(calendarView) {
|
|
|
|
case 'agendaDay':
|
2013-07-10 16:57:24 +03:00
|
|
|
var selDayName = $calendar.fullCalendar('getView')
|
2013-07-05 19:20:33 +03:00
|
|
|
.start.toString('dddd').toLowerCase();
|
|
|
|
|
2014-01-15 17:48:58 +02:00
|
|
|
// Add custom unavailable periods.
|
|
|
|
$.each(response.unavailables, function(index, unavailable) {
|
|
|
|
var unavailablePeriod = {
|
|
|
|
'title': EALang['unavailable'] + ' <br><small>' + ((unavailable.notes.length > 30)
|
|
|
|
? unavailable.notes.substring(0, 30) + '...'
|
|
|
|
: unavailable.notes) + '</small>',
|
|
|
|
'start': Date.parse(unavailable.start_datetime),
|
|
|
|
'end': Date.parse(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[selDayName] == null) {
|
|
|
|
unavailablePeriod = {
|
|
|
|
'title': EALang['not_working'],
|
|
|
|
'start': GeneralFunctions.clone($calendar.fullCalendar('getView').start),
|
|
|
|
'end': GeneralFunctions.clone($calendar.fullCalendar('getView').end),
|
|
|
|
'allDay': false,
|
|
|
|
'color': '#BEBEBE',
|
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable'
|
|
|
|
};
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
|
|
|
return; // go to next loop
|
|
|
|
}
|
2013-10-17 18:31:43 +03:00
|
|
|
|
2013-07-05 19:20:33 +03:00
|
|
|
// Add unavailable period before work starts.
|
2013-07-10 16:57:24 +03:00
|
|
|
var calendarDateStart = $calendar.fullCalendar('getView').start;
|
2013-07-05 19:20:33 +03:00
|
|
|
var workDateStart = Date.parseExact(
|
|
|
|
calendarDateStart.toString('dd/MM/yyyy') + ' '
|
|
|
|
+ workingPlan[selDayName].start,
|
|
|
|
'dd/MM/yyyy HH:mm');
|
|
|
|
|
|
|
|
if (calendarDateStart < workDateStart) {
|
|
|
|
unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['not_working'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': calendarDateStart,
|
|
|
|
'end': workDateStart,
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable'
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2013-07-05 19:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add unavailable period after work ends.
|
2013-07-10 16:57:24 +03:00
|
|
|
var calendarDateEnd = $calendar.fullCalendar('getView').end;
|
2013-07-05 19:20:33 +03:00
|
|
|
var workDateEnd = Date.parseExact(
|
|
|
|
calendarDateStart.toString('dd/MM/yyyy') + ' '
|
|
|
|
+ workingPlan[selDayName].end,
|
|
|
|
'dd/MM/yyyy HH:mm'); // Use calendarDateStart ***
|
|
|
|
if (calendarDateEnd > workDateEnd) {
|
|
|
|
var unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['not_working'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': workDateEnd,
|
|
|
|
'end': calendarDateEnd,
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable'
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2013-07-05 19:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add unavailable periods for breaks.
|
|
|
|
var breakStart, breakEnd;
|
|
|
|
$.each(workingPlan[selDayName].breaks, function(index, currBreak) {
|
|
|
|
breakStart = Date.parseExact(calendarDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + currBreak.start, 'dd/MM/yyyy HH:mm');
|
|
|
|
breakEnd = Date.parseExact(calendarDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + currBreak.end, 'dd/MM/yyyy HH:mm');
|
|
|
|
var unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['break'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': breakStart,
|
|
|
|
'end': breakEnd,
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable fc-break'
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2013-07-05 19:20:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'agendaWeek':
|
2013-07-10 16:57:24 +03:00
|
|
|
var currDateStart = GeneralFunctions.clone($calendar.fullCalendar('getView').start);
|
2013-07-05 19:20:33 +03:00
|
|
|
var currDateEnd = GeneralFunctions.clone(currDateStart).addDays(1);
|
|
|
|
|
2014-01-15 17:48:58 +02:00
|
|
|
// 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) {
|
|
|
|
//if (currDateStart.toString('dd/MM/yyyy')
|
|
|
|
// === Date.parse(unavailable.start_datetime).toString('dd/MM/yyyy')) {
|
|
|
|
unavailablePeriod = {
|
|
|
|
'title': EALang['unavailable'] + ' <br><small>' + ((unavailable.notes.length > 30)
|
|
|
|
? unavailable.notes.substring(0, 30) + '...'
|
|
|
|
: unavailable.notes) + '</small>',
|
|
|
|
'start': Date.parse(unavailable.start_datetime),
|
|
|
|
'end': Date.parse(unavailable.end_datetime),
|
|
|
|
'allDay': false,
|
|
|
|
'color': '#879DB4',
|
|
|
|
'editable': true,
|
|
|
|
'className': 'fc-unavailable fc-custom',
|
|
|
|
'data': unavailable
|
|
|
|
};
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
//}
|
|
|
|
});
|
|
|
|
|
2013-12-19 18:28:19 +02:00
|
|
|
$.each(workingPlan, function(index, workingDay) {
|
2013-10-20 19:45:46 +03:00
|
|
|
|
|
|
|
if (workingDay == null) {
|
|
|
|
// Add a full day unavailable event.
|
|
|
|
unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['not_working'],
|
2013-10-20 19:45:46 +03:00
|
|
|
'start': GeneralFunctions.clone(currDateStart),
|
|
|
|
'end': GeneralFunctions.clone(currDateEnd),
|
|
|
|
'allDay': false,
|
|
|
|
'color': '#BEBEBE',
|
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable'
|
|
|
|
};
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
|
|
|
currDateStart.addDays(1);
|
|
|
|
currDateEnd.addDays(1);
|
|
|
|
return; // Go to the next loop.
|
|
|
|
}
|
|
|
|
|
2013-07-05 19:20:33 +03:00
|
|
|
var start, end;
|
|
|
|
|
|
|
|
// Add unavailable period before work starts.
|
|
|
|
start = Date.parseExact(currDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + workingDay.start, 'dd/MM/yyyy HH:mm');
|
|
|
|
if (currDateStart < start) {
|
|
|
|
unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['not_working'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': GeneralFunctions.clone(currDateStart),
|
|
|
|
'end': GeneralFunctions.clone(start),
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable'
|
|
|
|
};
|
2013-10-20 19:45:46 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, true);
|
2013-07-05 19:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add unavailable period after work ends.
|
|
|
|
end = Date.parseExact(currDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + workingDay.end, 'dd/MM/yyyy HH:mm');
|
|
|
|
if (currDateEnd > end) {
|
|
|
|
unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['not_working'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': GeneralFunctions.clone(end),
|
|
|
|
'end': GeneralFunctions.clone(currDateEnd),
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable fc-brake'
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2013-07-05 19:20:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add unavailable periods during day breaks.
|
|
|
|
var breakStart, breakEnd;
|
|
|
|
$.each(workingDay.breaks, function(index, currBreak) {
|
|
|
|
breakStart = Date.parseExact(currDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + currBreak.start, 'dd/MM/yyyy HH:mm');
|
|
|
|
breakEnd = Date.parseExact(currDateStart.toString('dd/MM/yyyy')
|
|
|
|
+ ' ' + currBreak.end, 'dd/MM/yyyy HH:mm');
|
|
|
|
var unavailablePeriod = {
|
2013-12-20 19:44:44 +02:00
|
|
|
'title': EALang['break'],
|
2013-07-05 19:20:33 +03:00
|
|
|
'start': breakStart,
|
|
|
|
'end': breakEnd,
|
|
|
|
'allDay': false,
|
2013-09-13 16:21:03 +03:00
|
|
|
'color': '#BEBEBE',
|
2013-07-05 19:20:33 +03:00
|
|
|
'editable': false,
|
|
|
|
'className': 'fc-unavailable fc-break'
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2013-07-05 19:20:33 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
currDateStart.addDays(1);
|
|
|
|
currDateEnd.addDays(1);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-10-27 19:41:37 +02:00
|
|
|
// Convert the titles to html code.
|
|
|
|
//BackendCalendar.convertTitlesToHtml();
|
2013-07-05 19:20:33 +03:00
|
|
|
}
|
2013-06-13 19:25:34 +03:00
|
|
|
}, 'json');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method stores the changes of an already registered appointment
|
|
|
|
* into the database, via an ajax call.
|
|
|
|
*
|
2013-07-06 03:00:04 +03:00
|
|
|
* @param {object} appointment Contain the new appointment data. The
|
2013-06-13 19:25:34 +03:00
|
|
|
* id of the appointment MUST be already included. The rest values must
|
|
|
|
* follow the database structure.
|
2013-07-06 03:00:04 +03:00
|
|
|
* @param {object} customer (OPTIONAL) contains the customer data.
|
2013-06-18 19:06:34 +03:00
|
|
|
* @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.
|
2013-06-13 19:25:34 +03:00
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
saveAppointment: function(appointment, customer, successCallback, errorCallback) {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2015-05-28 00:52:11 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'appointment_data': JSON.stringify(appointment)
|
|
|
|
};
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
if (customer !== undefined) {
|
|
|
|
postData['customer_data'] = JSON.stringify(customer);
|
2013-06-18 19:06:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
2013-07-03 20:27:00 +03:00
|
|
|
'type': 'POST',
|
|
|
|
'url': postUrl,
|
|
|
|
'data': postData,
|
|
|
|
'dataType': 'json',
|
|
|
|
'success': function(response) {
|
2013-06-18 19:06:34 +03:00
|
|
|
/////////////////////////////////////////////////////////////
|
2013-06-29 00:54:12 +03:00
|
|
|
console.log('Save Appointment Data Response:', response);
|
2013-06-18 19:06:34 +03:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (successCallback !== undefined) {
|
|
|
|
successCallback(response);
|
|
|
|
}
|
|
|
|
},
|
2013-07-03 20:27:00 +03:00
|
|
|
'error': function(jqXHR, textStatus, errorThrown) {
|
2013-06-18 19:06:34 +03:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2013-06-29 00:54:12 +03:00
|
|
|
console.log('Save Appointment Data Error:', jqXHR, textStatus,
|
2013-06-24 12:52:23 +03:00
|
|
|
errorThrown);
|
2013-06-18 19:06:34 +03:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if (errorCallback !== undefined) {
|
|
|
|
errorCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
/**
|
|
|
|
* Save unavailable period to database.
|
|
|
|
*
|
|
|
|
* @param {object} unavailable Containts the unavailable period data.
|
|
|
|
* @param {function} successCallback The ajax success callback function.
|
|
|
|
* @param {function} errorCallback The ajax failure callback function.
|
|
|
|
*/
|
2013-07-10 16:57:24 +03:00
|
|
|
saveUnavailable: function(unavailable, successCallback, errorCallback) {
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2013-07-09 17:46:48 +03:00
|
|
|
|
|
|
|
var postData = {
|
2015-07-20 22:13:34 +03:00
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
2013-07-09 17:46:48 +03:00
|
|
|
'unavailable': JSON.stringify(unavailable)
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
'type': 'POST',
|
|
|
|
'url': postUrl,
|
|
|
|
'data': postData,
|
|
|
|
'success': successCallback,
|
|
|
|
'error': errorCallback
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
/**
|
|
|
|
* Calendar Event "Resize" Callback
|
|
|
|
*
|
|
|
|
* The user can change the duration of an event by resizing an appointment
|
|
|
|
* object on the calendar. This change needs to be stored to the database
|
|
|
|
* too and this is done via an ajax call.
|
|
|
|
*
|
|
|
|
* @see updateAppointmentData()
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
calendarEventResize: function(event, dayDelta, minuteDelta, revertFunc,
|
2013-06-18 19:06:34 +03:00
|
|
|
jsEvent, ui, view) {
|
2013-09-26 19:06:57 +03:00
|
|
|
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
|
|
|
revertFunc();
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['no_privileges_edit_appointments']);
|
2013-09-26 19:06:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
$('#notification').hide('bind');
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (event.data.is_unavailable == false) {
|
|
|
|
// :: PREPARE THE APPOINTMENT DATA
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// Must delete the following because only appointment data should be
|
|
|
|
// provided to the ajax call.
|
|
|
|
delete appointment['customer'];
|
|
|
|
delete appointment['provider'];
|
|
|
|
delete appointment['service'];
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
appointment['end_datetime'] = Date.parseExact(
|
|
|
|
appointment['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ minutes: minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
// :: DEFINE THE SUCCESS CALLBACK FUNCTION
|
|
|
|
var successCallback = function(response) {
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
// Display warning information to the user.
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display success notification to user.
|
|
|
|
var undoFunction = function() {
|
|
|
|
appointment['end_datetime'] = Date.parseExact(
|
|
|
|
appointment['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'appointment_data': JSON.stringify(appointment)
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
revertFunc();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['appointment_updated'], [
|
2013-07-10 16:57:24 +03:00
|
|
|
{
|
|
|
|
'label': 'Undo',
|
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
2013-06-18 19:06:34 +03:00
|
|
|
};
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// :: UPDATE APPOINTMENT DATA VIA AJAX CALL
|
|
|
|
BackendCalendar.saveAppointment(appointment, undefined,
|
|
|
|
successCallback, undefined);
|
|
|
|
} else {
|
|
|
|
// :: UPDATE UNAVAILABLE TIME PERIOD
|
|
|
|
var unavailable = {
|
|
|
|
'id': event.data.id,
|
|
|
|
'start_datetime': event.start.toString('yyyy-MM-dd HH:mm:ss'),
|
|
|
|
'end_datetime': event.end.toString('yyyy-MM-dd HH:mm:ss'),
|
|
|
|
'id_users_provider': event.data.id_users_provider
|
|
|
|
};
|
|
|
|
|
|
|
|
// :: DEFINE THE SUCCESS CALLBACK FUNCTION
|
|
|
|
var successCallback = function(response) {
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
// Display warning information to the user.
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
2013-06-18 19:06:34 +03:00
|
|
|
}
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// Display success notification to user.
|
|
|
|
var undoFunction = function() {
|
|
|
|
unavailable['end_datetime'] = Date.parseExact(
|
|
|
|
unavailable['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'unavailable': JSON.stringify(unavailable)
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
revertFunc();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['unavailable_updated'], [
|
2013-07-10 16:57:24 +03:00
|
|
|
{
|
|
|
|
'label': 'Undo',
|
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
};
|
|
|
|
|
|
|
|
BackendCalendar.saveUnavailable(unavailable, successCallback, undefined);
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Window "Resize" Callback
|
|
|
|
*
|
|
|
|
* The calendar element needs to be resized too in order to fit into the
|
|
|
|
* window. Nevertheless, if the window becomes very small the the calendar
|
|
|
|
* won't shrink anymore.
|
|
|
|
*
|
|
|
|
* @see getCalendarHeight()
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
calendarWindowResize: function(view) {
|
2013-06-18 19:06:34 +03:00
|
|
|
$('#calendar').fullCalendar('option', 'height',
|
2013-11-21 23:58:51 +02:00
|
|
|
BackendCalendar.getCalendarHeight());
|
2013-06-18 19:06:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Day "Click" Callback
|
|
|
|
*
|
|
|
|
* When the user clicks on a day square on the calendar, then he will
|
|
|
|
* automatically be transfered to that day view calendar.
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
calendarDayClick: function(date, allDay, jsEvent, view) {
|
2013-06-18 19:06:34 +03:00
|
|
|
if (allDay) {
|
|
|
|
$('#calendar').fullCalendar('gotoDate', date);
|
|
|
|
$('#calendar').fullCalendar('changeView', 'agendaDay');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Event "Click" Callback
|
|
|
|
*
|
|
|
|
* When the user clicks on an appointment object on the calendar, then
|
|
|
|
* a data preview popover is display above the calendar item.
|
|
|
|
*/
|
2013-07-03 20:27:00 +03:00
|
|
|
calendarEventClick: function(event, jsEvent, view) {
|
|
|
|
$('.popover').remove(); // Close all open popovers.
|
|
|
|
|
2013-09-26 19:06:57 +03:00
|
|
|
var html, displayEdit, displayDelete;
|
2013-07-05 19:20:33 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
// Depending where the user clicked the event (title or empty space) we
|
|
|
|
// need to use different selectors to reach the parent element.
|
|
|
|
var $parent = $(jsEvent.target.offsetParent);
|
|
|
|
var $altParent = $(jsEvent.target).parents().eq(1);
|
|
|
|
|
|
|
|
if ($parent.hasClass('fc-unavailable') || $altParent.hasClass('fc-unavailable')) {
|
2013-09-26 19:06:57 +03:00
|
|
|
displayEdit = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
|
|
|
&& GlobalVariables.user.privileges.appointments.edit == true)
|
2013-07-10 16:57:24 +03:00
|
|
|
? '' : 'hide';
|
2013-09-27 15:49:29 +03:00
|
|
|
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
|
|
|
&& GlobalVariables.user.privileges.appointments.delete == true)
|
2013-09-26 19:06:57 +03:00
|
|
|
? '' : 'hide'; // Same value at the time.
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
var notes = '';
|
|
|
|
if (event.data) { // Only custom unavailable periods have notes.
|
|
|
|
notes = '<strong>Notes</strong> ' + event.data.notes;
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
html =
|
|
|
|
'<style type="text/css">'
|
|
|
|
+ '.popover-content strong {min-width: 80px; display:inline-block;}'
|
|
|
|
+ '.popover-content button {margin-right: 10px;}'
|
|
|
|
+ '</style>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['start'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.start.toString('dd/MM/yyyy HH:mm')
|
|
|
|
+ '<br>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['end'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.end.toString('dd/MM/yyyy HH:mm')
|
2013-07-10 16:57:24 +03:00
|
|
|
+ '<br>'
|
|
|
|
+ notes
|
|
|
|
+ '<hr>' +
|
2013-07-09 17:46:48 +03:00
|
|
|
'<center>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<button class="edit-popover btn btn-primary ' + displayEdit + '">' + EALang['edit'] + '</button>' +
|
|
|
|
'<button class="delete-popover btn btn-danger ' + displayDelete + '">' + EALang['delete'] + '</button>' +
|
|
|
|
'<button class="close-popover btn" data-po=' + jsEvent.target + '>' + EALang['close'] + '</button>' +
|
2013-07-09 17:46:48 +03:00
|
|
|
'</center>';
|
2013-09-26 19:06:57 +03:00
|
|
|
} else {
|
|
|
|
displayEdit = (GlobalVariables.user.privileges.appointments.edit == true)
|
|
|
|
? '' : 'hide';
|
|
|
|
displayDelete = (GlobalVariables.user.privileges.appointments.delete == true)
|
|
|
|
? '' : 'hide';
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
html =
|
|
|
|
'<style type="text/css">'
|
|
|
|
+ '.popover-content strong {min-width: 80px; display:inline-block;}'
|
|
|
|
+ '.popover-content button {margin-right: 10px;}'
|
|
|
|
+ '</style>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['start'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.start.toString('dd/MM/yyyy HH:mm')
|
|
|
|
+ '<br>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['end'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.end.toString('dd/MM/yyyy HH:mm')
|
|
|
|
+ '<br>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['service'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.data['service']['name']
|
|
|
|
+ '<br>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['provider'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.data['provider']['first_name'] + ' '
|
|
|
|
+ event.data['provider']['last_name']
|
|
|
|
+ '<br>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<strong>' + EALang['customer'] + '</strong> '
|
2013-07-09 17:46:48 +03:00
|
|
|
+ event.data['customer']['first_name'] + ' '
|
|
|
|
+ event.data['customer']['last_name']
|
|
|
|
+ '<hr>' +
|
|
|
|
'<center>' +
|
2013-12-20 19:44:44 +02:00
|
|
|
'<button class="edit-popover btn btn-primary ' + displayEdit + '">' + EALang['edit'] + '</button>' +
|
|
|
|
'<button class="delete-popover btn btn-danger ' + displayDelete + '">' + EALang['delete'] + '</button>' +
|
|
|
|
'<button class="close-popover btn" data-po=' + jsEvent.target + '>' + EALang['close'] + '</button>' +
|
2013-07-09 17:46:48 +03:00
|
|
|
'</center>';
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
$(jsEvent.target).popover({
|
2013-07-03 20:27:00 +03:00
|
|
|
'placement': 'top',
|
|
|
|
'title': event.title,
|
|
|
|
'content': html,
|
|
|
|
'html': true,
|
|
|
|
'container': 'body',
|
|
|
|
'trigger': 'manual'
|
2013-06-18 19:06:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
BackendCalendar.lastFocusedEventData = event;
|
2013-12-23 18:55:42 +02:00
|
|
|
$(jsEvent.target).popover('toggle');
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
// Fix popover position
|
2013-12-29 15:57:09 +02:00
|
|
|
if ($('.popover').length > 0) {
|
|
|
|
if ($('.popover').position().top < 200) $('.popover').css('top', '200px');
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Event "Drop" Callback
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
calendarEventDrop : function(event, dayDelta, minuteDelta, allDay,
|
|
|
|
revertFunc, jsEvent, ui, view) {
|
2013-09-26 19:06:57 +03:00
|
|
|
if (GlobalVariables.user.privileges.appointments.edit == false) {
|
|
|
|
revertFunc();
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['no_privileges_edit_appointments']);
|
2013-09-26 19:06:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-28 17:23:17 +03:00
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
$('#notification').hide('bind');
|
2013-07-10 16:57:24 +03:00
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (event.data.is_unavailable == false) {
|
|
|
|
|
|
|
|
// :: PREPARE THE APPOINTMENT DATA
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
|
|
|
|
|
|
|
// Must delete the following because only appointment data should be
|
|
|
|
// provided to the ajax call.
|
|
|
|
delete appointment['customer'];
|
|
|
|
delete appointment['provider'];
|
|
|
|
delete appointment['service'];
|
|
|
|
|
|
|
|
appointment['start_datetime'] = Date.parseExact(
|
|
|
|
appointment['start_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: dayDelta, minutes: minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
appointment['end_datetime'] = Date.parseExact(
|
|
|
|
appointment['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: dayDelta, minutes: minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
event.data['start_datetime'] = appointment['start_datetime'];
|
|
|
|
event.data['end_datetime'] = appointment['end_datetime'];
|
|
|
|
|
|
|
|
// :: DEFINE THE SUCCESS CALLBACK FUNCTION
|
|
|
|
var successCallback = function(response) {
|
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.warnings) {
|
|
|
|
// Display warning information to the user.
|
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define the undo function, if the user needs to reset the last change.
|
|
|
|
var undoFunction = function() {
|
|
|
|
appointment['start_datetime'] = Date.parseExact(
|
|
|
|
appointment['start_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: -dayDelta, minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
appointment['end_datetime'] = Date.parseExact(
|
|
|
|
appointment['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: -dayDelta, minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
event.data['start_datetime'] = appointment['start_datetime'];
|
|
|
|
event.data['end_datetime'] = appointment['end_datetime'];
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2013-07-10 16:57:24 +03:00
|
|
|
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'appointment_data': JSON.stringify(appointment)
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
revertFunc();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['appointment_updated'], [
|
2013-07-10 16:57:24 +03:00
|
|
|
{
|
|
|
|
'label': 'Undo',
|
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
};
|
|
|
|
|
|
|
|
// :: UPDATE APPOINTMENT DATA VIA AJAX CALL
|
|
|
|
BackendCalendar.saveAppointment(appointment, undefined,
|
|
|
|
successCallback, undefined);
|
|
|
|
} else {
|
|
|
|
// :: UPDATE UNAVAILABLE TIME PERIOD
|
|
|
|
var unavailable = {
|
|
|
|
'id': event.data.id,
|
|
|
|
'start_datetime': event.start.toString('yyyy-MM-dd HH:mm:ss'),
|
|
|
|
'end_datetime': event.end.toString('yyyy-MM-dd HH:mm:ss'),
|
|
|
|
'id_users_provider': event.data.id_users_provider
|
2013-07-03 20:27:00 +03:00
|
|
|
}
|
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
var successCallback = function(response) {
|
|
|
|
console.log('Drop Unavailable Event Response:', response);
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (response.exceptions) {
|
2013-12-26 02:57:59 +02:00
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
|
|
|
}
|
2013-07-03 20:27:00 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
if (response.warnings) {
|
2013-12-26 02:57:59 +02:00
|
|
|
response.warnings = GeneralFunctions.parseExceptions(response.warnings);
|
2013-10-27 19:41:37 +02:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.WARNINGS_TITLE, GeneralFunctions.WARNINGS_MESSAGE);
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.warnings));
|
|
|
|
}
|
|
|
|
|
|
|
|
var undoFunction = function() {
|
|
|
|
unavailable['start_datetime'] = Date.parseExact(
|
|
|
|
unavailable['start_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: -dayDelta, minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
unavailable['end_datetime'] = Date.parseExact(
|
|
|
|
unavailable['end_datetime'], 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
.add({ days: -dayDelta, minutes: -minuteDelta })
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
event.data['start_datetime'] = unavailable['start_datetime'];
|
|
|
|
event.data['end_datetime'] = unavailable['end_datetime'];
|
|
|
|
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2013-07-10 16:57:24 +03:00
|
|
|
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'unavailable': JSON.stringify(unavailable)
|
|
|
|
};
|
2013-07-10 16:57:24 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
revertFunc();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 19:44:44 +02:00
|
|
|
Backend.displayNotification(EALang['unavailable_updated'], [
|
2013-07-10 16:57:24 +03:00
|
|
|
{
|
|
|
|
'label': 'Undo',
|
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
2013-06-18 19:06:34 +03:00
|
|
|
|
2013-07-10 16:57:24 +03:00
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
};
|
|
|
|
|
|
|
|
BackendCalendar.saveUnavailable(unavailable, successCallback, undefined);
|
|
|
|
}
|
2013-06-18 19:06:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar "View Display" Callback
|
|
|
|
*
|
|
|
|
* Whenever the calendar changes or refreshes its view certain actions
|
|
|
|
* need to be made, in order to display proper information to the user.
|
|
|
|
*/
|
|
|
|
calendarViewDisplay : function(view) {
|
2013-07-09 17:46:48 +03:00
|
|
|
if ($('#select-filter-item').val() === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-18 19:06:34 +03:00
|
|
|
BackendCalendar.refreshCalendarAppointments(
|
|
|
|
$('#calendar'),
|
|
|
|
$('#select-filter-item').val(),
|
|
|
|
$('#select-filter-item option:selected').attr('type'),
|
|
|
|
$('#calendar').fullCalendar('getView').visStart,
|
|
|
|
$('#calendar').fullCalendar('getView').visEnd);
|
2013-10-27 19:41:37 +02:00
|
|
|
$(window).trigger('resize'); // Places the footer on the bottom.
|
2013-11-21 23:58:51 +02:00
|
|
|
|
2013-10-27 19:41:37 +02:00
|
|
|
// Remove all open popovers.
|
|
|
|
$('.close-popover').each(function() {
|
|
|
|
$(this).parents().eq(2).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add new pop overs.
|
2013-06-18 19:06:34 +03:00
|
|
|
$('.fv-events').each(function(index, eventHandle) {
|
|
|
|
$(eventHandle).popover();
|
|
|
|
});
|
2013-06-19 22:29:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method disables the google synchronization for a specific provider.
|
|
|
|
*
|
|
|
|
* @param {int} providerId The selected provider record id.
|
|
|
|
*/
|
|
|
|
disableProviderSync: function(providerId) {
|
|
|
|
// Make an ajax call to the server in order to disable the setting
|
|
|
|
// from the database.
|
2015-05-20 23:26:11 +03:00
|
|
|
var postUrl = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_disable_provider_sync';
|
2015-05-28 00:42:40 +03:00
|
|
|
var postData = {
|
|
|
|
'csrfToken': GlobalVariables.csrfToken,
|
|
|
|
'provider_id': providerId
|
|
|
|
};
|
2013-06-19 22:29:00 +03:00
|
|
|
|
|
|
|
$.post(postUrl, postData, function(response) {
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
//console.log('Disable Provider Sync Response :', response);
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
2013-07-03 20:27:00 +03:00
|
|
|
if (response.exceptions) {
|
|
|
|
response.exceptions = GeneralFunctions.parseExceptions(response.exceptions);
|
2013-09-27 15:49:29 +03:00
|
|
|
GeneralFunctions.displayMessageBox(GeneralFunctions.EXCEPTIONS_TITLE, GeneralFunctions.EXCEPTIONS_MESSAGE);
|
2013-07-03 20:27:00 +03:00
|
|
|
$('#message_box').append(GeneralFunctions.exceptionsToHtml(response.exceptions));
|
|
|
|
return;
|
2013-06-19 22:29:00 +03:00
|
|
|
}
|
|
|
|
}, 'json');
|
2013-06-29 00:54:12 +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.
|
|
|
|
*/
|
|
|
|
resetAppointmentDialog: function() {
|
2013-07-06 03:00:04 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
// :: EMPTY FORM FIELDS
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('input, textarea').val('');
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').fadeOut();
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
// :: PREPARE SERVICE AND PROVIDER LISTBOXES
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#select-service').val(
|
|
|
|
$dialog.find('#select-service').eq(0).attr('value'));
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
// Fill the providers listbox with providers that can serve the appointment's
|
|
|
|
// service and then select the user's provider.
|
2013-11-23 21:10:31 +02:00
|
|
|
$dialog.find('#select-provider').empty();
|
2013-06-29 00:54:12 +03:00
|
|
|
$.each(GlobalVariables.availableProviders, function(index, provider) {
|
|
|
|
var canProvideService = false;
|
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
$.each(provider['services'], function(index, serviceId) {
|
|
|
|
if (serviceId == $dialog.find('#select-service').val()) {
|
2013-06-29 00:54:12 +03:00
|
|
|
canProvideService = true;
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (canProvideService) { // Add the provider to the listbox.
|
|
|
|
var option = new Option(provider['first_name']
|
|
|
|
+ ' ' + provider['last_name'], provider['id']);
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#select-provider').append(option);
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
});
|
2013-11-22 18:19:52 +02:00
|
|
|
|
|
|
|
// :: CLOSE EXISTING CUSTOMERS FILTER FRAME
|
|
|
|
$('#existing-customers-list').slideUp('slow');
|
|
|
|
$('#filter-existing-customers').fadeOut('slow');
|
2013-12-20 19:44:44 +02:00
|
|
|
$('#select-customer').text(EALang['select']);
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
// :: SETUP START AND END DATETIME PICKERS
|
|
|
|
// Get the selected service duration. It will be needed in order to calculate
|
|
|
|
// the appointment end datetime.
|
|
|
|
var serviceDuration = 0;
|
|
|
|
$.each(GlobalVariables.availableServices, function(index, service) {
|
2013-07-06 03:00:04 +03:00
|
|
|
if (service['id'] == $dialog.find('#select-service').val()) {
|
2013-06-29 00:54:12 +03:00
|
|
|
serviceDuration = service['duration'];
|
2013-09-25 18:43:17 +03:00
|
|
|
return false;
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-03 20:27:00 +03:00
|
|
|
var startDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout)
|
|
|
|
.toString('dd/MM/yyyy HH:mm');
|
|
|
|
var endDatetime = new Date().addMinutes(GlobalVariables.bookAdvanceTimeout)
|
|
|
|
.addMinutes(serviceDuration).toString('dd/MM/yyyy HH:mm');
|
2013-06-29 00:54:12 +03:00
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#start-datetime').datetimepicker({
|
2013-12-20 19:44:44 +02:00
|
|
|
'dateFormat': 'dd/mm/yy',
|
|
|
|
// Translation
|
|
|
|
dayNames: [EALang['sunday'], EALang['monday'], EALang['tuesday'], EALang['wednesday'],
|
|
|
|
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)],
|
|
|
|
monthNames: [EALang['january'], EALang['february'], EALang['march'], EALang['april'],
|
|
|
|
EALang['may'], EALang['june'], EALang['july'], EALang['august'], EALang['september'],
|
|
|
|
EALang['october'], EALang['november'], EALang['december']],
|
|
|
|
prevText: EALang['previous'],
|
|
|
|
nextText: EALang['next'],
|
|
|
|
currentText: EALang['now'],
|
|
|
|
closeText: EALang['close'],
|
|
|
|
timeOnlyTitle: EALang['select_time'],
|
|
|
|
timeText: EALang['time'],
|
|
|
|
hourText: EALang['hour'],
|
2014-01-04 19:25:21 +02:00
|
|
|
minuteText: EALang['minutes'],
|
|
|
|
firstDay: 1
|
2013-06-29 00:54:12 +03:00
|
|
|
});
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#start-datetime').val(startDatetime);
|
2013-06-29 00:54:12 +03:00
|
|
|
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#end-datetime').datetimepicker({
|
2013-12-20 19:44:44 +02:00
|
|
|
'dateFormat': 'dd/mm/yy',
|
|
|
|
// Translation
|
|
|
|
dayNames: [EALang['sunday'], EALang['monday'], EALang['tuesday'], EALang['wednesday'],
|
|
|
|
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)],
|
|
|
|
monthNames: [EALang['january'], EALang['february'], EALang['march'], EALang['april'],
|
|
|
|
EALang['may'], EALang['june'], EALang['july'], EALang['august'], EALang['september'],
|
|
|
|
EALang['october'], EALang['november'], EALang['december']],
|
|
|
|
prevText: EALang['previous'],
|
|
|
|
nextText: EALang['next'],
|
|
|
|
currentText: EALang['now'],
|
|
|
|
closeText: EALang['close'],
|
|
|
|
timeOnlyTitle: EALang['select_time'],
|
|
|
|
timeText: EALang['time'],
|
|
|
|
hourText: EALang['hour'],
|
2014-01-04 19:25:21 +02:00
|
|
|
minuteText: EALang['minutes'],
|
|
|
|
firstDay: 1
|
2013-06-29 00:54:12 +03:00
|
|
|
});
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('#end-datetime').val(endDatetime);
|
2013-06-29 00:54:12 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate the manage appointment dialog data. Validation checks need to
|
|
|
|
* run every time the data are going to be saved.
|
|
|
|
*
|
|
|
|
* @returns {bool} Returns the validation result.
|
|
|
|
*/
|
|
|
|
validateAppointmentForm: function() {
|
2013-07-06 03:00:04 +03:00
|
|
|
var $dialog = $('#manage-appointment');
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
// Reset previous validation css formating.
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('.control-group').removeClass('error');
|
2013-09-27 15:49:29 +03:00
|
|
|
$dialog.find('.modal-message').fadeOut();
|
2013-06-29 00:54:12 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
// :: CHECK REQUIRED FIELDS
|
|
|
|
var missingRequiredField = false;
|
2013-07-06 03:00:04 +03:00
|
|
|
$dialog.find('.required').each(function() {
|
2013-10-17 18:31:43 +03:00
|
|
|
if ($(this).val() == '' || $(this).val() == null) {
|
2013-06-29 00:54:12 +03:00
|
|
|
$(this).parents().eq(1).addClass('error');
|
|
|
|
missingRequiredField = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (missingRequiredField) {
|
2014-01-11 02:07:25 +02:00
|
|
|
throw EALang['fields_are_required'];
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// :: CHECK EMAIL ADDRESS
|
2013-07-06 03:00:04 +03:00
|
|
|
if (!GeneralFunctions.validateEmail($dialog.find('#email').val())) {
|
|
|
|
$dialog.find('#email').parents().eq(1).addClass('error');
|
2014-01-11 02:07:25 +02:00
|
|
|
throw EALang['invalid_email'];
|
2013-06-29 00:54:12 +03:00
|
|
|
}
|
|
|
|
|
2013-11-22 18:19:52 +02:00
|
|
|
// :: CHECK APPOINTMENT START AND END TIME
|
|
|
|
var start = Date.parseExact($('#start-datetime').val(), 'dd/MM/yyyy HH:mm');
|
|
|
|
var end = Date.parseExact($('#end-datetime').val(), 'dd/MM/yyyy HH:mm');
|
|
|
|
if (start > end) {
|
|
|
|
$dialog.find('#start-datetime').parents().eq(1).addClass('error');
|
|
|
|
$dialog.find('#end-datetime').parents().eq(1).addClass('error');
|
2014-01-11 02:07:25 +02:00
|
|
|
throw EALang['start_date_before_end_error'];
|
2013-11-22 18:19:52 +02:00
|
|
|
}
|
|
|
|
|
2013-06-29 00:54:12 +03:00
|
|
|
return true;
|
|
|
|
} catch(exc) {
|
2013-09-26 19:06:57 +03:00
|
|
|
$dialog.find('.modal-message').addClass('alert-error').text(exc).show('fade');
|
2013-06-29 00:54:12 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-05 11:39:52 +03:00
|
|
|
},
|
2013-07-09 17:46:48 +03:00
|
|
|
|
2013-07-05 11:39:52 +03:00
|
|
|
/**
|
2013-07-09 17:46:48 +03:00
|
|
|
* Reset the "#manage-unavailable" dialog. Use this method to bring the dialog
|
|
|
|
* to the initial state before it becomes visible to the user.
|
2013-07-05 11:39:52 +03:00
|
|
|
*/
|
2013-07-09 17:46:48 +03:00
|
|
|
resetUnavailableDialog: function() {
|
|
|
|
var $dialog = $('#manage-unavailable');
|
|
|
|
|
2014-01-04 19:25:21 +02:00
|
|
|
$dialog.find('#unavailable-id').val('');
|
|
|
|
|
2013-07-09 17:46:48 +03:00
|
|
|
// Set default time values
|
|
|
|
var start = new Date().toString('dd/MM/yyyy HH:mm');
|
|
|
|
var end = new Date().addHours(1).toString('dd/MM/yyyy HH:mm');
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-start').datetimepicker({
|
2013-12-20 19:44:44 +02:00
|
|
|
'dateFormat': 'dd/mm/yy',
|
|
|
|
// Translation
|
|
|
|
dayNames: [EALang['sunday'], EALang['monday'], EALang['tuesday'], EALang['wednesday'],
|
|
|
|
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)],
|
|
|
|
monthNames: [EALang['january'], EALang['february'], EALang['march'], EALang['april'],
|
|
|
|
EALang['may'], EALang['june'], EALang['july'], EALang['august'], EALang['september'],
|
|
|
|
EALang['october'], EALang['november'], EALang['december']],
|
|
|
|
prevText: EALang['previous'],
|
|
|
|
nextText: EALang['next'],
|
|
|
|
currentText: EALang['now'],
|
|
|
|
closeText: EALang['close'],
|
|
|
|
timeOnlyTitle: EALang['select_time'],
|
|
|
|
timeText: EALang['time'],
|
|
|
|
hourText: EALang['hour'],
|
2014-01-04 19:25:21 +02:00
|
|
|
minuteText: EALang['minutes'],
|
|
|
|
firstDay: 1
|
2013-07-09 17:46:48 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-start').val(start);
|
|
|
|
|
|
|
|
$dialog.find('#unavailable-end').datetimepicker({
|
2013-12-20 19:44:44 +02:00
|
|
|
'dateFormat': 'dd/mm/yy',
|
|
|
|
// Translation
|
|
|
|
dayNames: [EALang['sunday'], EALang['monday'], EALang['tuesday'], EALang['wednesday'],
|
|
|
|
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)],
|
|
|
|
monthNames: [EALang['january'], EALang['february'], EALang['march'], EALang['april'],
|
|
|
|
EALang['may'], EALang['june'], EALang['july'], EALang['august'], EALang['september'],
|
|
|
|
EALang['october'], EALang['november'], EALang['december']],
|
|
|
|
prevText: EALang['previous'],
|
|
|
|
nextText: EALang['next'],
|
|
|
|
currentText: EALang['now'],
|
|
|
|
closeText: EALang['close'],
|
|
|
|
timeOnlyTitle: EALang['select_time'],
|
|
|
|
timeText: EALang['time'],
|
|
|
|
hourText: EALang['hour'],
|
2014-01-04 19:25:21 +02:00
|
|
|
minuteText: EALang['minutes'],
|
|
|
|
firstDay: 1
|
2013-07-09 17:46:48 +03:00
|
|
|
});
|
|
|
|
$dialog.find('#unavailable-end').val(end);
|
|
|
|
|
|
|
|
// Clear the unavailable notes field.
|
|
|
|
$dialog.find('#unavailable-notes').val('');
|
2013-10-27 19:41:37 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On some calendar events the titles contain html markup that is not
|
|
|
|
* displayed properly due to the fullcalendar plugin. This plugin sets
|
|
|
|
* the .fc-event-title value by using the $.text() method and not the
|
2013-11-21 23:58:51 +02:00
|
|
|
* $.html() method. So in order for the title to displya the html properly
|
2013-10-27 19:41:37 +02:00
|
|
|
* we convert all the .fc-event-titles where needed into html.
|
|
|
|
*/
|
|
|
|
convertTitlesToHtml: function() {
|
|
|
|
// Convert the titles to html code.
|
|
|
|
$('.fc-custom').each(function() {
|
|
|
|
var title = $(this).find('.fc-event-title').text();
|
|
|
|
$(this).find('.fc-event-title').html(title);
|
2013-11-21 23:58:51 +02:00
|
|
|
var time = $(this).find('.fc-event-time').text();
|
|
|
|
$(this).find('.fc-event-time').html(time);
|
2013-10-27 19:41:37 +02:00
|
|
|
});
|
2013-06-12 18:31:16 +03:00
|
|
|
}
|
|
|
|
};
|