diff --git a/views/js/main.js b/views/js/main.js index b0cb09c..6c83ca4 100644 --- a/views/js/main.js +++ b/views/js/main.js @@ -15,6 +15,13 @@ function tabs() { elm.classList.remove("selected"); } child.classList.add("selected"); + + for (const childElm of child.parentElement.children) { + if (childElm.classList.contains("selected")) { + childElm.classList.remove("selected") + } + } + document.querySelector(`.tabs .content[data-tab="${ child.getAttribute("data-tab") }"]`)?.classList.add("selected"); @@ -41,6 +48,55 @@ function tabs() { } } + for (const elm of document.querySelectorAll(".tabs-header")) { + let count = 0; + let selected = 0; + for (const child of elm.children[0].children) { + if (child.tagName == "BUTTON") { + count++; + if (child.classList.contains("selected")) { + selected++; + } + if (!child.getAttribute("data-armed")) { + child.addEventListener("click", () => { + if (!child.classList.contains("selected")) { + for (const elm of child.parentElement.children) { + elm.classList.remove("selected"); + } + child.classList.add("selected"); + + for (const childElm of child.parentElement.parentElement.children) { + if (childElm.classList.contains("selected")) { + childElm.classList.remove("selected") + } + } + + document.querySelector(`.tabs-header .content[data-tab="${ + child.getAttribute("data-tab") + }"]`)?.classList.add("selected"); + } + }); + child.setAttribute("data-armed", "true") + } + } + } + + if (selected > 1 || selected == 0) { + for (const child of elm.children) { + child.classList.remove("selected"); + } + for (const child of elm.children[0].children) { + if (child.tagName == "BUTTON") { + child.classList.add("selected"); + document.querySelector(`.tabs .content[data-tab="${ + child.getAttribute("data-tab") + }"]`)?.classList.add("selected"); + break; + } + } + + } + } } function load() { for (const elm of document.querySelectorAll("form > button")) { diff --git a/views/models/edit.html b/views/models/edit.html index f31134e..f55b26e 100644 --- a/views/models/edit.html +++ b/views/models/edit.html @@ -126,30 +126,40 @@ {{ if eq (len .Classes) 0 }} TODO CREATE TABLE {{else}} -