Refactor handler to server package
This commit is contained in:
parent
fb97ba20c0
commit
ca4e448f82
9 changed files with 215 additions and 189 deletions
36
server/templates/index.html
Normal file
36
server/templates/index.html
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<header>
|
||||
<h1>Kill me please</h1>
|
||||
</header>
|
||||
<nav>
|
||||
<a href="order">New</a>
|
||||
</nav>
|
||||
<main>
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Surname</th>
|
||||
<th>Phone</th>
|
||||
<th>Location</th>
|
||||
<th>Date</th>
|
||||
<th>Accepted</th>
|
||||
<th>Status</th>
|
||||
<th>Paid</th>
|
||||
<th>Cakes</th>
|
||||
</tr>
|
||||
{{range .}}
|
||||
<tr>
|
||||
<th><a href="/order/{{.ID}}">edit</a></th>
|
||||
<th>{{.Name}}</th>
|
||||
<th>{{.Surname}}</th>
|
||||
<th>{{.Phone}}</th>
|
||||
<th>{{.Location}}</th>
|
||||
<th>{{.Date.Format "2006-01-02"}}</th>
|
||||
<th>{{.Accepted.Format "2006-01-02"}}</th>
|
||||
<th>{{.Status}}</th>
|
||||
<th>{{.Paid}}</th>
|
||||
<th>{{range .Cakes}} {{.Name}} {{.Amount}} {{end}}</th>
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
</main>
|
||||
91
server/templates/order.html
Normal file
91
server/templates/order.html
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<header>
|
||||
<h1>New Order</h1>
|
||||
</header>
|
||||
<nav>
|
||||
<a href="/">back</a>
|
||||
</nav>
|
||||
<main>
|
||||
<form method="post">
|
||||
{{with .Order}}
|
||||
<div>
|
||||
<h2>Info</h2>
|
||||
<input hidden="true" name="id" value="{{.ID}}">
|
||||
<label>name</label>
|
||||
<input type="text" name="name" value="{{.Name}}">
|
||||
<label>surname</label>
|
||||
<input type="text" name="surname" value="{{.Surname}}">
|
||||
<label>phone</label>
|
||||
<input type="tel" name="phone" value="{{.Phone}}">
|
||||
<label>location</label>
|
||||
<select name="location">
|
||||
<option value="Kartuzy">Kartuzy</option>
|
||||
<option value="Somonino">Somonino</option>
|
||||
</select>
|
||||
<label>date</label>
|
||||
<input type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
|
||||
<label>status</label>
|
||||
<select name="status" id="status">
|
||||
<option value="accepted">accepted</option>
|
||||
<option value="done">done</option>
|
||||
</select>
|
||||
<label>paid</label>
|
||||
<input type="number" name="paid" min="0" value="{{.Paid}}">
|
||||
</div>
|
||||
<div>
|
||||
<h2>Basket</h2>
|
||||
<ul id="basket">
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
{{with .Catalogue}}
|
||||
<div>
|
||||
<h2>Catalogue</h2>
|
||||
<ul>
|
||||
{{range .}}
|
||||
<li>
|
||||
{{.Name}} {{.Price}} <button type=button onClick="addCake({{.ID}},'{{.Name}} {{.Price}}', 1)">add</button>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
<button type="submit">submit</button>
|
||||
</form>
|
||||
</main>
|
||||
<script>
|
||||
function addCake(id, name, amount){
|
||||
var cake = document.getElementById("cake["+id+"]")
|
||||
if (cake != null){
|
||||
var value = Number(cake.getAttribute("value"))
|
||||
cake.setAttribute("value", value+1)
|
||||
return;
|
||||
}
|
||||
var label = document.createElement("label")
|
||||
label.innerText = name
|
||||
var 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)
|
||||
var button = document.createElement("button")
|
||||
button.setAttribute("type", "button")
|
||||
button.setAttribute("onClick", "removeCake("+id+")")
|
||||
button.innerText= "delete"
|
||||
var li = document.createElement("li")
|
||||
li.appendChild(label)
|
||||
li.appendChild(input)
|
||||
li.appendChild(button)
|
||||
li.setAttribute("id", "li["+id+"]")
|
||||
var ul = document.getElementById("basket")
|
||||
ul.appendChild(li)
|
||||
}
|
||||
|
||||
function removeCake(id){
|
||||
document.getElementById("li["+id+"]").remove()
|
||||
}
|
||||
|
||||
{{range .Order.Cakes}}
|
||||
addCake({{.ID}}, '{{.Name}} {{.Price}}', {{.Amount}})
|
||||
{{end}}
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue