Add blocked period CRUD operations to the app (#432)

This commit is contained in:
Alex Tselegidis 2023-11-03 18:25:23 +01:00
parent 38f872d857
commit fbcd35f197
44 changed files with 1454 additions and 1 deletions

View file

@ -72,6 +72,7 @@ const PRIV_USERS = 'users';
const PRIV_SYSTEM_SETTINGS = 'system_settings';
const PRIV_USER_SETTINGS = 'user_settings';
const PRIV_WEBHOOKS = 'webhooks';
const PRIV_BLOCKED_PERIODS = 'blocked_periods';
const DATE_FORMAT_DMY = 'DMY';
const DATE_FORMAT_MDY = 'MDY';

View file

@ -0,0 +1,235 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Blocked_periods controller.
*
* Handles the blocked-periods related operations.
*
* @package Controllers
*/
class Blocked_periods extends EA_Controller {
/**
* Blocked_periods constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->model('blocked_periods_model');
$this->load->model('roles_model');
$this->load->library('accounts');
$this->load->library('timezones');
$this->load->library('webhooks_client');
}
/**
* Render the backend blocked-periods page.
*
* On this page admin users will be able to manage blocked-periods, which are eventually selected by customers during the
* booking process.
*/
public function index()
{
session(['dest_url' => site_url('blocked_periods')]);
$user_id = session('user_id');
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
if ($user_id)
{
abort(403, 'Forbidden');
}
redirect('login');
return;
}
$role_slug = session('role_slug');
script_vars([
'user_id' => $user_id,
'role_slug' => $role_slug,
]);
html_vars([
'page_title' => lang('blocked_periods'),
'active_menu' => PRIV_BLOCKED_PERIODS,
'user_display_name' => $this->accounts->get_user_display_name($user_id),
'timezones' => $this->timezones->to_array(),
'privileges' => $this->roles_model->get_permissions_by_slug($role_slug),
]);
$this->load->view('pages/blocked_periods');
}
/**
* Filter blocked-periods by the provided keyword.
*/
public function search()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$keyword = request('keyword', '');
$order_by = 'update_datetime DESC';
$limit = request('limit', 1000);
$offset = 0;
$blocked_periods = $this->blocked_periods_model->search($keyword, $limit, $offset, $order_by);
json_response($blocked_periods);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Store a new service-category.
*/
public function store()
{
try
{
if (cannot('add', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$service_category = request('service_category');
$this->blocked_periods_model->only($service_category, [
'name',
'description'
]);
$service_category_id = $this->blocked_periods_model->save($service_category);
$service_category = $this->blocked_periods_model->find($service_category_id);
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
json_response([
'success' => TRUE,
'id' => $service_category_id
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Update a service-category.
*/
public function update()
{
try
{
if (cannot('edit', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$service_category = request('service_category');
$this->blocked_periods_model->only($service_category, [
'id',
'name',
'description'
]);
$service_category_id = $this->blocked_periods_model->save($service_category);
$service_category = $this->blocked_periods_model->find($service_category_id);
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_SAVE, $service_category);
json_response([
'success' => TRUE,
'id' => $service_category_id
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Remove a service-category.
*/
public function destroy()
{
try
{
if (cannot('delete', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$service_category_id = request('service_category_id');
$service_category = $this->blocked_periods_model->find($service_category_id);
$this->blocked_periods_model->delete($service_category_id);
$this->webhooks_client->trigger(WEBHOOK_SERVICE_CATEGORY_DELETE, $service_category);
json_response([
'success' => TRUE,
]);
}
catch (Throwable $e)
{
json_exception($e);
}
}
/**
* Find a service-category.
*/
public function find()
{
try
{
if (cannot('view', PRIV_BLOCKED_PERIODS))
{
abort(403, 'Forbidden');
}
$service_category_id = request('service_category_id');
$service_category = $this->blocked_periods_model->find($service_category_id);
json_response($service_category);
}
catch (Throwable $e)
{
json_exception($e);
}
}
}

View file

@ -52,6 +52,7 @@
* @property Unavailabilities_model $unavailabilities_model
* @property Users_model $users_model
* @property Webhooks_model $webhooks_model
* @property Blocked_periods_model $blocked_periods_model
*
* @property Accounts $accounts
* @property Api $api

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -438,4 +438,9 @@ $lang['make_non_working_day'] = 'This provider will not be available for work on
$lang['no_breaks'] = 'No Breaks';
$lang['service_categories'] = 'Service Categories';
$lang['service_category'] = 'Service Category';
$lang['blocked_period_saved'] = 'Blocked period saved successfully.';
$lang['blocked_period_deleted'] = 'Blocked period deleted successfully.';
$lang['delete_blocked_period'] = 'Delete Blocked Period';
$lang['blocked_period'] = 'Blocked Period';
$lang['blocked_periods'] = 'Blocked Periods';
// End

View file

@ -17,7 +17,7 @@ class Migration_Drop_delete_datetime_column_from_all_tables extends EA_Migration
*/
protected $tables = [
'appointments',
'categories',
'service_categories',
'consents',
'roles',
'services',

View file

@ -0,0 +1,71 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.4.0
* ---------------------------------------------------------------------------- */
class Migration_Create_blocked_periods_table extends EA_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->table_exists('blocked_periods'))
{
$this->dbforge->add_field([
'id' => [
'type' => 'INT',
'constraint' => 11,
'auto_increment' => TRUE
],
'create_datetime' => [
'type' => 'DATETIME',
'null' => TRUE
],
'update_datetime' => [
'type' => 'DATETIME',
'null' => TRUE
],
'name' => [
'type' => 'VARCHAR',
'constraint' => '256',
'null' => TRUE,
],
'start_datetime' => [
'type' => 'DATETIME',
'null' => TRUE,
],
'end_datetime' => [
'type' => 'DATETIME',
'null' => TRUE,
],
'description' => [
'type' => 'TEXT',
'null' => TRUE,
],
]);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('blocked_periods', TRUE, ['engine' => 'InnoDB']);
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->table_exists('blocked_periods'))
{
$this->dbforge->drop_table('blocked_periods');
}
}
}

View file

@ -0,0 +1,48 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.4.0
* ---------------------------------------------------------------------------- */
class Migration_Add_blocked_periods_column_to_roles_table extends EA_Migration {
/**
* Upgrade method.
*/
public function up()
{
if ( ! $this->db->field_exists('blocked_periods', 'roles'))
{
$fields = [
'blocked_periods' => [
'type' => 'INT',
'constraint' => '11',
'null' => TRUE
]
];
$this->dbforge->add_column('roles', $fields);
$this->db->update('roles', ['blocked_periods' => '15'], ['slug' => 'admin']);
$this->db->update('roles', ['blocked_periods' => '0'], ['slug !=' => 'admin']);
}
}
/**
* Downgrade method.
*/
public function down()
{
if ($this->db->field_exists('blocked_periods', 'roles'))
{
$this->dbforge->drop_column('roles', 'blocked_periods');
}
}
}

View file

@ -0,0 +1,357 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Blocked-Periods model.
*
* Handles all the database operations of the blocked-period resource.
*
* @package Models
*/
class Blocked_periods_model extends EA_Model {
/**
* @var array
*/
protected array $casts = [
'id' => 'integer',
];
/**
* @var array
*/
protected array $api_resource = [
'id' => 'id',
'name' => 'name',
'start' => 'start_datetime',
'end' => 'end_datetime',
'description' => 'description',
];
/**
* Save (insert or update) a blocked-period.
*
* @param array $blocked_period Associative array with the blocked-period data.
*
* @return int Returns the blocked-period ID.
*
* @throws InvalidArgumentException
*/
public function save(array $blocked_period): int
{
$this->validate($blocked_period);
if (empty($blocked_period['id']))
{
return $this->insert($blocked_period);
}
else
{
return $this->update($blocked_period);
}
}
/**
* Validate the blocked-period data.
*
* @param array $blocked_period Associative array with the blocked-period data.
*
* @throws InvalidArgumentException
*/
public function validate(array $blocked_period)
{
// If a blocked-period ID is provided then check whether the record really exists in the database.
if ( ! empty($blocked_period['id']))
{
$count = $this->db->get_where('blocked_periods', ['id' => $blocked_period['id']])->num_rows();
if ( ! $count)
{
throw new InvalidArgumentException('The provided blocked-period ID does not exist in the database: ' . $blocked_period['id']);
}
}
// Make sure all required fields are provided.
if (
empty($blocked_period['name'])
)
{
throw new InvalidArgumentException('Not all required fields are provided: ' . print_r($blocked_period, TRUE));
}
}
/**
* Insert a new blocked-period into the database.
*
* @param array $blocked_period Associative array with the blocked-period data.
*
* @return int Returns the blocked-period ID.
*
* @throws RuntimeException
*/
protected function insert(array $blocked_period): int
{
$blocked_period['create_datetime'] = date('Y-m-d H:i:s');
$blocked_period['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->insert('blocked_periods', $blocked_period))
{
throw new RuntimeException('Could not insert blocked-period.');
}
return $this->db->insert_id();
}
/**
* Update an existing blocked-period.
*
* @param array $blocked_period Associative array with the blocked-period data.
*
* @return int Returns the blocked-period ID.
*
* @throws RuntimeException
*/
protected function update(array $blocked_period): int
{
$blocked_period['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('blocked_periods', $blocked_period, ['id' => $blocked_period['id']]))
{
throw new RuntimeException('Could not update blocked periods.');
}
return $blocked_period['id'];
}
/**
* Remove an existing blocked-period from the database.
*
* @param int $blocked_period_id Blocked period ID.
*
* @throws RuntimeException
*/
public function delete(int $blocked_period_id): void
{
$this->db->delete('blocked_periods', ['id' => $blocked_period_id]);
}
/**
* Get a specific blocked-period from the database.
*
* @param int $blocked_period_id The ID of the record to be returned.
*
* @return array Returns an array with the blocked-period data.
*
* @throws InvalidArgumentException
*/
public function find(int $blocked_period_id): array
{
$blocked_period = $this->db->get_where('blocked_periods', ['id' => $blocked_period_id])->row_array();
if ( ! $blocked_period)
{
throw new InvalidArgumentException('The provided blocked-period ID was not found in the database: ' . $blocked_period_id);
}
$this->cast($blocked_period);
return $blocked_period;
}
/**
* Get a specific field value from the database.
*
* @param int $blocked_period_id Blocked period ID.
* @param string $field Name of the value to be returned.
*
* @return mixed Returns the selected blocked-period value from the database.
*
* @throws InvalidArgumentException
*/
public function value(int $blocked_period_id, string $field): mixed
{
if (empty($field))
{
throw new InvalidArgumentException('The field argument is cannot be empty.');
}
if (empty($blocked_period_id))
{
throw new InvalidArgumentException('The blocked-period ID argument cannot be empty.');
}
// Check whether the service exists.
$query = $this->db->get_where('blocked_periods', ['id' => $blocked_period_id]);
if ( ! $query->num_rows())
{
throw new InvalidArgumentException('The provided blocked-period ID was not found in the database: ' . $blocked_period_id);
}
// Check if the required field is part of the blocked-period data.
$blocked_period = $query->row_array();
$this->cast($blocked_period);
if ( ! array_key_exists($field, $blocked_period))
{
throw new InvalidArgumentException('The requested field was not found in the blocked-period data: ' . $field);
}
return $blocked_period[$field];
}
/**
* Get all services that match the provided criteria.
*
* @param array|string|null $where Where conditions
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
*
* @return array Returns an array of blocked periods.
*/
public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
if ($where !== NULL)
{
$this->db->where($where);
}
if ($order_by !== NULL)
{
$this->db->order_by($order_by);
}
$blocked_periods = $this->db->get('blocked_periods', $limit, $offset)->result_array();
foreach ($blocked_periods as &$blocked_period)
{
$this->cast($blocked_period);
}
return $blocked_periods;
}
/**
* Get the query builder interface, configured for use with the blocked periods table.
*
* @return CI_DB_query_builder
*/
public function query(): CI_DB_query_builder
{
return $this->db->from('blocked_periods');
}
/**
* Search blocked periods by the provided keyword.
*
* @param string $keyword Search keyword.
* @param int|null $limit Record limit.
* @param int|null $offset Record offset.
* @param string|null $order_by Order by.
*
* @return array Returns an array of blocked periods.
*/
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL): array
{
$blocked_periods = $this
->db
->select()
->from('blocked_periods')
->group_start()
->like('name', $keyword)
->or_like('description', $keyword)
->group_end()
->limit($limit)
->offset($offset)
->order_by($order_by)
->get()
->result_array();
foreach ($blocked_periods as &$blocked_period)
{
$this->cast($blocked_period);
}
return $blocked_periods;
}
/**
* Load related resources to a blocked-period.
*
* @param array $blocked_period Associative array with the blocked-period data.
* @param array $resources Resource names to be attached.
*
* @throws InvalidArgumentException
*/
public function load(array &$blocked_period, array $resources)
{
// Blocked periods do not currently have any related resources.
}
/**
* Convert the database blocked-period record to the equivalent API resource.
*
* @param array $blocked_period Blocked period data.
*/
public function api_encode(array &$blocked_period)
{
$encoded_resource = [
'id' => array_key_exists('id', $blocked_period) ? (int)$blocked_period['id'] : NULL,
'name' => $blocked_period['name'],
'start' => array_key_exists('start_datetime', $blocked_period) ? $blocked_period['start_datetime'] : NULL,
'end' => array_key_exists('end_datetime', $blocked_period) ? $blocked_period['end_datetime'] : NULL,
'description' => array_key_exists('description', $blocked_period) ? $blocked_period['description'] : NULL
];
$blocked_period = $encoded_resource;
}
/**
* Convert the API resource to the equivalent database blocked-period record.
*
* @param array $blocked_period API resource.
* @param array|null $base Base blocked-period data to be overwritten with the provided values (useful for updates).
*/
public function api_decode(array &$blocked_period, array $base = NULL)
{
$decoded_resource = $base ?: [];
if (array_key_exists('id', $blocked_period))
{
$decoded_resource['id'] = $blocked_period['id'];
}
if (array_key_exists('name', $blocked_period))
{
$decoded_resource['name'] = $blocked_period['name'];
}
if (array_key_exists('start', $blocked_period))
{
$decoded_resource['start_datetime'] = $blocked_period['start'];
}
if (array_key_exists('end', $blocked_period))
{
$decoded_resource['end_datetime'] = $blocked_period['end'];
}
if (array_key_exists('description', $blocked_period))
{
$decoded_resource['description'] = $blocked_period['description'];
}
$blocked_period = $decoded_resource;
}
}

View file

@ -0,0 +1,110 @@
<?php extend('layouts/backend_layout') ?>
<?php section('content') ?>
<div class="container-fluid backend-page" id="blocked-periods-page">
<div class="row" id="blocked-periods">
<div id="filter-blocked-periods" class="filter-records column col-12 col-md-5">
<form class="input-append mb-4">
<div class="input-group">
<input type="text" class="key form-control" aria-label="keyword">
<button class="filter btn btn-outline-secondary" type="submit"
data-tippy-content="<?= lang('filter') ?>">
<i class="fas fa-search"></i>
</button>
</div>
</form>
<h4 class="text-black-50 mb-3 fw-light">
<?= lang('blocked_periods') ?>
</h4>
<div class="results">
<!-- JS -->
</div>
</div>
<div class="record-details col-12 col-md-5">
<div class="btn-toolbar mb-4">
<div class="add-edit-delete-group btn-group">
<button id="add-blocked-period" class="btn btn-primary">
<i class="fas fa-plus-square me-2"></i>
<?= lang('add') ?>
</button>
<button id="edit-blocked-period" class="btn btn-outline-secondary" disabled="disabled">
<i class="fas fa-edit me-2"></i>
<?= lang('edit') ?>
</button>
<button id="delete-blocked-period" class="btn btn-outline-secondary" disabled="disabled">
<i class="fas fa-trash-alt me-2"></i>
<?= lang('delete') ?>
</button>
</div>
<div class="save-cancel-group" style="display:none;">
<button id="save-blocked-period" class="btn btn-primary">
<i class="fas fa-check-square me-2"></i>
<?= lang('save') ?>
</button>
<button id="cancel-blocked-period" class="btn btn-secondary">
<?= lang('cancel') ?>
</button>
</div>
</div>
<h4 class="text-black-50 mb-3 fw-light">
<?= lang('details') ?>
</h4>
<div class="form-message alert" style="display:none;"></div>
<input type="hidden" id="id">
<div class="mb-3">
<label class="form-label" for="name">
<?= lang('name') ?>
<span class="text-danger" hidden>*</span>
</label>
<input id="name" class="form-control required" disabled>
</div>
<div class="mb-3">
<label class="form-label" for="start-datetime">
<?= lang('start') ?>
<span class="text-danger" hidden>*</span>
</label>
<input id="start-datetime" class="form-control required" disabled>
</div>
<div class="mb-3">
<label class="form-label" for="end-datetime">
<?= lang('end') ?>
<span class="text-danger" hidden>*</span>
</label>
<input id="end-datetime" class="form-control required" disabled>
</div>
<div class="mb-3">
<label class="form-label" for="description">
<?= lang('description') ?>
</label>
<textarea id="description" rows="4" class="form-control" disabled></textarea>
</div>
</div>
</div>
</div>
<?php end_section('content') ?>
<?php section('scripts') ?>
<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/http/blocked_periods_http_client.js') ?>"></script>
<script src="<?= asset_url('assets/js/pages/blocked_periods.js') ?>"></script>
<?php end_section('scripts') ?>

View file

@ -0,0 +1,133 @@
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Blocked-periods HTTP client.
*
* This module implements the blocked-periods related HTTP requests.
*/
App.Http.BlockedPeriods = (function () {
/**
* Save (create or update) a blocked-period.
*
* @param {Object} blockedPeriod
*
* @return {Object}
*/
function save(blockedPeriod) {
return blockedPeriod.id ? update(blockedPeriod) : store(blockedPeriod);
}
/**
* Create a blocked-period.
*
* @param {Object} blockedPeriod
*
* @return {Object}
*/
function store(blockedPeriod) {
const url = App.Utils.Url.siteUrl('blocked_periods/store');
const data = {
csrf_token: vars('csrf_token'),
blocked_period: blockedPeriod
};
return $.post(url, data);
}
/**
* Update a blocked-period.
*
* @param {Object} blockedPeriod
*
* @return {Object}
*/
function update(blockedPeriod) {
const url = App.Utils.Url.siteUrl('blocked_periods/update');
const data = {
csrf_token: vars('csrf_token'),
blocked_period: blockedPeriod
};
return $.post(url, data);
}
/**
* Delete a blocked-period.
*
* @param {Number} blockedPeriodId
*
* @return {Object}
*/
function destroy(blockedPeriodId) {
const url = App.Utils.Url.siteUrl('blocked_periods/destroy');
const data = {
csrf_token: vars('csrf_token'),
blocked_period_id: blockedPeriodId
};
return $.post(url, data);
}
/**
* Search blocked-periods by keyword.
*
* @param {String} keyword
* @param {Number} [limit]
* @param {Number} [offset]
* @param {String} [orderBy]
*
* @return {Object}
*/
function search(keyword, limit = null, offset = null, orderBy = null) {
const url = App.Utils.Url.siteUrl('blocked_periods/search');
const data = {
csrf_token: vars('csrf_token'),
keyword,
limit,
offset,
order_by: orderBy
};
return $.post(url, data);
}
/**
* Find a blocked-period.
*
* @param {Number} blockedPeriodId
*
* @return {Object}
*/
function find(blockedPeriodId) {
const url = App.Utils.Url.siteUrl('blocked_periods/find');
const data = {
csrf_token: vars('csrf_token'),
blocked_period_id: blockedPeriodId
};
return $.post(url, data);
}
return {
save,
store,
update,
destroy,
search,
find
};
})();

View file

@ -0,0 +1,337 @@
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Blocked-periods page.
*
* This module implements the functionality of the blocked-periods page.
*/
App.Pages.BlockedPeriods = (function () {
const $blockedPeriods = $('#blocked-periods');
const $filterBlockedPeriods = $('#filter-blocked-periods');
const $id = $('#id');
const $name = $('#name');
const $description = $('#description');
let filterResults = {};
let filterLimit = 20;
/**
* Add the page event listeners.
*/
function addEventListeners() {
/**
* Event: Filter Blocked Periods Form "Submit"
*
* @param {jQuery.Event} event
*/
$blockedPeriods.on('submit', '#filter-blocked-periods form', (event) => {
event.preventDefault();
const key = $('#filter-blocked-periods .key').val();
$('.selected').removeClass('selected');
resetForm();
filter(key);
});
/**
* Event: Filter Blocked-Periods Row "Click"
*
* Displays the selected row data on the right side of the page.
*
* @param {jQuery.Event} event
*/
$blockedPeriods.on('click', '.blocked-period-row', (event) => {
if ($('#filter-blocked-periods .filter').prop('disabled')) {
$('#filter-blocked-periods .results').css('color', '#AAA');
return; // exit because we are on edit mode
}
const blockedPeriodId = $(event.currentTarget).attr('data-id');
const blockedPeriod = filterResults.find((filterResult) => Number(filterResult.id) === Number(blockedPeriodId));
display(blockedPeriod);
$('#filter-blocked-periods .selected').removeClass('selected');
$(event.currentTarget).addClass('selected');
$('#edit-blocked-period, #delete-blocked-period').prop('disabled', false);
});
/**
* Event: Add Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#add-blocked-period', () => {
resetForm();
$blockedPeriods.find('.add-edit-delete-group').hide();
$blockedPeriods.find('.save-cancel-group').show();
$blockedPeriods.find('.record-details').find('input, select, textarea').prop('disabled', false);
$blockedPeriods.find('.record-details .form-label span').prop('hidden', false);
$filterBlockedPeriods.find('button').prop('disabled', true);
$filterBlockedPeriods.find('.results').css('color', '#AAA');
});
/**
* Event: Edit Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#edit-blocked-period', () => {
$blockedPeriods.find('.add-edit-delete-group').hide();
$blockedPeriods.find('.save-cancel-group').show();
$blockedPeriods.find('.record-details').find('input, select, textarea').prop('disabled', false);
$blockedPeriods.find('.record-details .form-label span').prop('hidden', false);
$filterBlockedPeriods.find('button').prop('disabled', true);
$filterBlockedPeriods.find('.results').css('color', '#AAA');
});
/**
* Event: Delete Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#delete-blocked-period', () => {
const blockedPeriodId = $id.val();
const buttons = [
{
text: lang('cancel'),
click: (event, messageModal) => {
messageModal.dispose();
}
},
{
text: lang('delete'),
click: (event, messageModal) => {
remove(blockedPeriodId);
messageModal.dispose();
}
}
];
App.Utils.Message.show(lang('delete_blocked_period'), lang('delete_record_prompt'), buttons);
});
/**
* Event: Blocked period Save Button "Click"
*/
$blockedPeriods.on('click', '#save-blocked-period', () => {
const blockedPeriod = {
name: $name.val(),
description: $description.val()
};
if ($id.val() !== '') {
blockedPeriod.id = $id.val();
}
if (!validate()) {
return;
}
save(blockedPeriod);
});
/**
* Event: Cancel Blocked-Period Button "Click"
*/
$blockedPeriods.on('click', '#cancel-blocked-period', () => {
const id = $id.val();
resetForm();
if (id !== '') {
select(id, true);
}
});
}
/**
* Filter blocked periods records.
*
* @param {String} keyword This key string is used to filter the blocked-period records.
* @param {Number} selectId Optional, if set then after the filter operation the record with the given ID will be
* selected (but not displayed).
* @param {Boolean} show Optional (false), if true then the selected record will be displayed on the form.
*/
function filter(keyword, selectId = null, show = false) {
App.Http.BlockedPeriods.search(keyword, filterLimit).then((response) => {
filterResults = response;
$('#filter-blocked-periods .results').empty();
response.forEach((blockedPeriod) => {
$('#filter-blocked-periods .results').append(getFilterHtml(blockedPeriod)).append($('<hr/>'));
});
if (response.length === 0) {
$('#filter-blocked-periods .results').append(
$('<em/>', {
'text': lang('no_records_found')
})
);
} else if (response.length === filterLimit) {
$('<button/>', {
'type': 'button',
'class': 'btn btn-outline-secondary w-100 load-more text-center',
'text': lang('load_more'),
'click': () => {
filterLimit += 20;
filter(keyword, selectId, show);
}
}).appendTo('#filter-blocked-periods .results');
}
if (selectId) {
select(selectId, show);
}
});
}
/**
* Save a blocked-period record to the database (via AJAX post).
*
* @param {Object} blockedPeriod Contains the blocked-period data.
*/
function save(blockedPeriod) {
App.Http.BlockedPeriods.save(blockedPeriod).then((response) => {
App.Layouts.Backend.displayNotification(lang('blocked_period_saved'));
resetForm();
$filterBlockedPeriods.find('.key').val('');
filter('', response.id, true);
});
}
/**
* Delete blocked-period record.
*
* @param {Number} id Record ID to be deleted.
*/
function remove(id) {
App.Http.BlockedPeriods.destroy(id).then(() => {
App.Layouts.Backend.displayNotification(lang('blocked_period_deleted'));
resetForm();
filter($('#filter-blocked-periods .key').val());
});
}
/**
* Display a blocked-period record on the form.
*
* @param {Object} blockedPeriod Contains the blocked-period data.
*/
function display(blockedPeriod) {
$id.val(blockedPeriod.id);
$name.val(blockedPeriod.name);
$description.val(blockedPeriod.description);
}
/**
* Validate blocked-period data before save (insert or update).
*
* @return {Boolean} Returns the validation result.
*/
function validate() {
$blockedPeriods.find('.is-invalid').removeClass('is-invalid');
$blockedPeriods.find('.form-message').removeClass('alert-danger').hide();
try {
let missingRequired = false;
$blockedPeriods.find('.required').each((index, fieldEl) => {
if (!$(fieldEl).val()) {
$(fieldEl).addClass('is-invalid');
missingRequired = true;
}
});
if (missingRequired) {
throw new Error(lang('fields_are_required'));
}
return true;
} catch (error) {
$blockedPeriods.find('.form-message').addClass('alert-danger').text(error.message).show();
return false;
}
}
/**
* Bring the blocked-period form back to its initial state.
*/
function resetForm() {
$filterBlockedPeriods.find('.selected').removeClass('selected');
$filterBlockedPeriods.find('button').prop('disabled', false);
$filterBlockedPeriods.find('.results').css('color', '');
$blockedPeriods.find('.add-edit-delete-group').show();
$blockedPeriods.find('.save-cancel-group').hide();
$blockedPeriods.find('.record-details').find('input, select, textarea').val('').prop('disabled', true);
$blockedPeriods.find('.record-details .form-label span').prop('hidden', true);
$('#edit-blocked-period, #delete-blocked-period').prop('disabled', true);
$blockedPeriods.find('.record-details .is-invalid').removeClass('is-invalid');
$blockedPeriods.find('.record-details .form-message').hide();
}
/**
* Get the filter results row HTML code.
*
* @param {Object} blockedPeriod Contains the blocked-period data.
*
* @return {String} Returns the record HTML code.
*/
function getFilterHtml(blockedPeriod) {
return $('<div/>', {
'class': 'blocked-period-row entry',
'data-id': blockedPeriod.id,
'html': [
$('<strong/>', {
'text': blockedPeriod.name
}),
$('<br/>')
]
});
}
/**
* Select a specific record from the current filter results.
*
* If the blocked-period ID does not exist in the list then no record will be selected.
*
* @param {Number} id The record ID to be selected from the filter results.
* @param {Boolean} show Optional (false), if true then the method will display the record on the form.
*/
function select(id, show = false) {
$filterBlockedPeriods.find('.selected').removeClass('selected');
$filterBlockedPeriods.find('.blocked-period-row[data-id="' + id + '"]').addClass('selected');
if (show) {
const blockedPeriod = filterResults.find((blockedPeriod) => Number(blockedPeriod.id) === Number(id));
display(blockedPeriod);
$('#edit-blocked-period, #delete-blocked-period').prop('disabled', false);
}
}
/**
* Initialize the module.
*/
function initialize() {
resetForm();
filter('');
addEventListeners();
}
document.addEventListener('DOMContentLoaded', initialize);
return {
filter,
save,
remove,
getFilterHtml,
resetForm,
select
};
})();