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.
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
Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
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]
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:
Upload Files button:
[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:
Upload Files button:
You do not have the required permissions to view the files attached to this post.
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
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:
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');
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
***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:
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?
How to fix this?***
Adding this:
Code: Select all
nuVendorLogin('TFM');
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.
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
It constructs the Audio url again even though I have switched to the Video tab. What am I missing here?
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
// See corrected code in previous post.
-
- 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
ChatGPT said (untested):
Problem
You are using which opens a new window with .
Then, your code also calls again to open Tiny File Manager, resulting in two separate tabs.
Goal
Make only one window open.
Reuse the same window opened by and update its URL instead of opening a new one.
Solution
Step 1. Modify to return the window handle
Step 2. Open and then redirect the same window
Problem
You are using
Code: Select all
nuVendorLogin('TFM')
Code: Select all
window.open()
Then, your code also calls
Code: Select all
window.open()
Goal
Make only one window open.
Reuse the same window opened by
Code: Select all
nuVendorLogin()
Solution
Step 1. Modify
Code: Select all
nuVendorLogin()
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
}
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;
}
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
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:
Not sure where the :1 came from.
"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)
-
- 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
Try Replacing:
With
This adds a small delay to give TFM time to complete before redirect.
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 }
Re: Navigate to appropriate folder in TFM when globeadmin clicks on 'Upload Files' button
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:
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 }
-
- 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
Did you ask AI to fix it?