/* Javascript for the manufacturers page */
// https://www.site24x7.com/tools/javascript-validator.html
/* GLOBAL CONSTANTS */
/* GLOBAL VARIABLES */
/* FUNCTIONS */
var zz = console.log; // I'm tired of typing "console.log" over and over during testing
// *** We received the data from the components table, asynchronously
function manufDataReceived( xmlHttpRequest) {
console.log('manufDataReceived');
const NoOfCellsInARow = 3;
// Store the fields definitions <<<40~50 ms>>>
// Need to detect if the responseText is an error and put it to the console <<<
var tableData = JSON.parse(xmlHttpRequest.responseText);
var mainTableHTML = '';
var manufData = tableData[1]; // Get just the data
for (var manufData of manufData) {
// Manufacturer
var manufName = manufData[0];
var manufURL = manufData[1];
manufLink = manufName;
if (manufURL != '') {
manufLink = '' + manufName + '';
}
mainTableHTML += '
' + manufLink;
// Types of connectors
var nodeCodeList = manufData[2];
var manufTableHTML = '';
if (nodeCodeList != '') {
var tdInRow = 0; // Number of table cells in a row
nodeCodeList = nodeCodeList.split(',');
for (var nodeCode of nodeCodeList) {
var nodeName = nodeCode.replaceAll ('_',' ');
if (tdInRow == 0) {
manufTableHTML += ' |
';
}
tdInRow++;
if (tdInRow == NoOfCellsInARow) {
tdInRow = 0;
}
manufTableHTML += '' + nodeName + ' ';
}
manufTableHTML = '';
}
mainTableHTML += ' | ' + manufTableHTML;
}
manufTable.innerHTML = mainTableHTML;
} // manufDataReceived
// *** Initialize
// Called only once at init
function init( ) {
console.log('init');
// Get the components table
var dbURL = 'cgi-bin/getManufacturers.py';
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("GET",dbURL,true);
xmlHttpRequest.send();
// Later, after the database loads, execute this function
xmlHttpRequest.onreadystatechange = function() {
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status === 200) {
manufDataReceived(xmlHttpRequest);
}
};
// Show the list of components
manufTable.innerHTML = 'Loading';
}
// Initialize
init();
|