Backend calendar handling with timezones.
This commit is contained in:
parent
534d6e1761
commit
849f83ed03
6 changed files with 107 additions and 11 deletions
|
@ -11,9 +11,9 @@
|
||||||
* @since v1.0.0
|
* @since v1.0.0
|
||||||
* ---------------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
use \EA\Engine\Types\Text;
|
use EA\Engine\Types\Email;
|
||||||
use \EA\Engine\Types\Email;
|
use EA\Engine\Types\Text;
|
||||||
use \EA\Engine\Types\Url;
|
use EA\Engine\Types\Url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backend API Controller
|
* Backend API Controller
|
||||||
|
@ -102,7 +102,7 @@ class Backend_api extends CI_Controller {
|
||||||
$userId = $this->session->userdata('user_id');
|
$userId = $this->session->userdata('user_id');
|
||||||
$roleSlug = $this->session->userdata('role_slug');
|
$roleSlug = $this->session->userdata('role_slug');
|
||||||
|
|
||||||
// If the current user is a provider he must only see his own appointments.
|
// If the current user is a provider he must only see his own appointments.
|
||||||
if ($roleSlug === DB_SLUG_PROVIDER)
|
if ($roleSlug === DB_SLUG_PROVIDER)
|
||||||
{
|
{
|
||||||
foreach ($response['appointments'] as $index => $appointment)
|
foreach ($response['appointments'] as $index => $appointment)
|
||||||
|
@ -261,6 +261,7 @@ class Backend_api extends CI_Controller {
|
||||||
$this->load->model('services_model');
|
$this->load->model('services_model');
|
||||||
$this->load->model('customers_model');
|
$this->load->model('customers_model');
|
||||||
$this->load->model('settings_model');
|
$this->load->model('settings_model');
|
||||||
|
$this->load->model('timezones_model');
|
||||||
|
|
||||||
// :: SAVE CUSTOMER CHANGES TO DATABASE
|
// :: SAVE CUSTOMER CHANGES TO DATABASE
|
||||||
if ($this->input->post('customer_data'))
|
if ($this->input->post('customer_data'))
|
||||||
|
@ -299,6 +300,16 @@ class Backend_api extends CI_Controller {
|
||||||
$appointment['id_users_customer'] = $customer['id'];
|
$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);
|
$appointment['id'] = $this->appointments_model->add($appointment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@ class Timezones_Model extends CI_Model {
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $timezones = [
|
protected $timezones = [
|
||||||
|
'UTC' => [
|
||||||
|
'UTC' => 'UTC'
|
||||||
|
],
|
||||||
'America' => [
|
'America' => [
|
||||||
'America/Adak' => 'Adak -10:00',
|
'America/Adak' => 'Adak -10:00',
|
||||||
'America/Atka' => 'Atka -10:00',
|
'America/Atka' => 'Atka -10:00',
|
||||||
|
|
|
@ -187,6 +187,11 @@
|
||||||
<label for="appointment-location" class="control-label"><?= lang('location') ?></label>
|
<label for="appointment-location" class="control-label"><?= lang('location') ?></label>
|
||||||
<input id="appointment-location" class="form-control">
|
<input id="appointment-location" class="form-control">
|
||||||
</div>
|
</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>
|
||||||
|
|
||||||
<div class="col-xs-12 col-sm-6">
|
<div class="col-xs-12 col-sm-6">
|
||||||
|
@ -201,8 +206,22 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="appointment-notes" class="control-label"><?= lang('notes') ?></label>
|
<label class="control-label"><?= lang('timezone') ?></label>
|
||||||
<textarea id="appointment-notes" class="form-control" rows="1"></textarea>
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?= lang('provider') ?>:
|
||||||
|
<span class="provider-timezone">
|
||||||
|
-
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?= lang('current_user') ?>:
|
||||||
|
<span>
|
||||||
|
<?= $timezones[$timezone] ?>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -316,6 +335,25 @@
|
||||||
<input id="unavailable-end" class="form-control">
|
<input id="unavailable-end" class="form-control">
|
||||||
</div>
|
</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">
|
<div class="form-group">
|
||||||
<label for="unavailable-notes" class="control-label"><?= lang('notes') ?></label>
|
<label for="unavailable-notes" class="control-label"><?= lang('notes') ?></label>
|
||||||
<textarea id="unavailable-notes" rows="3" class="form-control"></textarea>
|
<textarea id="unavailable-notes" rows="3" class="form-control"></textarea>
|
||||||
|
@ -361,6 +399,25 @@
|
||||||
<label for="extra-end" class="control-label"><?= lang('end') ?></label>
|
<label for="extra-end" class="control-label"><?= lang('end') ?></label>
|
||||||
<input id="extra-end" class="form-control">
|
<input id="extra-end" class="form-control">
|
||||||
</div>
|
</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>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<select <?= $attributes ?>>
|
<select <?= $attributes ?>>
|
||||||
<option value="UTC">UTC</option>
|
|
||||||
<?php foreach ($timezones as $continent => $entries): ?>
|
<?php foreach ($timezones as $continent => $entries): ?>
|
||||||
<optgroup label="<?= $continent ?>">
|
<optgroup label="<?= $continent ?>">
|
||||||
<?php foreach ($entries as $value => $name): ?>
|
<?php foreach ($entries as $value => $name): ?>
|
||||||
|
|
|
@ -22,6 +22,18 @@ window.BackendCalendarAppointmentsModal = window.BackendCalendarAppointmentsModa
|
||||||
|
|
||||||
'use strict';
|
'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() {
|
function _bindEventHandlers() {
|
||||||
/**
|
/**
|
||||||
* Event: Manage Appointments Dialog Cancel Button "Click"
|
* 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"
|
* Event: Enter New Customer Button "Click"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -256,6 +256,16 @@ window.BackendCalendarDefaultView = window.BackendCalendarDefaultView || {};
|
||||||
$('#calendar').fullCalendar('option', 'selectable', true);
|
$('#calendar').fullCalendar('option', 'selectable', true);
|
||||||
$('#calendar').fullCalendar('option', 'editable', 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 the user has already the sync enabled then apply the proper style changes.
|
||||||
if ($('#select-filter-item option:selected').attr('google-sync') === 'true') {
|
if ($('#select-filter-item option:selected').attr('google-sync') === 'true') {
|
||||||
$('#enable-sync').addClass('btn-danger enabled');
|
$('#enable-sync').addClass('btn-danger enabled');
|
||||||
|
|
Loading…
Reference in a new issue