From 8be07a291c14eb9e3b1a033244803f339cafbcc6 Mon Sep 17 00:00:00 2001 From: adrien Date: Sun, 26 Sep 2021 22:49:52 +0200 Subject: [PATCH] update host fix --- css/style.css | 2 +- js/script.js | 39 ++++++++++++++++++++++++--------------- network.php | 13 ++++++++----- updateHost.php | 17 +++++++++++------ 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/css/style.css b/css/style.css index 949b568..fff88b7 100644 --- a/css/style.css +++ b/css/style.css @@ -3,7 +3,7 @@ padding: 0; } -.td-input input[type="text"]:not(.browser-default) { +.td-input input:not(.browser-default) { margin: 0; } diff --git a/js/script.js b/js/script.js index 3f44238..36581cb 100644 --- a/js/script.js +++ b/js/script.js @@ -5,19 +5,28 @@ function showCard(card, button) { } function updateHost(input) { - input.parentElement.classList.remove("ok") - input.parentElement.classList.remove("nok") - input.parentElement.classList.add("pending") - fetch(new Request("updateHost.php", { - method:"POST", - body:new FormData(input.form), - mode:"cors" - })).then(response => { - input.parentElement.classList.remove("pending") - if (response.ok) { - input.parentElement.classList.add("ok") - } else { - input.parentElement.classList.add("nok") - } - }) + if (input.form.checkValidity()) { + var td = input.parentElement + var tr = td.parentElement + tr.classList.remove("ok") + tr.classList.remove("nok") + tr.classList.add("pending") + fetch(new Request("updateHost.php", { + method:"POST", + body:new FormData(input.form), + mode:"cors" + })).then(response => { + tr.classList.remove("pending") + if (response.ok) { + tr.classList.add("ok") + var linkInput = tr.getElementsByTagName('input')[7] + var linkA = tr.getElementsByTagName('a')[0] + linkA.href = linkInput.value + } else { + tr.classList.add("nok") + } + }) + } else { + input.form.reportValidity() + } } \ No newline at end of file diff --git a/network.php b/network.php index f3121bb..18b450c 100644 --- a/network.php +++ b/network.php @@ -52,12 +52,13 @@ if (!$siteName) { FQDN Adresse MAC Commentaires + Lien - + "/> - "/> - "/> - "/> - "/> + "/> + "/> + "/> + "/> + "/> + " target="_blank">launch prepare(" - INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Comments) - VALUES($ip, $networkId, :i_hostname, :i_fqdn, :i_macAddress, :i_comments) - ON DUPLICATE KEY UPDATE Hostname = :u_hostname, FQDN = :u_fqdn, MacAddress = :u_macAddress, Comments = :u_comments + INSERT INTO Hosts(IpAddress, NetworkId, Hostname, FQDN, MacAddress, Link, Comments) + VALUES($ip, $networkId, :i_hostname, :i_fqdn, :i_macAddress, :i_link, :i_comments) + ON DUPLICATE KEY UPDATE Hostname = :u_hostname, FQDN = :u_fqdn, MacAddress = :u_macAddress, Comments = :u_comments, Link = :u_link "); $update->execute([ 'i_hostname' => $hostname, 'i_fqdn' => $fqdn, 'i_macAddress' => $macAddress, + 'i_link' => $link, 'i_comments' => $comments, 'u_hostname' => $hostname, 'u_fqdn' => $fqdn, 'u_macAddress' => $macAddress, + 'u_link' => $link, 'u_comments' => $comments ]); } catch(Exception $e) {