Files
notehub/assets/templates/form.html
T

68 lines
2.9 KiB
HTML
Raw Normal View History

2017-09-18 22:12:09 +02:00
{{define "Form"}}
2017-09-11 23:40:03 +02:00
<!DOCTYPE html>
<html>
<head>
2017-09-18 22:12:09 +02:00
<title>NoteHub &mdash; {{if .ID}}Edit{{else}}Add{{end}} note</title>
2017-09-21 22:59:23 +02:00
<meta charset="UTF-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
2017-09-11 23:40:03 +02:00
<link href="/style.css" rel="stylesheet" type="text/css" />
2017-09-21 22:59:23 +02:00
<script src='https://www.google.com/recaptcha/api.js'></script>
2017-09-23 23:29:06 +02:00
<script src='/note.js'></script>
2017-09-11 23:40:03 +02:00
</head>
<body>
2017-09-23 23:43:56 +02:00
<form autocomplete="off" onsubmit="return false">
2017-09-23 23:29:06 +02:00
<textarea autofocus id="text">{{.Text}}</textarea>
2017-09-11 23:40:03 +02:00
<fieldset>
2017-09-23 23:29:06 +02:00
<input id="id" value="{{.ID}}" type="hidden" />
<input class="ui-elem" id="password" placeholder="Password for editing" type="text" autocomplete="off" />
2017-09-11 23:40:03 +02:00
<label style="margin-right: 1em">
2017-09-23 23:29:06 +02:00
<input id="tos" type="checkbox" onClick="toggleButton()" />
2017-09-11 23:40:03 +02:00
Accept <a href="/TOS.md">Terms of Service</a>
</label>
2017-09-23 23:43:56 +02:00
<button class="button ui-elem" disabled id="publish-button" type="button" onclick="grecaptcha.execute()">
2017-09-23 23:29:06 +02:00
{{if .ID}}Update{{else}}Publish{{end}} Note
</button>
<span id="feedback"></span>
2017-09-11 23:40:03 +02:00
</fieldset>
</form>
<footer>
2017-09-18 23:59:01 +02:00
<a href="/">&#8962; notehub</a> &middot;
2017-09-11 23:40:03 +02:00
<a href="https://github.com/chmllr/NoteHub">source code</a> &middot;
<a href="/TOS.md">terms of service</a>
</footer>
<script>
function $(id) { return document.getElementById(id) }
2017-09-23 23:43:56 +02:00
function toggleButton() { $('publish-button').disabled = !$('tos').checked }
function submitForm(token) {
2017-09-23 23:29:06 +02:00
var id = $("id").value;
var text = $("text").value;
var deletion = id != "" && text == "";
if (deletion && !confirm("Do you want to delete this note?")) {
return;
}
var resp = post("/", {
"id": id,
"text": text,
"tos": $("tos").value,
2017-09-23 23:43:56 +02:00
"password": $("password").value,
"token": token
2017-09-23 23:29:06 +02:00
}, function (status, responseRaw) {
var response = JSON.parse(responseRaw);
if (status < 400 && response.Success) {
window.location.replace(deletion ? "/" : "/" + response.Payload)
} else {
2017-09-23 23:43:56 +02:00
grecaptcha.reset();
2017-09-23 23:29:06 +02:00
$('feedback').innerHTML = status + ": " + response.Payload;
}
})
}
2017-09-11 23:40:03 +02:00
</script>
2017-09-23 23:43:56 +02:00
<div class="g-recaptcha"
data-sitekey="6LfamjEUAAAAAANI45H3fpWG_xaSAcpYhENN4EnO"
data-callback="submitForm"
data-size="invisible">
</div>
2017-09-11 23:40:03 +02:00
</body>
</html>
2017-09-18 22:12:09 +02:00
{{end}}