blob: b219ba3172d5dbc06364b679d0f40cd7ea296f60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/main.css">
<title>Ideas</title>
</head>
<body>
{{ with .Error }}
<p class="error">{{.}}</p>
{{ end}}
<h3>Add an idea:</h3>
<form action="/idea/create/" method="post">
<input name="title" type="text" placeholder="Title" required></br>
<textarea name="text" cols=50 rows=4 placeholder="Write what is in your lightbulb here." required></textarea>
</br>
<input name="author" type="text" placeholder="Your Name" required></br>
<input type="submit" value="Think">
</form>
<hr>
<ul>
{{ range .Ideas }}
<div class="idea">
<h2 class="title">{{.Title}}</h2>
<p class="text">{{.Text}}</p>
<p class="creation">by <span class="author">{{.Author}}</span> on <span class="date">{{.CreatedAt}}</span></p>
<form action="/idea/delete/" method="post">
<input type="hidden" name="title" value="{{.Title}}">
<input type="submit" value="delete">
</form>
<button class="edit" data-title="{{.Title}}">edit</button>
</div>
{{ else }}
<p><i>No ideas here... Be the first one to think!</i></p>
{{ end }}
</ul>
<!--template-->
</body>
<script>
let dels = document.querySelectorAll("form[action=\"/idea/delete/\"]")
for (el of dels) {
el.addEventListener("submit", function(e) {
e.preventDefault()
if (confirm("are you sure?") === true) {
this.submit()
}
})
}
let eels = document.querySelectorAll("button.edit")
for (el of eels) {
el.onclick = function(e) {
location.href = "/idea/edit?t=" + el.getAttribute("data-title")
}
}
</script>
</html>
|