diff --git a/internal/server/static/order.js b/internal/server/static/order.js new file mode 100644 index 0000000..7f8100f --- /dev/null +++ b/internal/server/static/order.js @@ -0,0 +1,33 @@ +function addCake(id, name, amount) { + let template = document.getElementById("basket_element_template"); + let tr = template.content.cloneNode(true); + console.log(tr); + const cake = document.getElementById("cake[" + id + "]"); + if (cake != null) { + const value = Number(cake.getAttribute("value")); + cake.setAttribute("value", value + 1); + return; + } + const label = document.createElement("label"); + label.innerText = name; + const input = document.createElement("input"); + input.setAttribute("id", "cake[" + id + "]"); + input.setAttribute("type", "number"); + input.setAttribute("min", "0"); + input.setAttribute("name", "cake[" + id + "]"); + input.setAttribute("value", amount); + const button = document.createElement("button"); + button.setAttribute("type", "button"); + button.setAttribute("onClick", "removeCake(" + id + ")"); + button.innerText = "usuń"; + const li = document.createElement("li"); + li.appendChild(label); + li.appendChild(input); + li.appendChild(button); + li.setAttribute("id", "li[" + id + "]"); + const ul = document.getElementById("basket"); + ul.appendChild(li); +} +function removeCake(id) { + document.getElementById("li[" + id + "]").remove(); +} diff --git a/internal/server/templates/layout/layout.gohtml b/internal/server/templates/layout/layout.gohtml index aafcb17..9912d89 100644 --- a/internal/server/templates/layout/layout.gohtml +++ b/internal/server/templates/layout/layout.gohtml @@ -6,6 +6,7 @@ {{template "title" .}} + diff --git a/internal/server/templates/order.gohtml b/internal/server/templates/order.gohtml index fcddef8..ec0d54a 100644 --- a/internal/server/templates/order.gohtml +++ b/internal/server/templates/order.gohtml @@ -93,41 +93,6 @@