go-wiki/views/templates/editor.html
2020-03-19 09:04:54 +01:00

49 lines
1.2 KiB
HTML

{{define "title"}} {{.Title}} | Go-Wiki {{end}} {{define "content"}}
<h1>Editing {{.Title}}</h1>
<!-- Include stylesheet -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet" />
<!-- Create the editor container -->
<div id="editor">
<h1>{{.Title}}</h1>
<p><br /></p>
<p>{{printf "%s" .Body}}</p>
<p><br /></p>
</div>
<div class="form-group">
<form id="saveForm">
<input class="btn btn-primary" type="submit" value="Save changes" />
</form>
</div>
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
let quill = new Quill("#editor", {
theme: "snow"
});
saveForm = document.getElementById("saveForm");
saveForm.addEventListener("submit", async e => {
e.preventDefault();
console.log("send to backend");
let text = quill.getContents();
console.log(text);
response = await fetch("http://localhost:8080/editor", {
method: "post",
body: JSON.stringify(text),
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
}); //.then(r => console.log(r.json()));
// .then(r => (r));
// return await response.json();
});
</script>
{{end}}