Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

I'd like to have file manager go to the corresponding upload folder when 'Upload Files' button is clicked based on the Record_ID and the Tab that globeadmin is currently on. For example, if I am on the Edit form of Record_ID number 12 (a.k.a Case number) on the Audio tab,
case-no-record-id.PNG
[case-no-record-id.PNG]

and I click on the 'Upload Files' button, I want the user to go to this folder in the upload file structure: '/ Case 12 / Evidence / Audio' location on the server.

Folders:
case12-evidence-audio.PNG

Upload Files button:
file-manager.PNG
You do not have the required permissions to view the files attached to this post.
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

I tried putting this code in the javascript onclick event, but got "Uncaught ReferenceError: tab is not defined" when clicking on the button.

Here is the code:

Code: Select all

// Get the current tab and record number
var tabName = '#tab.id#';

// Use the strict equality operator (===) for comparison
if (tab.id === 'nuTab5') {
  var tablabel = 'Audio';
} else if (tab.id === 'nuTab6') {
  var tablabel = 'Video';
} else if (tab.id === 'nuTab7') {
  var tablabel = 'Photo';
}

var recordNumber = '#RECORD_ID#';

// Construct the file path dynamically.
var path = 'case ' + recordNumber + '/' + 'Evidence' + '/' + tablabel;

// Construct the full URL
var fileManagerUrl = '/tinyfilemanager.php?p=' + path;

// Use JavaScript to open the URL in a new tab
window.open(fileManagerUrl, '_blank');
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

***This code only works if there is an active Tiny File Manager session. If the session has expired, we are taken to the base level URL.
How to fix this?***

Adding this:

Code: Select all

nuVendorLogin('TFM');
to the beginning of the code works, but it opens two TFM tabs: one for the desired destination url and the other at the base url for the session.
Is there a way to have it first check to see if there is an active TFM session, then based on the result, open a new session if needed, or just use the current session?


Code: Select all

// Get the current tab and record number

var tab_id = nuSelectedTabId(); 

var tablabel = '';

if (tab_id === '68ca2d0c176d4d4') {
  tablabel = 'Audio';
} else if (tab_id === '68e16015b8742d6') {
  tablabel = 'Video';
} else if (tab_id === '68e16037843edff') {
  tablabel = 'Photo';
}

var recordNumber = (nuRecordId());

// Construct the file path dynamically.
var path = '/' + 'nubuilder2' + '/' + 'third_party' + '/' + 'tinyfilemanager' + '/';

// Construct the full URL
var fileManagerUrl = path + 'tinyfilemanager.php?p=' + 'Case+' + recordNumber + '/' + 'Evidence' + '/' + tablabel;

// Use JavaScript to open the URL in a new tab
window.open(fileManagerUrl, '_blank');
Last edited by Paul on Sun Oct 05, 2025 8:50 pm, edited 5 times in total.
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

It constructs the Audio url again even though I have switched to the Video tab. What am I missing here?
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

// See corrected code in previous post.
kev1n
nuBuilder Team
Posts: 4580
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 535 times
Contact:

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by kev1n »

ChatGPT said (untested):

Problem
You are using

Code: Select all

nuVendorLogin('TFM')
which opens a new window with

Code: Select all

window.open()
.
Then, your code also calls

Code: Select all

window.open()
again to open Tiny File Manager, resulting in two separate tabs.

Goal
Make only one window open.
Reuse the same window opened by

Code: Select all

nuVendorLogin()
and update its URL instead of opening a new one.

Solution

Step 1. Modify

Code: Select all

nuVendorLogin()
to return the window handle

Code: Select all

function nuVendorLogin(appId, table) {

	const tableName = table || nuSERVERRESPONSE.table;
	const params = new URLSearchParams({
		sessid: window.nuSESSION,
		appId: appId,
		table: tableName,
		timezone: nuSERVERRESPONSE.timezone
	});

	const url = `core/nuvendorlogin.php?${params.toString()}`;
	return window.open(url, appId); // use appId as window name for reuse
}
Step 2. Open and then redirect the same window

