Allow working plan exceptions to be defined as non-working days (#1383).

This commit is contained in:
Alex Tselegidis 2023-07-10 08:22:55 +02:00
parent 81e8b8824e
commit 5473544258
38 changed files with 207 additions and 59 deletions

View file

@ -444,6 +444,11 @@ class Calendar extends EA_Controller {
$working_plan_exception = request('working_plan_exception'); $working_plan_exception = request('working_plan_exception');
if ( ! $working_plan_exception)
{
$working_plan_exception = NULL;
}
$provider_id = request('provider_id'); $provider_id = request('provider_id');
$this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception); $this->providers_model->save_working_plan_exception($provider_id, $date, $working_plan_exception);

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Kliknite za prebacivanje';
$lang['week_short'] = 'Tjed'; $lang['week_short'] = 'Tjed';
$lang['scroll_to_increment'] = 'Skrolajte za inkrementaciju'; $lang['scroll_to_increment'] = 'Skrolajte za inkrementaciju';
$lang['year'] = 'Godina'; $lang['year'] = 'Godina';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Cliquez pour basculer';
$lang['week_short'] = 'Se'; $lang['week_short'] = 'Se';
$lang['scroll_to_increment'] = 'Faire défiler pour incrémenter'; $lang['scroll_to_increment'] = 'Faire défiler pour incrémenter';
$lang['year'] = 'Année'; $lang['year'] = 'Année';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Klicken Sie zum Umschalten';
$lang['week_short'] = 'Wo'; $lang['week_short'] = 'Wo';
$lang['scroll_to_increment'] = 'Scrollen Sie zu Inkrement'; $lang['scroll_to_increment'] = 'Scrollen Sie zu Inkrement';
$lang['year'] = 'Jahr'; $lang['year'] = 'Jahr';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Нажмите для переключения';
$lang['week_short'] = 'Нед'; $lang['week_short'] = 'Нед';
$lang['scroll_to_increment'] = 'Прокрутка для увеличения'; $lang['scroll_to_increment'] = 'Прокрутка для увеличения';
$lang['year'] = 'Год'; $lang['year'] = 'Год';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -434,4 +434,6 @@ $lang['click_to_toggle'] = 'Click To Toggle';
$lang['week_short'] = 'Wk'; $lang['week_short'] = 'Wk';
$lang['scroll_to_increment'] = 'Scroll To Increment'; $lang['scroll_to_increment'] = 'Scroll To Increment';
$lang['year'] = 'Year'; $lang['year'] = 'Year';
$lang['make_non_working_day'] = 'This provider will not be available for work on the selected day.';
$lang['no_breaks'] = 'No Breaks';
// End // End

View file

@ -582,7 +582,7 @@ class Providers_model extends EA_Model {
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @throws Exception * @throws Exception
*/ */
public function save_working_plan_exception(int $provider_id, string $date, array $working_plan_exception) public function save_working_plan_exception(int $provider_id, string $date, array $working_plan_exception = NULL)
{ {
// Validate the working plan exception data. // Validate the working plan exception data.
$start = date('H:i', strtotime($working_plan_exception['start'])); $start = date('H:i', strtotime($working_plan_exception['start']));
@ -610,7 +610,7 @@ class Providers_model extends EA_Model {
// Store the working plan exception. // Store the working plan exception.
$working_plan_exceptions = json_decode($provider['settings']['working_plan_exceptions'], TRUE); $working_plan_exceptions = json_decode($provider['settings']['working_plan_exceptions'], TRUE);
if ( ! isset($working_plan_exception['breaks'])) if ( is_array($working_plan_exception) && ! isset($working_plan_exception['breaks']))
{ {
$working_plan_exception['breaks'] = []; $working_plan_exception['breaks'] = [];
} }
@ -643,7 +643,7 @@ class Providers_model extends EA_Model {
unset($working_plan_exceptions[$date]); unset($working_plan_exceptions[$date]);
$provider['settings']['working_plan_exceptions'] = empty($working_plan_exceptions) ? new stdClass() : $working_plan_exceptions; $provider['settings']['working_plan_exceptions'] = empty($working_plan_exceptions) ? '{}' : $working_plan_exceptions;
$this->update($provider); $this->update($provider);
} }
@ -1015,10 +1015,10 @@ class Providers_model extends EA_Model {
/** /**
* Quickly check if a service is assigned to a provider. * Quickly check if a service is assigned to a provider.
* *
* @param int $provider_id * @param int $provider_id
* @param int $service_id * @param int $service_id
* *
* @return bool * @return bool
*/ */
public function is_service_supported(int $provider_id, int $service_id): bool public function is_service_supported(int $provider_id, int $service_id): bool

View file

@ -1,5 +1,5 @@
<div class="modal" id="working-plan-exceptions-modal"> <div class="modal" id="working-plan-exceptions-modal">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable"> <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title"><?= lang('working_plan_exception') ?></h5> <h5 class="modal-title"><?= lang('working_plan_exception') ?></h5>
@ -11,14 +11,27 @@
<input class="form-control" id="working-plan-exceptions-date"> <input class="form-control" id="working-plan-exceptions-date">
</div> </div>
<div class="mb-3"> <div class="form-check form-switch mb-3">
<label class="form-label" for="working-plan-exceptions-start"><?= lang('start') ?></label> <input class="form-check-input" type="checkbox" id="working-plan-exceptions-is-non-working-day">
<input class="form-control" id="working-plan-exceptions-start"> <label class="form-check-label" for="working-plan-exceptions-is-non-working-day">
<?= lang('make_non_working_day') ?>
</label>
</div> </div>
<div class="mb-3"> <div class="row">
<label class="form-label" for="working-plan-exceptions-end"><?= lang('end') ?></label> <div class="col-sm-6">
<input class="form-control" id="working-plan-exceptions-end"> <div class="mb-3">
<label class="form-label" for="working-plan-exceptions-start"><?= lang('start') ?></label>
<input class="form-control" id="working-plan-exceptions-start">
</div>
</div>
<div class="col-sm-6">
<div class="mb-3">
<label class="form-label" for="working-plan-exceptions-end"><?= lang('end') ?></label>
<input class="form-control" id="working-plan-exceptions-end">
</div>
</div>
</div> </div>
<h3><?= lang('breaks') ?></h3> <h3><?= lang('breaks') ?></h3>
@ -28,7 +41,7 @@
</p> </p>
<div> <div>
<button type="button" class="btn btn-primary working-plan-exceptions-add-break"> <button type="button" class="btn btn-outline-primary btn-sm working-plan-exceptions-add-break">
<i class="fas fa-plus-square me-2"></i> <i class="fas fa-plus-square me-2"></i>
<?= lang('add_break') ?> <?= lang('add_break') ?>
</button> </button>

View file

@ -22,6 +22,10 @@ App.Components.WorkingPlanExceptionsModal = (function () {
const $breaks = $('#working-plan-exceptions-breaks'); const $breaks = $('#working-plan-exceptions-breaks');
const $save = $('#working-plan-exceptions-save'); const $save = $('#working-plan-exceptions-save');
const $addBreak = $('.working-plan-exceptions-add-break'); const $addBreak = $('.working-plan-exceptions-add-break');
const $isNonWorkingDay = $('#working-plan-exceptions-is-non-working-day');
const moment = window.moment;
let deferred = null; let deferred = null;
let enableSubmit = false; let enableSubmit = false;
let enableCancel = false; let enableCancel = false;
@ -34,7 +38,35 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$date.val(''); $date.val('');
$start.val(''); $start.val('');
$end.val(''); $end.val('');
$breaks.find('tbody').empty(); $breaks.find('tbody').html(renderNoBreaksRow());
$isNonWorkingDay.prop('checked', false);
toggleFieldsByNonWorkingDay(false);
}
/**
* Render a single table row as a placeholder to empty breaks table.
*/
function renderNoBreaksRow() {
return $(`
<tr>
<td colspan="3" class="text-center">
${lang('no_breaks')}
</td>
</tr>
`);
}
/**
* Toggle the state of the fields depending on the non-working day checkbox value.
*
* @param {Boolean} isNonWorkingDay
*/
function toggleFieldsByNonWorkingDay(isNonWorkingDay) {
$start.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay);
$end.prop('disabled', isNonWorkingDay).toggleClass('text-decoration-line-through', isNonWorkingDay);
$addBreak.prop('disabled', isNonWorkingDay);
$breaks.find('button').prop('disabled', isNonWorkingDay);
$breaks.toggleClass('text-decoration-line-through', isNonWorkingDay)
} }
/** /**
@ -124,7 +156,9 @@ App.Components.WorkingPlanExceptionsModal = (function () {
const date = moment($date[0]._flatpickr.selectedDates[0]).format('YYYY-MM-DD'); const date = moment($date[0]._flatpickr.selectedDates[0]).format('YYYY-MM-DD');
const workingPlanException = { const isNonWorkingDay = $isNonWorkingDay.prop('checked');
const workingPlanException = isNonWorkingDay ? null : {
start: moment($start[0]._flatpickr.selectedDates[0]).format('HH:mm'), start: moment($start[0]._flatpickr.selectedDates[0]).format('HH:mm'),
end: moment($end[0]._flatpickr.selectedDates[0]).format('HH:mm'), end: moment($end[0]._flatpickr.selectedDates[0]).format('HH:mm'),
breaks: getBreaks() breaks: getBreaks()
@ -133,6 +167,7 @@ App.Components.WorkingPlanExceptionsModal = (function () {
deferred.resolve(date, workingPlanException); deferred.resolve(date, workingPlanException);
$modal.modal('hide'); $modal.modal('hide');
resetModal(); resetModal();
} }
@ -187,6 +222,10 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$start[0]._flatpickr.setDate(moment('08:00', 'HH:mm').toDate()); $start[0]._flatpickr.setDate(moment('08:00', 'HH:mm').toDate());
$end[0]._flatpickr.setDate(moment('20:00', 'HH:mm').toDate()); $end[0]._flatpickr.setDate(moment('20:00', 'HH:mm').toDate());
$isNonWorkingDay.prop('checked', false);
$breaks.find('tbody').html(renderNoBreaksRow());
$modal.modal('show'); $modal.modal('show');
return deferred.promise(); return deferred.promise();
@ -203,17 +242,34 @@ App.Components.WorkingPlanExceptionsModal = (function () {
function edit(date, workingPlanException) { function edit(date, workingPlanException) {
deferred = $.Deferred(); deferred = $.Deferred();
const isNonWorkingDay = !Boolean(workingPlanException);
$date[0]._flatpickr.setDate(moment(date, 'YYYY-MM-DD').toDate()); $date[0]._flatpickr.setDate(moment(date, 'YYYY-MM-DD').toDate());
$start[0]._flatpickr.setDate(moment(workingPlanException.start, 'HH:mm').toDate());
$end[0]._flatpickr.setDate(moment(workingPlanException.end, 'HH:mm').toDate());
workingPlanException.breaks.forEach((workingPlanExceptionBreak) => { if (isNonWorkingDay === false) {
renderBreakRow(workingPlanExceptionBreak).appendTo($breaks.find('tbody')); $start[0]._flatpickr.setDate(moment(workingPlanException.start, 'HH:mm').toDate());
}); $end[0]._flatpickr.setDate(moment(workingPlanException.end, 'HH:mm').toDate());
editableTimeCell( if (!workingPlanException.breaks) {
$breaks.find('tbody .working-plan-exceptions-break-start, tbody .working-plan-exceptions-break-end') $breaks.find('tbody').html(renderNoBreaksRow());
); }
workingPlanException.breaks.forEach((workingPlanExceptionBreak) => {
renderBreakRow(workingPlanExceptionBreak).appendTo($breaks.find('tbody'));
});
editableTimeCell(
$breaks.find('tbody .working-plan-exceptions-break-start, tbody .working-plan-exceptions-break-end')
);
} else {
$start[0]._flatpickr.setDate(moment('08:00', 'HH:mm').toDate());
$end[0]._flatpickr.setDate(moment('20:00', 'HH:mm').toDate());
$breaks.find('tbody').html(renderNoBreaksRow());
}
$isNonWorkingDay.prop('checked', isNonWorkingDay);
toggleFieldsByNonWorkingDay(isNonWorkingDay);
$modal.modal('show'); $modal.modal('show');
@ -388,6 +444,15 @@ App.Components.WorkingPlanExceptionsModal = (function () {
$addBreak.prop('disabled', false); $addBreak.prop('disabled', false);
} }
/**
* Event: Is Non Working Day "Change"
*/
function onIsNonWorkingDayChange() {
const isNonWorkingDay = $isNonWorkingDay.prop('checked');
toggleFieldsByNonWorkingDay(isNonWorkingDay);
}
/** /**
* Initialize the module. * Initialize the module.
*/ */
@ -405,6 +470,8 @@ App.Components.WorkingPlanExceptionsModal = (function () {
.on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick); .on('click', '.working-plan-exceptions-cancel-break', onCancelBreakClick);
$save.on('click', onSaveClick); $save.on('click', onSaveClick);
$isNonWorkingDay.on('change', onIsNonWorkingDayChange);
} }
document.addEventListener('DOMContentLoaded', initialize); document.addEventListener('DOMContentLoaded', initialize);

View file

@ -86,8 +86,10 @@ App.Utils.CalendarDefaultView = (function () {
let startMoment; let startMoment;
let endMoment; let endMoment;
if (lastFocusedEventData.extendedProps.data.workingPlanException) { const data = lastFocusedEventData.extendedProps.data;
if (data.hasOwnProperty('workingPlanException')) {
const date = lastFocusedEventData.extendedProps.data.date; const date = lastFocusedEventData.extendedProps.data.date;
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException; const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
const provider = lastFocusedEventData.extendedProps.data.provider; const provider = lastFocusedEventData.extendedProps.data.provider;
@ -466,6 +468,10 @@ App.Utils.CalendarDefaultView = (function () {
displayDelete = displayDelete =
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; $target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none';
const {date, workingPlanException, provider} = info.event.extendedProps.data;
const startTime = workingPlanException?.start;
const endTime = workingPlanException?.end;
$html = $('<div/>', { $html = $('<div/>', {
'html': [ 'html': [
$('<strong/>', { $('<strong/>', {
@ -473,11 +479,7 @@ App.Utils.CalendarDefaultView = (function () {
'text': lang('provider') 'text': lang('provider')
}), }),
$('<span/>', { $('<span/>', {
'text': info.event.extendedProps.data 'text': `${provider.first_name} ${provider.last_name}`
? info.event.extendedProps.data.provider.first_name +
' ' +
info.event.extendedProps.data.provider.last_name
: '-'
}), }),
$('<br/>'), $('<br/>'),
@ -486,14 +488,11 @@ App.Utils.CalendarDefaultView = (function () {
'text': lang('start') 'text': lang('start')
}), }),
$('<span/>', { $('<span/>', {
'text': App.Utils.Date.format( 'text': startTime ? App.Utils.Date.format(`${date} ${startTime}`,
info.event.extendedProps.data.date +
' ' +
info.event.extendedProps.data.workingPlanException.start,
vars('date_format'), vars('date_format'),
vars('time_format'), vars('time_format'),
true true
) ) : '-'
}), }),
$('<br/>'), $('<br/>'),
@ -502,14 +501,11 @@ App.Utils.CalendarDefaultView = (function () {
'text': lang('end') 'text': lang('end')
}), }),
$('<span/>', { $('<span/>', {
'text': App.Utils.Date.format( 'text': endTime ? App.Utils.Date.format(`${date} ${endTime}`,
info.event.extendedProps.data.date +
' ' +
info.event.extendedProps.data.workingPlanException.end,
vars('date_format'), vars('date_format'),
vars('time_format'), vars('time_format'),
true true
) ) : '-'
}), }),
$('<br/>'), $('<br/>'),
@ -518,7 +514,7 @@ App.Utils.CalendarDefaultView = (function () {
'text': lang('timezone') 'text': lang('timezone')
}), }),
$('<span/>', { $('<span/>', {
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone] 'text': startTime ? vars('timezones')[provider.timezone] : '-'
}), }),
$('<br/>'), $('<br/>'),
@ -1273,12 +1269,14 @@ App.Utils.CalendarDefaultView = (function () {
weekdayDate = calendarDate.format('YYYY-MM-DD'); weekdayDate = calendarDate.format('YYYY-MM-DD');
// Add working plan exception event. // Add working plan exception event.
if (workingPlanExceptions && workingPlanExceptions[weekdayDate]) { if (workingPlanExceptions && workingPlanExceptions.hasOwnProperty(weekdayDate)) {
sortedWorkingPlan[weekdayName] = workingPlanExceptions[weekdayDate]; sortedWorkingPlan[weekdayName] = workingPlanExceptions[weekdayDate];
workingPlanExceptionStart = const startTime = sortedWorkingPlan[weekdayName]?.start || '00:00';
weekdayDate + ' ' + sortedWorkingPlan[weekdayName].start; const endTime = sortedWorkingPlan[weekdayName]?.end || '00:00';
workingPlanExceptionEnd = weekdayDate + ' ' + sortedWorkingPlan[weekdayName].end;
workingPlanExceptionStart = `${weekdayDate} ${startTime}`;
workingPlanExceptionEnd = `${weekdayDate} ${endTime}`;
workingPlanExceptionEvent = { workingPlanExceptionEvent = {
title: lang('working_plan_exception'), title: lang('working_plan_exception'),
@ -1468,8 +1466,8 @@ App.Utils.CalendarDefaultView = (function () {
dayHeaderFormat: columnFormat dayHeaderFormat: columnFormat
}, },
timeGridWeek: { timeGridWeek: {
dayHeaderFormat: columnFormat dayHeaderFormat: columnFormat
} }
}, },
selectable: true, selectable: true,
selectMirror: true, selectMirror: true,
@ -1543,16 +1541,16 @@ App.Utils.CalendarDefaultView = (function () {
.prop('selected', true); .prop('selected', true);
} }
const localSelectFilterItemValue = window.localStorage.getItem('EasyAppointments.SelectFilterItem');
if (localSelectFilterItemValue && $selectFilterItem.find(`option[value="${localSelectFilterItemValue}"]`).length) {
$selectFilterItem.val(localSelectFilterItemValue);
}
// Add the page event listeners. // Add the page event listeners.
addEventListeners(); addEventListeners();
$reloadAppointments.trigger('click'); const localSelectFilterItemValue = window.localStorage.getItem('EasyAppointments.SelectFilterItem');
if (localSelectFilterItemValue && $selectFilterItem.find(`option[value="${localSelectFilterItemValue}"]`).length) {
$selectFilterItem.val(localSelectFilterItemValue).trigger('change');
} else {
$reloadAppointments.trigger('click');
}
// Display the edit dialog if an appointment hash is provided. // Display the edit dialog if an appointment hash is provided.
if (vars('edit_appointment')) { if (vars('edit_appointment')) {
@ -1613,8 +1611,6 @@ App.Utils.CalendarDefaultView = (function () {
fullCalendar.view.currentEnd fullCalendar.view.currentEnd
); );
}, 60000); }, 60000);
$reloadAppointments.trigger('click');
} }
return { return {

View file

@ -301,6 +301,9 @@ App.Utils.WorkingPlan = (function () {
*/ */
renderWorkingPlanExceptionRow(date, workingPlanException) { renderWorkingPlanExceptionRow(date, workingPlanException) {
const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm'; const timeFormat = vars('time_format') === 'regular' ? 'h:mm a' : 'HH:mm';
const start = workingPlanException?.start;
const end = workingPlanException?.end;
return $('<tr/>', { return $('<tr/>', {
'data': { 'data': {
@ -310,15 +313,15 @@ App.Utils.WorkingPlan = (function () {
'html': [ 'html': [
$('<td/>', { $('<td/>', {
'class': 'working-plan-exception-date', 'class': 'working-plan-exception-date',
'text': App.Utils.Date.format(date, vars('date_format'), vars('time_format'), false) 'text': App.Utils.Date.format(date, vars('date_format'), vars('time_format'), false)
}), }),
$('<td/>', { $('<td/>', {
'class': 'working-plan-exception--start', 'class': 'working-plan-exception--start',
'text': moment(workingPlanException.start, 'HH:mm').format(timeFormat).toLowerCase() 'text': start ? moment(start, 'HH:mm').format(timeFormat).toLowerCase() : '-'
}), }),
$('<td/>', { $('<td/>', {
'class': 'working-plan-exception--end', 'class': 'working-plan-exception--end',
'text': moment(workingPlanException.end, 'HH:mm').format(timeFormat).toLowerCase() 'text': end ? moment(end, 'HH:mm').format(timeFormat).toLowerCase() : '-'
}), }),
$('<td/>', { $('<td/>', {
'html': [ 'html': [