From 658ba092e2157f3f889b9e839836b20625045d62 Mon Sep 17 00:00:00 2001 From: MrM <11910225+mauro-miatello@users.noreply.github.com> Date: Sun, 31 Mar 2024 18:55:58 +0200 Subject: [PATCH] Hide encrypted values in hardware list Encrypted values are now hidden also in hardware list, clicking on them show the decrypted value --- resources/views/layouts/default.blade.php | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 216632ccf..03442bd0b 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -1041,6 +1041,64 @@ }); }); + // Select encrypted custom fields to hide them in the asset list + $(document).ready(function() { + // Selector for elements with css-padlock class + var selector = 'td.css-padlock'; + + // Function to add original value to elements + function addValue($element) { + // Get original value of the element + var originalValue = $element.text().trim(); + + // Show asterisks only for not empty values + if (originalValue !== '') { + // This is necessary to avoid loop because value is generated dynamically + if (originalValue !== '' && originalValue !== asterisks) $element.attr('value', originalValue); + + // Hide the original value and show asterisks of the same length + var asterisks = '*'.repeat(originalValue.length); + $element.text(asterisks); + + // Add click event to show original text + $element.click(function() { + var $this = $(this); + if ($this.text().trim() === asterisks) { + $this.text($this.attr('value')); + } else { + $this.text(asterisks); + } + }); + } + } + // Add value to existing elements + $(selector).each(function() { + addValue($(this)); + }); + + // Function to handle mutations in the DOM because content is generated dynamically + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + // Check if new nodes have been inserted + if (mutation.type === 'childList') { + mutation.addedNodes.forEach(function(node) { + if ($(node).is(selector)) { + addValue($(node)); + } else { + $(node).find(selector).each(function() { + addValue($(this)); + }); + } + }); + } + }); + }); + + // Configure the observer to observe changes in the DOM + var config = { childList: true, subtree: true }; + observer.observe(document.body, config); + }); +