2015-07-20 22:41:24 +03:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Easy ! Appointments - Open Source Web Scheduler
2015-10-05 01:31:06 +03:00
*
2015-07-20 22:41:24 +03:00
* @ package EasyAppointments
* @ author A . Tselegidis < alextselegidis @ gmail . com >
2021-12-18 19:43:45 +03:00
* @ copyright Copyright ( c ) Alex Tselegidis
* @ license https : //opensource.org/licenses/GPL-3.0 - GPLv3
* @ link https : //easyappointments.org
2015-07-20 22:41:24 +03:00
* @ since v1 . 0.0
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
2016-04-24 20:09:33 +03:00
window . GeneralFunctions = window . GeneralFunctions || { } ;
2013-05-08 17:31:17 +03:00
/ * *
2016-04-24 20:09:33 +03:00
* General Functions Module
*
* It contains functions that apply both on the front and back end of the application .
2015-10-05 01:31:06 +03:00
*
2016-04-24 20:09:33 +03:00
* @ module GeneralFunctions
2013-05-08 17:31:17 +03:00
* /
2018-01-23 12:08:37 +03:00
( function ( exports ) {
2022-01-18 13:14:45 +03:00
( 'use strict' ) ;
2016-04-24 20:09:33 +03:00
2020-12-02 20:57:49 +03:00
/ * *
* Register global error handler .
* /
2022-01-18 13:14:45 +03:00
document . addEventListener ( 'DOMContentLoaded' , ( ) => {
$ ( document ) . ajaxError ( ( event , jqxhr , settings , thrownError ) => {
2020-12-02 21:08:28 +03:00
GeneralFunctions . ajaxFailureHandler ( jqxhr , settings , thrownError ) ;
} ) ;
2020-12-02 20:57:49 +03:00
} ) ;
2013-06-13 19:25:34 +03:00
/ * *
2016-10-10 19:29:48 +03:00
* This functions displays a message box in the admin array . It is useful when user
2013-06-13 19:25:34 +03:00
* decisions or verifications are needed .
2015-10-05 01:31:06 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { String } title The title of the message box .
* @ param { String } message The message of the dialog .
2017-11-14 15:55:35 +03:00
* @ param { Array } buttons Contains the dialog buttons along with their functions .
2013-06-13 19:25:34 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . displayMessageBox = ( title , message , buttons = null ) => {
2020-05-06 20:15:11 +03:00
if ( ! title ) {
2020-04-27 21:14:20 +03:00
title = '- No Title Provided -' ;
2015-10-05 01:31:06 +03:00
}
2013-05-08 17:31:17 +03:00
2020-05-06 20:15:11 +03:00
if ( ! message ) {
2020-04-27 21:14:20 +03:00
message = '- No Message Provided -' ;
2015-10-05 01:31:06 +03:00
}
2013-05-08 17:31:17 +03:00
2020-05-06 20:15:11 +03:00
if ( ! buttons ) {
2017-11-14 15:55:35 +03:00
buttons = [
{
2022-01-18 10:22:25 +03:00
text : lang ( 'close' ) ,
2022-01-18 13:14:45 +03:00
click : ( ) => {
2020-09-07 11:08:18 +03:00
$ ( '#message-box' ) . dialog ( 'close' ) ;
2017-11-14 15:55:35 +03:00
}
}
] ;
2013-06-13 19:25:34 +03:00
}
2013-05-08 17:31:17 +03:00
2013-06-13 19:25:34 +03:00
// Destroy previous dialog instances.
2021-11-06 19:38:37 +03:00
$ ( '#message-box' ) . dialog ( 'destroy' ) . remove ( ) ;
2013-06-03 17:42:19 +03:00
2013-06-13 19:25:34 +03:00
// Create the html of the message box.
2020-04-27 21:14:20 +03:00
$ ( '<div/>' , {
2020-09-07 11:08:18 +03:00
'id' : 'message-box' ,
2020-04-27 21:14:20 +03:00
'title' : title ,
'html' : [
$ ( '<p/>' , {
'html' : message
} )
]
2021-11-06 19:38:37 +03:00
} ) . appendTo ( 'body' ) ;
2013-06-10 18:51:23 +03:00
2021-11-06 19:38:37 +03:00
$ ( '#message-box' ) . dialog ( {
2013-07-06 03:00:04 +03:00
autoOpen : false ,
modal : true ,
2015-04-26 17:20:16 +03:00
resize : 'auto' ,
width : 'auto' ,
height : 'auto' ,
2013-07-06 03:00:04 +03:00
resizable : false ,
2017-11-14 15:55:35 +03:00
buttons : buttons ,
2013-12-29 15:57:09 +02:00
closeOnEscape : true
2013-06-13 19:25:34 +03:00
} ) ;
2020-09-07 11:08:18 +03:00
$ ( '#message-box' ) . dialog ( 'open' ) ;
2020-09-28 15:24:29 +03:00
$ ( '.ui-dialog .ui-dialog-buttonset button' ) . addClass ( 'btn btn-outline-secondary' ) ;
2020-09-07 11:08:18 +03:00
$ ( '#message-box .ui-dialog-titlebar-close' ) . hide ( ) ;
2016-04-24 20:09:33 +03:00
} ;
2013-06-13 19:25:34 +03:00
/ * *
2016-04-24 20:09:33 +03:00
* This method centers a DOM element vertically and horizontally on the page .
2015-10-05 01:31:06 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { Object } elementHandle The object that is going to be centered .
2013-06-13 19:25:34 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . centerElementOnPage = ( elementHandle ) => {
2013-06-13 19:25:34 +03:00
// Center main frame vertical middle
2018-01-23 12:08:37 +03:00
$ ( window ) . resize ( function ( ) {
2013-06-13 19:25:34 +03:00
var elementLeft = ( $ ( window ) . width ( ) - elementHandle . outerWidth ( ) ) / 2 ;
var elementTop = ( $ ( window ) . height ( ) - elementHandle . outerHeight ( ) ) / 2 ;
2020-04-27 21:14:20 +03:00
elementTop = elementTop > 0 ? elementTop : 20 ;
2013-06-13 19:25:34 +03:00
elementHandle . css ( {
2013-07-06 03:00:04 +03:00
position : 'absolute' ,
left : elementLeft ,
top : elementTop
2015-10-05 01:31:06 +03:00
} ) ;
2013-06-13 19:25:34 +03:00
} ) ;
$ ( window ) . resize ( ) ;
2016-04-24 20:09:33 +03:00
} ;
2013-06-13 19:25:34 +03:00
/ * *
2015-10-05 01:31:06 +03:00
* This function retrieves a parameter from a "GET" formed url .
*
2020-04-27 21:14:20 +03:00
* @ link http : //www.netlobo.com/url_query_string_javascript.html
2015-10-05 01:31:06 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { String } url The selected url .
2020-04-27 21:14:20 +03:00
* @ param { String } parameterName The parameter name .
2016-04-24 20:09:33 +03:00
2016-05-14 13:25:20 +03:00
* @ return { String } Returns the parameter value .
2013-06-13 19:25:34 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . getUrlParameter = ( url , parameterName ) => {
2016-07-16 22:06:55 +03:00
var parsedUrl = url . substr ( url . indexOf ( '?' ) ) . slice ( 1 ) . split ( '&' ) ;
for ( var index in parsedUrl ) {
2018-01-23 12:08:37 +03:00
var parsedValue = parsedUrl [ index ] . split ( '=' ) ;
2016-07-16 22:06:55 +03:00
if ( parsedValue . length === 1 && parsedValue [ 0 ] === parameterName ) {
2018-01-23 12:08:37 +03:00
return '' ;
2016-07-16 22:06:55 +03:00
}
if ( parsedValue . length === 2 && parsedValue [ 0 ] === parameterName ) {
2018-01-23 12:08:37 +03:00
return decodeURIComponent ( parsedValue [ 1 ] ) ;
2016-07-16 22:06:55 +03:00
}
}
return '' ;
2016-04-24 20:09:33 +03:00
} ;
2013-06-13 19:25:34 +03:00
/ * *
2016-05-14 13:25:20 +03:00
* Convert date to ISO date string .
*
2016-04-24 20:09:33 +03:00
* This function creates a RFC 3339 date string . This string is needed by the Google Calendar API
2016-05-14 13:25:20 +03:00
* in order to pass dates as parameters .
2015-10-05 01:31:06 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { Date } date The given date that will be transformed .
2016-04-24 20:09:33 +03:00
* @ return { String } Returns the transformed string .
2013-06-13 19:25:34 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . ISODateString = ( date ) => {
2015-12-02 00:25:59 +02:00
function pad ( n ) {
2016-05-14 13:25:20 +03:00
return n < 10 ? '0' + n : n ;
2015-12-02 00:25:59 +02:00
}
2013-06-13 19:25:34 +03:00
2021-11-06 19:38:37 +03:00
return (
date . getUTCFullYear ( ) +
'-' +
pad ( date . getUTCMonth ( ) + 1 ) +
'-' +
pad ( date . getUTCDate ( ) ) +
'T' +
pad ( date . getUTCHours ( ) ) +
':' +
pad ( date . getUTCMinutes ( ) ) +
':' +
pad ( date . getUTCSeconds ( ) ) +
'Z'
) ;
2016-04-24 20:09:33 +03:00
} ;
2015-10-05 01:31:06 +03:00
2013-06-18 19:06:34 +03:00
/ * *
2016-05-14 13:25:20 +03:00
* Clone JS Object
2015-10-05 01:31:06 +03:00
*
2020-04-27 21:14:20 +03:00
* This method creates and returns an exact copy of the provided object . It is very useful whenever changes need to
* be made to an object without modifying the original data .
2015-10-05 01:31:06 +03:00
*
2020-04-27 21:14:20 +03:00
* @ link https : //stackoverflow.com/a/728694
2016-05-14 13:25:20 +03:00
*
* @ param { Object } originalObject Object to be copied .
2016-04-24 20:09:33 +03:00
2016-05-14 13:25:20 +03:00
* @ return { Object } Returns an exact copy of the provided element .
2013-06-18 19:06:34 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . clone = ( originalObject ) => {
2013-06-18 19:06:34 +03:00
// Handle the 3 simple types, and null or undefined
2020-05-06 20:15:11 +03:00
if ( ! originalObject || typeof originalObject !== 'object' ) {
2013-06-18 19:06:34 +03:00
return originalObject ;
2020-05-06 20:15:11 +03:00
}
var copy ;
2013-06-18 19:06:34 +03:00
// Handle Date
if ( originalObject instanceof Date ) {
2020-05-06 20:15:11 +03:00
copy = new Date ( ) ;
2013-06-18 19:06:34 +03:00
copy . setTime ( originalObject . getTime ( ) ) ;
return copy ;
}
// Handle Array
if ( originalObject instanceof Array ) {
2020-05-06 20:15:11 +03:00
copy = [ ] ;
2013-06-18 19:06:34 +03:00
for ( var i = 0 , len = originalObject . length ; i < len ; i ++ ) {
copy [ i ] = GeneralFunctions . clone ( originalObject [ i ] ) ;
}
return copy ;
}
// Handle Object
if ( originalObject instanceof Object ) {
2020-05-06 20:15:11 +03:00
copy = { } ;
2013-06-18 19:06:34 +03:00
for ( var attr in originalObject ) {
2021-11-06 19:38:37 +03:00
if ( originalObject . hasOwnProperty ( attr ) ) copy [ attr ] = GeneralFunctions . clone ( originalObject [ attr ] ) ;
2013-06-18 19:06:34 +03:00
}
return copy ;
}
2021-11-06 19:38:37 +03:00
throw new Error ( "Unable to copy obj! Its type isn't supported." ) ;
2016-04-24 20:09:33 +03:00
} ;
2015-10-05 01:31:06 +03:00
2013-06-29 00:54:12 +03:00
/ * *
2016-05-14 13:25:20 +03:00
* Validate Email Address
*
2013-06-29 00:54:12 +03:00
* This method validates an email address . If the address is not on the proper
* form then the result is FALSE .
2015-10-05 01:31:06 +03:00
*
2020-04-27 21:14:20 +03:00
* @ link http : //badsyntax.co/post/javascript-email-validation-rfc822
2015-10-11 23:30:18 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { String } email The email address to be checked .
2016-04-24 20:09:33 +03:00
2016-05-14 13:25:20 +03:00
* @ return { Boolean } Returns the validation result .
2013-06-29 00:54:12 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . validateEmail = ( email ) => {
2021-11-06 19:38:37 +03:00
var re =
/(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/ ;
2015-10-11 23:30:18 +03:00
return re . test ( email ) ;
2016-04-24 20:09:33 +03:00
} ;
2015-10-05 01:31:06 +03:00
2013-09-18 19:36:29 +03:00
/ * *
* Makes the first letter of the string upper case .
2015-10-05 01:31:06 +03:00
*
2020-04-27 21:14:20 +03:00
* @ param { String } value The string to be converted .
2016-05-14 13:25:20 +03:00
*
* @ return { String } Returns the capitalized string .
2013-09-18 19:36:29 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . upperCaseFirstLetter = ( value ) => value . charAt ( 0 ) . toUpperCase ( ) + value . slice ( 1 ) ;
2015-10-05 01:31:06 +03:00
2013-12-23 18:55:42 +02:00
/ * *
2016-05-14 13:25:20 +03:00
* Enable Language Selection
*
2020-04-27 21:14:20 +03:00
* Enables the language selection functionality . Must be called on every page has a language selection button .
2022-01-18 10:18:22 +03:00
* This method requires the global variable 'vars(' available _languages ')' to be initialized before the execution .
2015-10-05 01:31:06 +03:00
*
2016-05-14 13:25:20 +03:00
* @ param { Object } $element Selected element button for the language selection .
2022-01-17 21:44:44 +03:00
*
* @ deprecated Since 1.5
2013-12-23 18:55:42 +02:00
* /
2022-01-18 13:14:45 +03:00
exports . enableLanguageSelection = ( $element ) => {
2022-01-17 21:44:44 +03:00
console . warn (
` Call of deprecated GeneralFunctions.enableLanguageSelection method! Please use the App.Utils.Lang.enableLanguageSelection instead as this method will be removed soon. `
) ;
App . Utils . Lang . enableLanguageSelection ( $element ) ;
2016-04-24 20:09:33 +03:00
} ;
2015-10-09 00:12:59 +03:00
/ * *
2016-05-14 13:25:20 +03:00
* AJAX Failure Handler
2015-10-09 00:12:59 +03:00
*
2020-04-27 21:14:20 +03:00
* @ param { jqXHR } jqXHR
2016-05-14 13:25:20 +03:00
* @ param { String } textStatus
* @ param { Object } errorThrown
2015-10-09 00:12:59 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . ajaxFailureHandler = ( jqXHR , textStatus , errorThrown ) => {
2020-04-27 21:14:20 +03:00
console . error ( 'Unexpected HTTP Error: ' , jqXHR , textStatus , errorThrown ) ;
2020-08-15 15:26:26 +03:00
var response ;
try {
response = JSON . parse ( jqXHR . responseText ) ; // JSON response
2020-12-09 15:17:45 +03:00
} catch ( error ) {
response = { message : jqXHR . responseText } ; // String response
2020-08-15 15:26:26 +03:00
}
2020-04-27 21:14:20 +03:00
if ( ! response ) {
return ;
}
2022-01-18 10:22:25 +03:00
GeneralFunctions . displayMessageBox ( lang ( 'unexpected_issues' ) , lang ( 'unexpected_issues_message' ) ) ;
2020-04-27 21:14:20 +03:00
$ ( '<div/>' , {
2020-08-31 18:33:36 +03:00
'class' : 'card' ,
'html' : [
$ ( '<div/>' , {
2021-11-17 11:23:21 +03:00
'class' : 'card-body overflow-auto' ,
2020-08-31 18:33:36 +03:00
'html' : response . message || '→ No error information provided.'
} )
]
2021-11-06 19:38:37 +03:00
} ) . appendTo ( '#message-box' ) ;
2016-04-24 20:09:33 +03:00
} ;
2015-11-28 13:55:03 +02:00
/ * *
* Escape JS HTML string values for XSS prevention .
*
2020-04-27 21:14:20 +03:00
* @ param { String } content String to be escaped .
2016-05-14 13:25:20 +03:00
*
* @ return { String } Returns the escaped string .
2015-11-28 13:55:03 +02:00
* /
2022-01-18 13:14:45 +03:00
exports . escapeHtml = ( content ) => $ ( '<div/>' ) . text ( content ) . html ( ) ;
2015-12-02 00:25:59 +02:00
/ * *
* Format a given date according to the date format setting .
*
2020-10-20 16:03:48 +03:00
* @ param { String } date The date to be formatted .
2020-04-27 21:14:20 +03:00
* @ param { String } dateFormatSetting The setting provided by PHP must be one of the "DMY" , "MDY" or "YMD" .
2016-05-14 13:25:20 +03:00
* @ param { Boolean } addHours ( optional ) Whether to add hours to the result .
2016-04-24 20:09:33 +03:00
2016-05-14 13:25:20 +03:00
* @ return { String } Returns the formatted date string .
2015-12-02 00:25:59 +02:00
* /
2022-01-18 13:14:45 +03:00
exports . formatDate = ( date , dateFormatSetting , addHours ) => {
2022-01-18 10:18:22 +03:00
var timeFormat = vars ( 'time_format' ) === 'regular' ? 'h:mm a' : 'HH:mm' ;
2018-03-08 16:55:51 +03:00
var hours = addHours ? ' ' + timeFormat : '' ;
var result ;
2021-11-24 10:34:26 +03:00
var parsedDateMoment = moment ( date ) ;
2020-12-12 16:11:33 +03:00
2021-11-24 10:34:26 +03:00
if ( ! parsedDateMoment . isValid ( ) ) {
2020-12-12 16:11:33 +03:00
return date ;
}
2015-12-02 00:25:59 +02:00
2018-01-23 12:08:37 +03:00
switch ( dateFormatSetting ) {
2015-12-02 00:25:59 +02:00
case 'DMY' :
2021-11-24 10:34:26 +03:00
result = parsedDateMoment . format ( 'DD/MM/YYYY' + hours ) ;
2015-12-02 00:25:59 +02:00
break ;
case 'MDY' :
2021-11-24 10:34:26 +03:00
result = parsedDateMoment . format ( 'MM/DD/YYYY' + hours ) ;
2015-12-02 00:25:59 +02:00
break ;
case 'YMD' :
2021-11-24 10:34:26 +03:00
result = parsedDateMoment . format ( 'YYYY/MM/DD' + hours ) ;
2015-12-02 00:25:59 +02:00
break ;
default :
throw new Error ( 'Invalid date format setting provided!' , dateFormatSetting ) ;
}
return result ;
2016-04-24 20:09:33 +03:00
} ;
2018-06-29 01:41:17 +03:00
/ * *
2020-04-27 21:14:20 +03:00
* Get the Id of a Weekday using the US week format and day names ( Sunday = 0 ) as used in the JS code of the
* application , case insensitive , short and long names supported .
2018-06-29 01:41:17 +03:00
*
2020-04-27 21:14:20 +03:00
* @ param { String } weekDayName The weekday name among Sunday , Monday , Tuesday , Wednesday , Thursday , Friday ,
* Saturday .
2018-06-29 01:41:17 +03:00
2020-04-27 21:14:20 +03:00
* @ return { Number } Returns the ID of the weekday .
2018-06-29 01:41:17 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . getWeekDayId = ( weekDayName ) => {
2018-06-29 01:41:17 +03:00
var result ;
switch ( weekDayName . toLowerCase ( ) ) {
case 'sunday' :
case 'sun' :
result = 0 ;
break ;
case 'monday' :
case 'mon' :
result = 1 ;
break ;
case 'tuesday' :
case 'tue' :
result = 2 ;
break ;
case 'wednesday' :
case 'wed' :
result = 3 ;
break ;
case 'thursday' :
case 'thu' :
result = 4 ;
break ;
case 'friday' :
case 'fri' :
result = 5 ;
2020-03-10 22:32:53 +03:00
break ;
2018-06-29 01:41:17 +03:00
case 'saturday' :
case 'sat' :
result = 6 ;
2020-03-10 22:32:53 +03:00
break ;
2018-06-29 01:41:17 +03:00
default :
throw new Error ( 'Invalid weekday name provided!' , weekDayName ) ;
}
return result ;
} ;
2018-06-26 00:53:12 +03:00
/ * *
* Get the name in lowercase of a Weekday using its Id .
*
2020-04-27 21:14:20 +03:00
* @ param { Number } weekDayId The Id ( From 0 for sunday to 6 for saturday ) .
2018-06-26 00:53:12 +03:00
* @ return { String } Returns the name of the weekday .
* /
2022-01-18 13:14:45 +03:00
exports . getWeekdayName = ( weekDayId ) => {
2018-06-26 00:53:12 +03:00
var result ;
switch ( weekDayId ) {
case 0 :
result = 'sunday' ;
break ;
case 1 :
result = 'monday' ;
break ;
case 2 :
result = 'tuesday' ;
break ;
case 3 :
result = 'wednesday' ;
break ;
case 4 :
result = 'thursday' ;
break ;
case 5 :
result = 'friday' ;
break ;
case 6 :
result = 'saturday' ;
break ;
default :
throw new Error ( 'Invalid weekday Id provided!' , weekDayId ) ;
}
return result ;
} ;
/ * *
* Sort a dictionary where keys are weekdays
*
2020-04-27 21:14:20 +03:00
* @ param { Object } weekDictionary A dictionary with weekdays as keys .
* @ param { Number } startDayId Id of the first day to start sorting ( From 0 for sunday to 6 for saturday ) .
2018-06-26 00:53:12 +03:00
* @ return { Object } Returns a sorted dictionary
* /
2022-01-18 13:14:45 +03:00
exports . sortWeekDictionary = ( weekDictionary , startDayId ) => {
2020-12-09 15:17:45 +03:00
var sortedWeekDictionary = { } ;
2018-06-26 00:53:12 +03:00
2020-12-09 15:17:45 +03:00
for ( var i = startDayId ; i < startDayId + 7 ; i ++ ) {
2020-04-27 21:14:20 +03:00
var weekdayName = GeneralFunctions . getWeekdayName ( i % 7 ) ;
sortedWeekDictionary [ weekdayName ] = weekDictionary [ weekdayName ] ;
2018-06-26 00:53:12 +03:00
}
2020-04-27 21:14:20 +03:00
return sortedWeekDictionary ;
2018-06-26 00:53:12 +03:00
} ;
2019-06-08 18:20:49 +03:00
/ * *
* Render a map icon that links to Google maps .
*
* @ param { Object } user Should have the address , city , etc properties .
*
2020-04-27 21:14:20 +03:00
* @ return { string } The rendered HTML .
2019-06-08 18:20:49 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . renderMapIcon = ( user ) => {
2020-03-11 15:24:23 +03:00
var data = [ ] ;
2019-06-08 18:20:49 +03:00
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 $ ( '<div/>' , {
'html' : [
$ ( '<a/>' , {
'href' : 'https://www.google.com/maps/place/' + data . join ( ',' ) ,
'target' : '_blank' ,
'html' : [
$ ( '<span/>' , {
2020-06-29 16:23:51 +03:00
'class' : 'fas fa-map-marker-alt'
2019-06-08 18:20:49 +03:00
} )
]
} )
]
2021-11-06 19:38:37 +03:00
} ) . html ( ) ;
2019-06-08 18:20:49 +03:00
} ;
/ * *
* Render a mail icon .
*
* @ param { String } email
*
2020-04-27 21:14:20 +03:00
* @ return { string } The rendered HTML .
2019-06-08 18:20:49 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . renderMailIcon = ( email ) =>
$ ( '<div/>' , {
2019-06-08 18:20:49 +03:00
'html' : [
$ ( '<a/>' , {
'href' : 'mailto:' + email ,
'target' : '_blank' ,
'html' : [
$ ( '<span/>' , {
2020-12-08 01:10:49 +03:00
'class' : 'fas fa-envelope'
2019-06-08 18:20:49 +03:00
} )
]
} )
]
2021-11-06 19:38:37 +03:00
} ) . html ( ) ;
2019-06-08 18:20:49 +03:00
/ * *
* Render a phone icon .
*
* @ param { String } phone
*
2020-04-27 21:14:20 +03:00
* @ return { string } The rendered HTML .
2019-06-08 18:20:49 +03:00
* /
2022-01-18 13:14:45 +03:00
exports . renderPhoneIcon = ( phone ) =>
$ ( '<div/>' , {
2019-06-08 18:20:49 +03:00
'html' : [
$ ( '<a/>' , {
'href' : 'tel:' + phone ,
'target' : '_blank' ,
'html' : [
$ ( '<span/>' , {
2020-06-29 16:23:51 +03:00
'class' : 'fas fa-phone-alt'
2019-06-08 18:20:49 +03:00
} )
]
} )
]
2021-11-06 19:38:37 +03:00
} ) . html ( ) ;
2016-04-24 20:09:33 +03:00
} ) ( window . GeneralFunctions ) ;