Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated script.js: Clicking a row in the registry will load the form #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions mopidy_pummeluff/webui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const requestApi = (endpoint, data) => {
}

/**
* Refresh the registry.
* Refresh the action classes.
*/

const refreshActionClasses = () => {
Expand Down Expand Up @@ -113,7 +113,7 @@ const submitForm = event => {
document.getElementById('uid').value = ''
document.getElementById('alias').value = ''
document.getElementById('parameter').value = ''
document.getElementById('action').selectIndex = 0
document.getElementById('action').selectedIndex = 0

refreshRegistry()
})
Expand All @@ -124,12 +124,32 @@ const submitForm = event => {
*/

document.addEventListener('DOMContentLoaded', () => {
refreshActionClasses()
refreshRegistry()

const readTagInterval = 1000
readTag()
setInterval(readTag, readTagInterval)

document.querySelector('form').addEventListener('submit', submitForm)
})
refreshActionClasses();
refreshRegistry();

const readTagInterval = 1000;
readTag();
setInterval(readTag, readTagInterval);

document.querySelector('form').addEventListener('submit', submitForm);

// Add event listener to the tbody for click events
document.querySelector('#tags tbody').addEventListener('click', (event) => {
// Check if the clicked element or its parent is a tr
const clickedRow = event.target.closest('tr');
if (clickedRow) {
// Extract data from the clicked row
const cells = clickedRow.querySelectorAll('td');
const uid = cells[1].textContent;
const alias = cells[0].textContent;
const action = cells[2].textContent;
const parameter = cells[3].textContent;

// Populate form fields with the extracted data
document.getElementById('uid').value = uid;
document.getElementById('alias').value = alias;
document.getElementById('action').value = action;
document.getElementById('parameter').value = parameter;
}
});
});