Button in a layout to open another layout
AnsweredHello,
How to create a simple button to insert in a layout to open another layout?
I saw on Youtube that it was possible with an html button but the YouTuber does not want to share his source code.
I don't yet understand the Nx API but what is the easiest way to do this?
I looked at several posts on this forum but couldn't find any answers.
Thanks in advance
-
Hello,
It's in this video https://www.youtube.com/watch?v=pZPellijnUw&t=252s
The button where it says "Access Bat A" is an html page and when clicked on it, another layout opens.
Thank you -
Hi,
The approach is the following.
1. Create a layout to be opened.
2. Create an Event Rule
When: Generic Event
Either "Source contains", or "Caption contains" or "Description contains" having a pattern to identify and distinguish the layout to be opened.
Action: Open layout
Click "Layout" and select layout to be opened.
3. In the JS code of the web page invoke the /api/createEvent Server API with the "caption" parameter set to "Camera".
-
Hi Andrey Terentyev
Thank you for your precious help,
I created the rule but I can't make js code that works :/
Do you have an example?
Thank you -
Hi,
Generally, for invoking Server REST API you need to authenticate.
In JS API there is no need to do that, because GUI client works with already authenticated user creds.
In version 5.1, for getting auth token use Auth API
Authentication API
This section contains specification for the authentication API.
vms.auth object
Contains methods to retrieve authentication data.
Method
async sessionToken()
Returns a user session token or empty string if it is inaccessible (e.g. the user prohibited token transfer).
Could be used to authorize the rest api calls to the currently connected system.
If the cloud user is not part of the system OR if system is not connected a cloud at all, local bearer token will be returned.
Method
async cloudToken()
Returns a cloud refresh token or empty string if it is inaccessible (e.g. the user prohibited token transfer).
This token can be used to obtain an access token (using cloud) with the specified scope.
Returns the token even if the Cloud user is not part of the currently connected system(local user login).
Returns nothing with no error message if Client is not logged into the cloud.
Method
async cloudSystemId()
Returns the cloud system id or empty string if the system is not connected to cloud.
Method
async cloudHost()
Returns the cloud host.
Example
const token = await window.vms.auth.sessionToken();
Code examples are found in js_api_example of nx_open_integrations repo on GitHub.
Once the token is retrieved, you can invoke Server APIs
https://meta.nxvms.com/doc/developers/api-tool/main?type=1&system=4
Code example, although a bit outdated, can be found in node_js/src/mediaserverApi.ts. What needs to be refactored is updating the MediaserverApi class with token auth schema support.
-
I tried this JS code but it is probably wrong or incomplete
<script>
function sendRequest() {
$.ajax({
url: 'https://192.168.1.138:7001/api/createEvent',
type: 'post',
data: JSON.stringify({ caption: nereides }),
headers: { 'Content-Type': 'application/json' },
dataType: 'json',
success: function (data) {
console.log(data);
}
});
}
</script>If in JS there is no need to authenticate I prefer to use this method but I don't know how to form the code.
Do you have a simple example of JS code?Thank you
-
I modified the code:
<script>
function sendRequest() {
const boutonValue = 'CARTE';
const requestData = { caption: boutonValue };fetch('https://srvnx:7001/api/createEvent', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
})
.then(response => {
if (response.status !== 200) {
console.error('Erreur de statut HTTP :', response.status);
return;
}
return response.json(); // Parse la réponse JSON
})
.then(data => {
if (data) {
console.log(data);
} else {
console.error('Réponse vide ou non valide.');
}
})
.catch(error => {
console.error('Erreur lors de la requête :', error.message);
});
}
</script>and I get the error
POST https://srvnx:7001/api/createEvent 401 (Unauthorized)
Please sign in to leave a comment.
Comments
8 comments