web: add functio to clear part details
This commit is contained in:
parent
6286fc708a
commit
d95d527d5a
|
@ -4,6 +4,10 @@
|
|||
var last_search = null;
|
||||
// the collection of parts
|
||||
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()
|
||||
{
|
||||
|
@ -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()
|
||||
{
|
||||
const results = document.getElementById('results');
|
||||
|
@ -49,7 +77,6 @@ function select()
|
|||
if (part.id == part_selected) {
|
||||
console.log(part);
|
||||
// populate part fields
|
||||
const fields = ["name", "description", "details", "package", "pincount", "manufacturer", "family", "datasheet", "page", "location", "stock"];
|
||||
for (const field of fields) {
|
||||
const input = document.getElementById('part_' + field);
|
||||
if (input.tagName == "INPUT") {
|
||||
|
@ -67,7 +94,6 @@ function select()
|
|||
}
|
||||
}
|
||||
// set URLs
|
||||
const urls = ["page","datasheet"];
|
||||
for (const field of urls) {
|
||||
const a = document.getElementById('url_' + field);
|
||||
if (null == a) {
|
||||
|
@ -157,11 +183,11 @@ function delete_part()
|
|||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', '/delete/' + part_selected, true);
|
||||
xhr.onload = function() {
|
||||
clear();
|
||||
search(); // refresh search
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
console.log("delete part failed");
|
||||
};
|
||||
xhr.send();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue