diff options
author | xengineering <me@xengineering.eu> | 2023-01-14 18:07:47 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-02-08 20:44:02 +0100 |
commit | 9005de11ef8b7cf32cc8503e8b5f134eca47b4fb (patch) | |
tree | c6a445bd55790c9677d9217de72b8d968c33ce2d /data | |
parent | 1f8b5c2bbe20c4c6b7b334b00ae5e6622dcd51f7 (diff) | |
download | ceres-9005de11ef8b7cf32cc8503e8b5f134eca47b4fb.tar ceres-9005de11ef8b7cf32cc8503e8b5f134eca47b4fb.tar.zst ceres-9005de11ef8b7cf32cc8503e8b5f134eca47b4fb.zip |
Add new recipe edit page
Recipes should be completely editable and removable. Thus this edit page
was added.
Diffstat (limited to 'data')
-rw-r--r-- | data/templates/recipe.html | 42 | ||||
-rw-r--r-- | data/templates/recipe_edit.html | 33 |
2 files changed, 35 insertions, 40 deletions
diff --git a/data/templates/recipe.html b/data/templates/recipe.html index 536cac9..a35cc49 100644 --- a/data/templates/recipe.html +++ b/data/templates/recipe.html @@ -25,51 +25,13 @@ <main> <img src="./recipe/image?id={{.Id}}" alt="Recipe image"> <h2>Recipe description</h2> - <button id="editbtn" style="display:block" onclick=startEditMode()>edit</button> - <button id="cancelbtn" style="display:none" onclick=cancelEditMode()>abort</button> - <button id="savebtn" style="display:none" onclick=saveDescriptionMarkdown()>save</button> - <pre id="description_md" style="display:none;" contenteditable="true">{{.DescriptionMarkdown}}</pre> - <div id="rendered_description_md" style="display:block;"> - {{.RenderedDescriptionMarkdown}} - </div> + <a href="./recipe/edit?id={{.Id}}"><button>edit</button></a> + {{.RenderedDescriptionMarkdown}} <footer> <hr> <p>The <a href="https://xengineering.eu/git/ceres">Ceres</a> recipe server is licensed under <a href="https://www.gnu.org/licenses/agpl-3.0.en.html">AGPL v3</a> and developed with <a href="https://simplecss.org/">simple.css</a>.</p> </footer> </main> - - <script> - var editbtn = document.getElementById("editbtn"); - var cancelbtn = document.getElementById("cancelbtn"); - var savebtn = document.getElementById("savebtn"); - var description_md = document.getElementById("description_md"); - var rendered_description_md = document.getElementById("rendered_description_md"); - - function startEditMode() { - editbtn.style.display = "none"; - rendered_description_md.style.display = "none"; - cancelbtn.style.display = "block"; - savebtn.style.display = "block"; - description_md.style.display = "block"; - } - - function cancelEditMode() { - window.location.reload(true); - } - - function saveDescriptionMarkdown() { - var xhttp = new XMLHttpRequest(); - xhttp.onreadystatechange = function() { - if (this.readyState == 4) { - window.location.reload(true); - } - } - xhttp.open("POST", window.location.href, true); - xhttp.send(description_md.innerHTML.replaceAll("<br>", "\n")); - } - </script> - </body> - </html> diff --git a/data/templates/recipe_edit.html b/data/templates/recipe_edit.html new file mode 100644 index 0000000..b5c9672 --- /dev/null +++ b/data/templates/recipe_edit.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> + +<html> + + <head> + + <title>Recipes</title> + + <meta charset="utf-8"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <link rel="stylesheet" href="../../../static/style.css" type="text/css"> + + </head> + + <body> + <header> + <h1>Edit a recipe</h1> + </header> + + <main> + <p>ID: {{.Id}}</p> + <form action="/add_recipes" method="post" id="recipe_form"> + <input placeholder="Title" type="text" id="custom_title" name="title" value="{{.Title}}"><br> + <input placeholder="Link (optional)" type="text" id="custom_link" name="url" value="{{.UpstreamUrl}}"><br> + <label for="image">New image (optional):</label> + <input id="image" type="file"><br> + <pre form="recipe_form" name="description_markdown" contenteditable="true"><code>{{.DescriptionMarkdown}}</code></pre> + <button type="submit">save</button> + </form> + <a href="/recipe?id={{.Id}}"><button>cancel</button></a> + </main> + </body> +</html> |