Update the blocked period CRUD (#432)
This commit is contained in:
parent
9e2c4827aa
commit
1c3ae956aa
5 changed files with 80 additions and 24 deletions
|
@ -120,6 +120,8 @@ const WEBHOOK_SECRETARY_SAVE = 'secretary_save';
|
|||
const WEBHOOK_SECRETARY_DELETE = 'secretary_delete';
|
||||
const WEBHOOK_ADMIN_SAVE = 'admin_save';
|
||||
const WEBHOOK_ADMIN_DELETE = 'admin_delete';
|
||||
const WEBHOOK_BLOCKED_PERIOD_SAVE = 'blocked_period_save';
|
||||
const WEBHOOK_BLOCKED_PERIOD_DELETE = 'blocked_period_delete';
|
||||
|
||||
/* End of file constants.php */
|
||||
/* Location: ./application/config/constants.php */
|
||||
|
|
|
@ -63,6 +63,9 @@ class Blocked_periods extends EA_Controller {
|
|||
script_vars([
|
||||
'user_id' => $user_id,
|
||||
'role_slug' => $role_slug,
|
||||
'date_format' => setting('date_format'),
|
||||
'time_format' => setting('time_format'),
|
||||
'first_weekday' => setting('first_weekday'),
|
||||
]);
|
||||
|
||||
html_vars([
|
||||
|
@ -118,22 +121,24 @@ class Blocked_periods extends EA_Controller {
|
|||
abort(403, 'Forbidden');
|
||||
}
|
||||
|
||||
$service_category = request('service_category');
|
||||
$blocked_period = request('blocked_period');
|
||||
|
||||
$this->blocked_periods_model->only($service_category, [
|
||||
$this->blocked_periods_model->only($blocked_period, [
|
||||
'name',
|
||||
'start_datetime',
|
||||
'end_datetime',
|
||||
'description'
|
||||
]);
|
||||
|
||||
$service_category_id = $this->blocked_periods_model->save($service_category);
|
||||
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
|
||||
|
||||
$service_category = $this->blocked_periods_model->find($service_category_id);
|
||||
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
||||
|
||||
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
|
||||
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
|
||||
|
||||
json_response([
|
||||
'success' => TRUE,
|
||||
'id' => $service_category_id
|
||||
'id' => $blocked_period_id
|
||||
]);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
|
@ -154,23 +159,25 @@ class Blocked_periods extends EA_Controller {
|
|||
abort(403, 'Forbidden');
|
||||
}
|
||||
|
||||
$service_category = request('service_category');
|
||||
$blocked_period = request('blocked_period');
|
||||
|
||||
$this->blocked_periods_model->only($service_category, [
|
||||
$this->blocked_periods_model->only($blocked_period, [
|
||||
'id',
|
||||
'name',
|
||||
'start_datetime',
|
||||
'end_datetime',
|
||||
'description'
|
||||
]);
|
||||
|
||||
$service_category_id = $this->blocked_periods_model->save($service_category);
|
||||
$blocked_period_id = $this->blocked_periods_model->save($blocked_period);
|
||||
|
||||
$service_category = $this->blocked_periods_model->find($service_category_id);
|
||||
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
||||
|
||||
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
|
||||
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_SAVE, $blocked_period);
|
||||
|
||||
json_response([
|
||||
'success' => TRUE,
|
||||
'id' => $service_category_id
|
||||
'id' => $blocked_period_id
|
||||
]);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
|
@ -191,13 +198,13 @@ class Blocked_periods extends EA_Controller {
|
|||
abort(403, 'Forbidden');
|
||||
}
|
||||
|
||||
$service_category_id = request('service_category_id');
|
||||
$blocked_period_id = request('blocked_period_id');
|
||||
|
||||
$service_category = $this->blocked_periods_model->find($service_category_id);
|
||||
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
||||
|
||||
$this->blocked_periods_model->delete($service_category_id);
|
||||
$this->blocked_periods_model->delete($blocked_period_id);
|
||||
|
||||
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_DELETE, $service_category);
|
||||
$this->webhooks_client->trigger(WEBHOOK_BLOCKED_PERIOD_DELETE, $blocked_period);
|
||||
|
||||
json_response([
|
||||
'success' => TRUE,
|
||||
|
@ -221,11 +228,11 @@ class Blocked_periods extends EA_Controller {
|
|||
abort(403, 'Forbidden');
|
||||
}
|
||||
|
||||
$service_category_id = request('service_category_id');
|
||||
$blocked_period_id = request('blocked_period_id');
|
||||
|
||||
$service_category = $this->blocked_periods_model->find($service_category_id);
|
||||
$blocked_period = $this->blocked_periods_model->find($blocked_period_id);
|
||||
|
||||
json_response($service_category);
|
||||
json_response($blocked_period);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
|
|
|
@ -71,19 +71,19 @@
|
|||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="start-datetime">
|
||||
<label class="form-label" for="start-date-time">
|
||||
<?= lang('start') ?>
|
||||
<span class="text-danger" hidden>*</span>
|
||||
</label>
|
||||
<input id="start-datetime" class="form-control required" disabled>
|
||||
<input id="start-date-time" class="form-control required" disabled>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="end-datetime">
|
||||
<label class="form-label" for="end-date-time">
|
||||
<?= lang('end') ?>
|
||||
<span class="text-danger" hidden>*</span>
|
||||
</label>
|
||||
<input id="end-datetime" class="form-control required" disabled>
|
||||
<input id="end-date-time" class="form-control required" disabled>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
@ -104,6 +104,7 @@
|
|||
<script src="<?= asset_url('assets/js/utils/message.js') ?>"></script>
|
||||
<script src="<?= asset_url('assets/js/utils/validation.js') ?>"></script>
|
||||
<script src="<?= asset_url('assets/js/utils/url.js') ?>"></script>
|
||||
<script src="<?= asset_url('assets/js/utils/ui.js') ?>"></script>
|
||||
<script src="<?= asset_url('assets/js/http/blocked_periods_http_client.js') ?>"></script>
|
||||
<script src="<?= asset_url('assets/js/pages/blocked_periods.js') ?>"></script>
|
||||
|
||||
|
|
|
@ -19,7 +19,11 @@ App.Pages.BlockedPeriods = (function () {
|
|||
const $filterBlockedPeriods = $('#filter-blocked-periods');
|
||||
const $id = $('#id');
|
||||
const $name = $('#name');
|
||||
const $startDateTime = $('#start-date-time');
|
||||
const $endDateTime = $('#end-date-time');
|
||||
const $description = $('#description');
|
||||
const moment = window.moment;
|
||||
|
||||
let filterResults = {};
|
||||
let filterLimit = 20;
|
||||
|
||||
|
@ -117,8 +121,15 @@ App.Pages.BlockedPeriods = (function () {
|
|||
* Event: Blocked period Save Button "Click"
|
||||
*/
|
||||
$blockedPeriods.on('click', '#save-blocked-period', () => {
|
||||
const startDateTimeObject = App.Utils.UI.getDatetimepickerValue($startDateTime);
|
||||
const startDateTimeMoment = moment(startDateTimeObject);
|
||||
const endDateTimeObject = App.Utils.UI.getDatetimepickerValue($endDateTime);
|
||||
const endDateTimeMoment = moment(endDateTimeObject);
|
||||
|
||||
const blockedPeriod = {
|
||||
name: $name.val(),
|
||||
start_datetime: startDateTimeMoment.format('YYYY-MM-DD HH:mm:ss'),
|
||||
end_datetime: endDateTimeMoment.format('YYYY-MM-DD HH:mm:ss'),
|
||||
description: $description.val()
|
||||
};
|
||||
|
||||
|
@ -222,6 +233,8 @@ App.Pages.BlockedPeriods = (function () {
|
|||
function display(blockedPeriod) {
|
||||
$id.val(blockedPeriod.id);
|
||||
$name.val(blockedPeriod.name);
|
||||
App.Utils.UI.setDatetimepickerValue($startDateTime, new Date(blockedPeriod.start_datetime));
|
||||
App.Utils.UI.setDatetimepickerValue($endDateTime, new Date(blockedPeriod.end_datetime));
|
||||
$description.val(blockedPeriod.description);
|
||||
}
|
||||
|
||||
|
@ -322,6 +335,8 @@ App.Pages.BlockedPeriods = (function () {
|
|||
resetForm();
|
||||
filter('');
|
||||
addEventListeners();
|
||||
App.Utils.UI.initializeDatetimepicker($startDateTime);
|
||||
App.Utils.UI.initializeDatetimepicker($endDateTime);
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initialize);
|
||||
|
|
|
@ -225,11 +225,42 @@ window.App.Utils.UI = (function () {
|
|||
$target.trumbowyg(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Date, Date-Time or Time picker value.
|
||||
*
|
||||
* @param {jQuery} $target
|
||||
*
|
||||
* @return {Date}
|
||||
*/
|
||||
function getDatetimepickerValue($target) {
|
||||
if (!$target?.length) {
|
||||
throw new Error('Empty $target argument provided.')
|
||||
}
|
||||
|
||||
return $target[0]._flatpickr.selectedDates[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Date, Date-Time or Time picker value.
|
||||
*
|
||||
* @param {jQuery} $target
|
||||
* @param {Date} value
|
||||
*/
|
||||
function setDatetimepickerValue($target, value) {
|
||||
if (!$target?.length) {
|
||||
throw new Error('Empty $target argument provided.')
|
||||
}
|
||||
|
||||
return $target[0]._flatpickr.setDate(value);
|
||||
}
|
||||
|
||||
return {
|
||||
initializeDatetimepicker,
|
||||
initializeDatepicker,
|
||||
initializeTimepicker,
|
||||
initializeDropdown,
|
||||
initializeTextEditor,
|
||||
getDatetimepickerValue,
|
||||
setDatetimepickerValue,
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue