Backend calendar handling with timezones.

This commit is contained in:
Alex Tselegidis 2020-03-29 15:08:07 +02:00
parent 534d6e1761
commit 849f83ed03
6 changed files with 107 additions and 11 deletions

View file

@ -11,9 +11,9 @@
* @since v1.0.0
* ---------------------------------------------------------------------------- */
use \EA\Engine\Types\Text;
use \EA\Engine\Types\Email;
use \EA\Engine\Types\Url;
use EA\Engine\Types\Email;
use EA\Engine\Types\Text;
use EA\Engine\Types\Url;
/**
* Backend API Controller
@ -261,6 +261,7 @@ class Backend_api extends CI_Controller {
$this->load->model('services_model');
$this->load->model('customers_model');
$this->load->model('settings_model');
$this->load->model('timezones_model');
// :: SAVE CUSTOMER CHANGES TO DATABASE
if ($this->input->post('customer_data'))
@ -299,6 +300,16 @@ class Backend_api extends CI_Controller {
$appointment['id_users_customer'] = $customer['id'];
}
$provider_timezone = $this->timezones_model->get_user_timezone($appointment['id_users_provider']);
$session_timezone = $this->timezones_model->get_session_timezone();
$appointment['start_datetime'] = $this->timezones_model->convert($appointment['start_datetime'],
$session_timezone, $provider_timezone);
$appointment['end_datetime'] = $this->timezones_model->convert($appointment['end_datetime'],
$session_timezone, $provider_timezone);
$appointment['id'] = $this->appointments_model->add($appointment);
}

View file

@ -26,6 +26,9 @@ class Timezones_Model extends CI_Model {
* @var array
*/
protected $timezones = [
'UTC' => [
'UTC' => 'UTC'
],
'America' => [
'America/Adak' => 'Adak -10:00',
'America/Atka' => 'Atka -10:00',

View file

@ -187,6 +187,11 @@
<label for="appointment-location" class="control-label"><?= lang('location') ?></label>
<input id="appointment-location" class="form-control">
</div>
<div class="form-group">
<label for="appointment-notes" class="control-label"><?= lang('notes') ?></label>
<textarea id="appointment-notes" class="form-control" rows="3"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-6">
@ -201,8 +206,22 @@
</div>
<div class="form-group">
<label for="appointment-notes" class="control-label"><?= lang('notes') ?></label>
<textarea id="appointment-notes" class="form-control" rows="1"></textarea>
<label class="control-label"><?= lang('timezone') ?></label>
<ul>
<li>
<?= lang('provider') ?>:
<span class="provider-timezone">
-
</span>
</li>
<li>
<?= lang('current_user') ?>:
<span>
<?= $timezones[$timezone] ?>
</span>
</li>
</ul>
</div>
</div>
</div>
@ -316,6 +335,25 @@
<input id="unavailable-end" class="form-control">
</div>
<div class="form-group">
<label class="control-label"><?= lang('timezone') ?></label>
<ul>
<li>
<?= lang('provider') ?>:
<span class="provider-timezone">
-
</span>
</li>
<li>
<?= lang('current_user') ?>:
<span>
<?= $timezones[$timezone] ?>
</span>
</li>
</ul>
</div>
<div class="form-group">
<label for="unavailable-notes" class="control-label"><?= lang('notes') ?></label>
<textarea id="unavailable-notes" rows="3" class="form-control"></textarea>
@ -361,6 +399,25 @@
<label for="extra-end" class="control-label"><?= lang('end') ?></label>
<input id="extra-end" class="form-control">
</div>
<div class="form-group">
<label class="control-label"><?= lang('timezone') ?></label>
<ul>
<li>
<?= lang('provider') ?>:
<span class="provider-timezone">
-
</span>
</li>
<li>
<?= lang('current_user') ?>:
<span>
<?= $timezones[$timezone] ?>
</span>
</li>
</ul>
</div>
</fieldset>
</form>
</div>

View file

@ -1,5 +1,4 @@
<select <?= $attributes ?>>
<option value="UTC">UTC</option>
<?php foreach ($timezones as $continent => $entries): ?>
<optgroup label="<?= $continent ?>">
<?php foreach ($entries as $value => $name): ?>

View file

@ -22,6 +22,18 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
'use strict';
function _updateTimezone() {
var providerId = $('#select-provider').val();
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
return availableProvider.id == providerId;
}).shift();
if (provider && provider.timezone) {
$('.provider-timezone').text(GlobalVariables.timezones[provider.timezone]);
}
}
function _bindEventHandlers() {
/**
* Event: Manage Appointments Dialog Cancel Button "Click"
@ -318,10 +330,14 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
});
});
});
// If the appointment is opened from a link it triggers the previous function to fill the form
if (window.location.href.indexOf("backend/index/") > -1) {
$('#select-service').change();
}
/**
* Event: Provider "Change"
*/
$('#select-provider').change(function () {
_updateTimezone();
});
/**
* Event: Enter New Customer Button "Click"
*/

View file

@ -256,6 +256,16 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
$('#calendar').fullCalendar('option', 'selectable', true);
$('#calendar').fullCalendar('option', 'editable', true);
var providerId = $('#select-filter-item').val();
var provider = GlobalVariables.availableProviders.filter(function(availableProvider) {
return availableProvider.id == providerId;
}).shift();
if (provider && provider.timezone) {
$('.provider-timezone').text(GlobalVariables.timezones[provider.timezone]);
}
// If the user has already the sync enabled then apply the proper style changes.
if ($('#select-filter-item option:selected').attr('google-sync') === 'true') {
$('#enable-sync').addClass('btn-danger enabled');