Code: Select all

// 1. Open TFM via nuVendorLogin()
var win = nuVendorLogin('TFM');

// 2. Build the Tiny File Manager URL
// Get the current tab and record number

var tab_id = nuSelectedTabId(); 

var tablabel = '';

if (tab_id === '68ca2d0c176d4d4') {
  tablabel = 'Audio';
} else if (tab_id === '68e16015b8742d6') {
  tablabel = 'Video';
} else if (tab_id === '68e16037843edff') {
  tablabel = 'Photo';
}

var recordNumber = (nuRecordId());

// Construct the file path dynamically.
var path = '/' + 'nubuilder2' + '/' + 'third_party' + '/' + 'tinyfilemanager' + '/';

// Construct the full URL
var fileManagerUrl = path + 'tinyfilemanager.php?p=' + 'Case+' + recordNumber + '/' + 'Evidence' + '/' + tablabel;


// 3. Once the vendor login window is created, change its location
if (win) {
   win.location.href = fileManagerUrl;
}
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

I added the two blocks of code you provided, but when I click the button, I get a blank, white page except for:
"Tiny File Manager: Session Expired" at the top left.

Chrome console says:

Code: Select all

tinyfilemanager.php?p=Case%2012/Evidence/Audio:1  Failed to load resource: the server responded with a status of 400 (Bad Request)
Not sure where the :1 came from.
kev1n
nuBuilder Team
Posts: 4580
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 535 times
Contact:

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by kev1n »

Try Replacing:

Code: Select all


 if (win) { win.location.href = fileManagerUrl; } 


With

Code: Select all

 if (win) { setTimeout(() => { win.location.href = fileManagerUrl; }, 1000); // wait 1 second or adjust } 
This adds a small delay to give TFM time to complete before redirect.
Paul
Posts: 133
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 29 times
Been thanked: 3 times

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by Paul »

Still not working:

Javascript Error: Uncaught SyntaxError: Unexpected end of input

Console: nubuilder2/?f=68c452e608cbadc&r=12:43 Uncaught SyntaxError: Unexpected end of input

Here is the code for the button onlclick event:

Code: Select all

function nuVendorLogin(appId, table) {

	const tableName = table || nuSERVERRESPONSE.table;
	const params = new URLSearchParams({
		sessid: window.nuSESSION,
		appId: appId,
		table: tableName,
		timezone: nuSERVERRESPONSE.timezone
	});

	const url = `core/nuvendorlogin.php?${params.toString()}`;
	return window.open(url, appId); // use appId as window name for reuse

}

// 1. Open TFM via nuVendorLogin()
var win = nuVendorLogin('TFM');

// 2. Build the Tiny File Manager URL
// Get the current tab and record number

var tab_id = nuSelectedTabId(); 

var tablabel = '';

if (tab_id === '68ca2d0c176d4d4') {
  tablabel = 'Audio';
} else if (tab_id === '68e16015b8742d6') {
  tablabel = 'Video';
} else if (tab_id === '68e16037843edff') {
  tablabel = 'Photo';
}

var recordNumber = (nuRecordId());

// Construct the file path dynamically.
var path = '/' + 'nubuilder2' + '/' + 'third_party' + '/' + 'tinyfilemanager' + '/';

// Construct the full URL
var fileManagerUrl = path + 'tinyfilemanager.php?p=' + 'Case ' + recordNumber + '/' + 'Evidence' + '/' + tablabel;

// 3. Once the vendor login window is created, change its location
if (win) { setTimeout(() => { win.location.href = fileManagerUrl; }, 1000); // wait 1 second or adjust } 
kev1n
nuBuilder Team
Posts: 4580
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 76 times
Been thanked: 535 times
Contact:

Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button

Unread post by kev1n »

Did you ask AI to fix it?
Post Reply