/* ---------------------------------------------------------------------------- * Easy!Appointments - Online Appointment Scheduler * * @package EasyAppointments * @author A.Tselegidis * @copyright Copyright (c) Alex Tselegidis * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 * @link https://easyappointments.org * @since v1.5.0 * ---------------------------------------------------------------------------- */ /** * Appointment status options component. * * This module implements the appointment status options. */ App.Components.AppointmentStatusOptions = (function () { /** * Render an appointment status option. * * @param {String} [appointmentStatusOption] * * @return {jQuery} Returns a jQuery selector with the list group item markup. */ function renderListGroupItem(appointmentStatusOption = '') { return $(`
  • `); } /** * Event: Delete Appointment Status Option "Click" * * @param {jQuery.Event} event */ function onDeleteAppointmentStatusOptionClick(event) { $(event.currentTarget).closest('li').remove(); } /** * Event: Add Appointment Status Option "Click" * * @param {jQuery.Event} event */ function onAddAppointmentStatusOptionClick(event) { const $target = $(event.currentTarget); const $listGroup = $target.closest('.appointment-status-options').find('.list-group'); if (!$listGroup.length) { return; } renderListGroupItem() .appendTo($listGroup); } /** * Get target options. * * @param {jQuery} $target Container element ".status-list" selector. * * @return {String[]} */ function getOptions($target) { const $listGroup = $target.find('.list-group'); const appointmentStatusOptions = []; $listGroup.find('li').each((index, listGroupItemEl) => { const $listGroupItem = $(listGroupItemEl); const appointmentStatusOption = $listGroupItem.find('input:text').val(); appointmentStatusOptions.push(appointmentStatusOption); }); return appointmentStatusOptions; } /** * Set target options. * * @param {jQuery} $target Container element ".status-list" selector. * @param {String[]} appointmentStatusOptions Appointment status options. */ function setOptions($target, appointmentStatusOptions) { if (!$target.length || !appointmentStatusOptions || !appointmentStatusOptions.length) { return; } const $listGroup = $target.find('.list-group'); if (!$listGroup.length) { return; } $listGroup.empty(); appointmentStatusOptions.forEach((appointmentStatusOption) => { renderListGroupItem(appointmentStatusOption).appendTo($listGroup); }); } /** * Initialize the module. */ function initialize() { $(document).on('click', '.delete-appointment-status-option', onDeleteAppointmentStatusOptionClick); $(document).on('click', '.add-appointment-status-option', onAddAppointmentStatusOptionClick); } document.addEventListener('DOMContentLoaded', initialize); return { getOptions, setOptions }; })();