From ddd252303ea552b4e9e76f05984dd01fa16311e6 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Wed, 12 Jan 2022 11:22:22 +0100 Subject: [PATCH] Port calendar event popover methods from GeneralFunctions to the new CalendarEventPopover utility module. --- assets/js/utils/calendar_event_popover.js | 115 ++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 assets/js/utils/calendar_event_popover.js diff --git a/assets/js/utils/calendar_event_popover.js b/assets/js/utils/calendar_event_popover.js new file mode 100644 index 00000000..56d832e5 --- /dev/null +++ b/assets/js/utils/calendar_event_popover.js @@ -0,0 +1,115 @@ +/* ---------------------------------------------------------------------------- + * Easy!Appointments - Open Source Web 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.2.0 + * ---------------------------------------------------------------------------- */ + +App.Utils.CalendarEventPopover = (function () { + /** + * Render a map icon that links to Google maps. + * + * Old Name: GeneralFunctions.renderMapIcon + * + * @param {Object} user Should have the address, city, etc properties. + * + * @return {string} The rendered HTML. + */ + function renderMapIcon(user) { + const data = []; + + if (user.address) { + data.push(user.address); + } + + if (user.city) { + data.push(user.city); + } + + if (user.state) { + data.push(user.state); + } + + if (user.zip_code) { + data.push(user.zip_code); + } + + if (!data.length) { + return ''; + } + + return $('
', { + 'html': [ + $('', { + 'href': 'https://google.com/maps/place/' + data.join(','), + 'target': '_blank', + 'html': [ + $('', { + 'class': 'fas fa-map-marker-alt' + }) + ] + }) + ] + }).html(); + } + + /** + * Render a mail icon. + * + * Old Name: GeneralFunctions.renderMailIcon + * + * @param {String} email + * + * @return {string} The rendered HTML. + */ + function renderMailIcon(email) { + return $('
', { + 'html': [ + $('', { + 'href': 'mailto:' + email, + 'target': '_blank', + 'html': [ + $('', { + 'class': 'fas fa-envelope' + }) + ] + }) + ] + }).html(); + } + + /** + * Render a phone icon. + * + * Old Name: GeneralFunctions.renderPhoneIcon + * + * @param {String} phone + * + * @return {string} The rendered HTML. + */ + function renderPhoneIcon(phone) { + return $('
', { + 'html': [ + $('', { + 'href': 'tel:' + phone, + 'target': '_blank', + 'html': [ + $('', { + 'class': 'fas fa-phone-alt' + }) + ] + }) + ] + }).html(); + } + + return { + renderPhoneIcon, + renderMapIcon, + renderMailIcon + }; +})();