web: add functio to clear part details

This commit is contained in:
King Kévin 2023-01-26 05:44:11 +01:00
parent 6286fc708a
commit d95d527d5a
1 changed files with 29 additions and 3 deletions

View File

@ -4,6 +4,10 @@
var last_search = null; var last_search = null;
// the collection of parts // the collection of parts
var parts = null; var parts = null;
// part field to populate
const fields = ["name", "description", "details", "package", "pincount", "manufacturer", "family", "datasheet", "page", "location", "stock"];
// URLs to set
const urls = ["page","datasheet"];
function search() function search()
{ {
@ -40,6 +44,30 @@ function results()
} }
} }
function clear()
{
// clear part fields
for (const field of fields) {
const input = document.getElementById('part_' + field);
if (input.tagName == "INPUT") {
input.value = "";
} else if (input.tagName == "TEXTAREA") {
input.innerHTML = null;
}
}
// clear URLs
for (const field of urls) {
const a = document.getElementById('url_' + field);
a.href = null;
}
// clear distributors
const distributors = document.getElementById('distributors');
distributors.innerHTML = null;
// clear properties
const properties = document.getElementById('properties');
properties.innerHTML = null;
}
function select() function select()
{ {
const results = document.getElementById('results'); const results = document.getElementById('results');
@ -49,7 +77,6 @@ function select()
if (part.id == part_selected) { if (part.id == part_selected) {
console.log(part); console.log(part);
// populate part fields // populate part fields
const fields = ["name", "description", "details", "package", "pincount", "manufacturer", "family", "datasheet", "page", "location", "stock"];
for (const field of fields) { for (const field of fields) {
const input = document.getElementById('part_' + field); const input = document.getElementById('part_' + field);
if (input.tagName == "INPUT") { if (input.tagName == "INPUT") {
@ -67,7 +94,6 @@ function select()
} }
} }
// set URLs // set URLs
const urls = ["page","datasheet"];
for (const field of urls) { for (const field of urls) {
const a = document.getElementById('url_' + field); const a = document.getElementById('url_' + field);
if (null == a) { if (null == a) {
@ -157,11 +183,11 @@ function delete_part()
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('GET', '/delete/' + part_selected, true); xhr.open('GET', '/delete/' + part_selected, true);
xhr.onload = function() { xhr.onload = function() {
clear();
search(); // refresh search search(); // refresh search
}; };
xhr.onerror = function() { xhr.onerror = function() {
console.log("delete part failed"); console.log("delete part failed");
}; };
xhr.send(); xhr.send();
} }