Page 1 of 1
Make a URL a clickable link - Error as Globeadmin
Posted: Thu Oct 09, 2025 6:56 pm
by Paul
The code for 'Make a URL a clickable link' works fine for non-admin users, but not so well for globeadmin.
Here is what Globeadmin sees when logging in:
Globeadmin-Browse-form.PNG
When globeadmin clicks on the Back button, then clicks on the button to open the Browse form again, the aforesaid error appears:
Code: Select all
Uncaught SyntaxError: Failed to execute 'appendChild' on 'Node': Identifier 'hyperlinkColumns' has already been declared
at m (jquery-3.7.1.min.js:2:880)
at $e (jquery-3.7.1.min.js:2:46274)
at ce.fn.init.append (jquery-3.7.1.min.js:2:47633)
at nuAddJavaScript (nuform.js?ts=20251009185246:6294:12)
at nuBuildForm (nuform.js?ts=20251009185246:144:3)
at Object.successCallback (nuajax.js?ts=20251009185246:193:4)
at c (jquery-3.7.1.min.js:2:25304)
at Object.fireWith [as resolveWith] (jquery-3.7.1.min.js:2:26053)
at l (jquery-3.7.1.min.js:2:77782)
at XMLHttpRequest.<anonymous> (jquery-3.7.1.min.js:2:80265)
Re: Make a URL a clickable link - Error as Globeadmin
Posted: Thu Oct 09, 2025 6:59 pm
by Paul
For reference, here is the Browse form code:
Code: Select all
// ==============================
// Hide specific columns normally,
// but show them during nuPrint().
// ==============================
// Columns with hyperlinks (replace with correct column indexes!)
const hyperlinkColumns = [4, 5, 6]; // example: 1=audio, 2=video, 3=photo
// Function to hide columns
function hideColumns(cols) {
cols.forEach(i => nuSetBrowseColumnSize(i, 0));
}
// Function to show columns (auto size)
function showColumns(cols) {
cols.forEach(i => nuSetBrowseColumnSize(i, 'auto'));
}
// Hide columns by default (non-admins only)
if (!nuGlobalAccess()) {
hideColumns(hyperlinkColumns);
}
// ==============================
// Hook into nuPrint()
// ==============================
(function() {
// Keep a reference to the original nuPrint
const originalNuPrint = window.nuPrint;
window.nuPrint = function() {
// Before print: show the hyperlink columns
showColumns(hyperlinkColumns);
// Call the original nuPrint function
originalNuPrint();
// After short delay, re-hide the columns (so Browse view looks normal again)
setTimeout(() => {
if (!nuGlobalAccess()) hideColumns(hyperlinkColumns);
}, 2000);
};
})();
// ==============================
// Your existing blank column logic
// ==============================
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
}
{
const hiddenColumns = hideBlankColumns();
if (!nuGlobalAccess()) var columnIndex = 0;
const columnsToExclude = [...new Set([columnIndex, ...hiddenColumns])];
nuPrintExcludeColumns(columnsToExclude);
}
function hideBlankColumns() {
const hiddenColumns = [];
const browseDiv = document.getElementById('nuRECORD');
if (!browseDiv) return hiddenColumns;
const headers = browseDiv.querySelectorAll('.nuBrowseTitle');
if (headers.length === 0) return hiddenColumns;
const colCount = headers.length;
const isColumnBlank = new Array(colCount).fill(true);
const dataCells = browseDiv.querySelectorAll('.nuCell[data-nu-column]');
dataCells.forEach(cell => {
const colIndex = parseInt(cell.getAttribute('data-nu-column'));
const content = cell.textContent.trim();
if (content !== '' && colIndex >= 0) isColumnBlank[colIndex] = false;
});
for (let j = 0; j < colCount; j++) {
if (isColumnBlank[j]) {
nuSetBrowseColumnSize(j, 0);
hiddenColumns.push(j);
}
}
return hiddenColumns;
}
Re: Make a URL a clickable link - Error as Globeadmin
Posted: Thu Oct 09, 2025 7:31 pm
by Paul
Here is the corrected code (thank you ChatGPT),
making sure that it only runs once:
Code: Select all
// Prevent duplicate initialization
if (!window.hyperlinkColumnsInitialized) {
window.hyperlinkColumnsInitialized = true;
// ==============================
// Hide specific columns normally,
// but show them during nuPrint().
// ==============================
const hyperlinkColumns = [4, 5, 6]; // example: 1=audio, 2=video, 3=photo
// Function to hide columns
function hideColumns(cols) {
cols.forEach(i => nuSetBrowseColumnSize(i, 0));
}
// Function to show columns (auto size)
function showColumns(cols) {
cols.forEach(i => nuSetBrowseColumnSize(i, 'auto'));
}
// Hide columns by default (non-admins only)
if (!nuGlobalAccess()) {
hideColumns(hyperlinkColumns);
}
// ==============================
// Hook into nuPrint()
// ==============================
(function() {
// Prevent re-wrapping nuPrint multiple times
if (!window.nuPrintWrapped) {
window.nuPrintWrapped = true;
const originalNuPrint = window.nuPrint;
window.nuPrint = function() {
// Before print: show hyperlink columns
showColumns(hyperlinkColumns);
// Call the original print
originalNuPrint();
// Re-hide columns after delay
setTimeout(() => {
if (!nuGlobalAccess()) hideColumns(hyperlinkColumns);
}, 2000);
};
}
})();
// ==============================
// Your existing blank column logic
// ==============================
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
}
{
const hiddenColumns = hideBlankColumns();
if (!nuGlobalAccess()) var columnIndex = 0;
const columnsToExclude = [...new Set([columnIndex, ...hiddenColumns])];
nuPrintExcludeColumns(columnsToExclude);
}
function hideBlankColumns() {
const hiddenColumns = [];
const browseDiv = document.getElementById('nuRECORD');
if (!browseDiv) return hiddenColumns;
const headers = browseDiv.querySelectorAll('.nuBrowseTitle');
if (headers.length === 0) return hiddenColumns;
const colCount = headers.length;
const isColumnBlank = new Array(colCount).fill(true);
const dataCells = browseDiv.querySelectorAll('.nuCell[data-nu-column]');
dataCells.forEach(cell => {
const colIndex = parseInt(cell.getAttribute('data-nu-column'));
const content = cell.textContent.trim();
if (content !== '' && colIndex >= 0) isColumnBlank[colIndex] = false;
});
for (let j = 0; j < colCount; j++) {
if (isColumnBlank[j]) {
nuSetBrowseColumnSize(j, 0);
hiddenColumns.push(j);
}
}
return hiddenColumns;
}
}