diff options
Diffstat (limited to 't_idea')
-rw-r--r-- | t_idea/edit.html | 38 | ||||
-rw-r--r-- | t_idea/index.html | 59 |
2 files changed, 97 insertions, 0 deletions
diff --git a/t_idea/edit.html b/t_idea/edit.html new file mode 100644 index 0000000..cae7bd2 --- /dev/null +++ b/t_idea/edit.html @@ -0,0 +1,38 @@ +<!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>Editing "{{.Title}}"</title> + <style> +textarea[name="text"] { + color: #4c4c4c; + border: dashed 1px black; + font-size: 1.25em; + font-family: monospace; +} +input[name="title"] { + color: #4c4c4c; + border: dashed 1px black; + font-weight: bold; + font-size: 2em; +} + </style> + </head> + <body> + <h3>Editing "{{.Title}}"</h3> + <hr> + <div class="idea"> + <form action="/idea/edit/" method="post"> + <input name="title" type="text" value="{{.Title}}"><br> + <textarea name="text" cols=80 rows=4 required>{{.Text}}</textarea> + <p class="creation">by <span class="author">{{.Author}}</span> on <span class="date">{{.CreatedAt}}</span></p> + <input type="submit" value="confirm"> + </form> + <form action="/ideas/" method="get"> + <input type="submit" value="cancel"> + </form> + </div> + </body> +</html> diff --git a/t_idea/index.html b/t_idea/index.html new file mode 100644 index 0000000..b219ba3 --- /dev/null +++ b/t_idea/index.html @@ -0,0 +1,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> |