| 1 |
if (!window.SequraFE) { |
| 2 |
window.SequraFE = {}; |
| 3 |
} |
| 4 |
|
| 5 |
(function () { |
| 6 |
function UtilityService() { |
| 7 |
/** |
| 8 |
* Shows the HTML node. |
| 9 |
* |
| 10 |
* @param {HTMLElement} element |
| 11 |
*/ |
| 12 |
this.showElement = (element) => { |
| 13 |
element?.classList.remove('sqs--hidden'); |
| 14 |
}; |
| 15 |
|
| 16 |
/** |
| 17 |
* Hides the HTML node. |
| 18 |
* |
| 19 |
* @param {HTMLElement} element |
| 20 |
*/ |
| 21 |
this.hideElement = (element) => { |
| 22 |
element?.classList.add('sqs--hidden'); |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* Enables loading spinner. |
| 27 |
*/ |
| 28 |
this.showLoader = () => { |
| 29 |
this.showElement(document.getElementById('sq-spinner')); |
| 30 |
}; |
| 31 |
|
| 32 |
/** |
| 33 |
* Hides loading spinner. |
| 34 |
*/ |
| 35 |
this.hideLoader = () => { |
| 36 |
this.hideElement(document.getElementById('sq-spinner')); |
| 37 |
}; |
| 38 |
|
| 39 |
/** |
| 40 |
* Shows flash message. |
| 41 |
* |
| 42 |
* @note Only one flash message will be shown at the same time. |
| 43 |
* |
| 44 |
* @param {string} message |
| 45 |
* @param {'error' | 'warning' | 'success'} status |
| 46 |
* @param {number?} clearAfter Time in ms to remove alert message. |
| 47 |
*/ |
| 48 |
this.createFlashMessage = (message, status, clearAfter) => { |
| 49 |
return SequraFE.elementGenerator.createFlashMessage(message, status, clearAfter); |
| 50 |
}; |
| 51 |
|
| 52 |
/** |
| 53 |
* Updates a form's footer state based on the number of changes. |
| 54 |
* |
| 55 |
* @param {boolean} disable |
| 56 |
*/ |
| 57 |
this.disableFooter = (disable) => { |
| 58 |
const saveButton = document.querySelector('.sq-page-footer .sqp-actions .sqp-save'); |
| 59 |
const cancelButton = document.querySelector('.sq-page-footer .sqp-actions .sqp-cancel'); |
| 60 |
|
| 61 |
if(saveButton && cancelButton){ |
| 62 |
saveButton.disabled = disable; |
| 63 |
cancelButton.disabled = disable; |
| 64 |
} |
| 65 |
}; |
| 66 |
/** |
| 67 |
* Creates deep clone of an object with object's properties. |
| 68 |
* Removes object's methods. |
| 69 |
* |
| 70 |
* @note Object cannot have values that cannot be converted to json (undefined, infinity etc). |
| 71 |
* |
| 72 |
* @param {object} obj |
| 73 |
* @return {object} |
| 74 |
*/ |
| 75 |
this.cloneObject = (obj) => JSON.parse(JSON.stringify(obj || {})); |
| 76 |
|
| 77 |
/** |
| 78 |
* Gets the first ancestor element with the corresponding class name. |
| 79 |
* |
| 80 |
* @param {HTMLElement} element |
| 81 |
* @param {string} className |
| 82 |
* @return {HTMLElement} |
| 83 |
*/ |
| 84 |
this.getAncestor = (element, className) => { |
| 85 |
let parent = element?.parentElement; |
| 86 |
|
| 87 |
while (parent) { |
| 88 |
if (parent.classList.contains(className)) { |
| 89 |
break; |
| 90 |
} |
| 91 |
|
| 92 |
parent = parent.parentElement; |
| 93 |
} |
| 94 |
|
| 95 |
return parent; |
| 96 |
}; |
| 97 |
|
| 98 |
/** |
| 99 |
* Returns the menu item array for page navigation. |
| 100 |
* |
| 101 |
* @param {string} activePage |
| 102 |
* @return {[{label: string, href: string, isActive: boolean},{label: string, href: string, isActive: boolean}]} |
| 103 |
*/ |
| 104 |
this.getMenuItems = (activePage) => { |
| 105 |
const menuItems = [ |
| 106 |
{ |
| 107 |
label: 'general.paymentMethods', |
| 108 |
href: window.location.href.split('#')[0] + '#payment', |
| 109 |
isActive: activePage === SequraFE.appStates.PAYMENT |
| 110 |
}, |
| 111 |
{ |
| 112 |
label: 'general.settings', |
| 113 |
href: window.location.href.split('#')[0] + '#settings', |
| 114 |
isActive: activePage === SequraFE.appStates.SETTINGS |
| 115 |
} |
| 116 |
]; |
| 117 |
|
| 118 |
if (SequraFE.pages?.transactions?.[0]) { |
| 119 |
menuItems.push({ |
| 120 |
label: 'general.transactionLogs', |
| 121 |
href: window.location.href.split('#')[0] + '#transactions', |
| 122 |
isActive: activePage === SequraFE.appStates.TRANSACTION |
| 123 |
}) |
| 124 |
} |
| 125 |
if (SequraFE.pages?.advanced?.[0]) { |
| 126 |
menuItems.push({ |
| 127 |
label: 'general.advanced', |
| 128 |
href: window.location.href.split('#')[0] + '#advanced', |
| 129 |
isActive: activePage === SequraFE.appStates.ADVANCED |
| 130 |
}) |
| 131 |
} |
| 132 |
|
| 133 |
return menuItems; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
SequraFE.utilities = new UtilityService(); |
| 138 |
})(); |
| 139 |
|