summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-12 20:06:17 +0200
committerxengineering <me@xengineering.eu>2024-05-12 20:06:17 +0200
commitf2800e8289e9637bb3227a5f9622edabf6529b0f (patch)
tree826dfa8b2cb5e68fca4c5cbabb8402688beebf51
parentcfeff398f0ad7e4205dc26b66ca2b46ebca24606 (diff)
downloadceres-f2800e8289e9637bb3227a5f9622edabf6529b0f.tar
ceres-f2800e8289e9637bb3227a5f9622edabf6529b0f.tar.zst
ceres-f2800e8289e9637bb3227a5f9622edabf6529b0f.zip
view: Move all JS code to static/ceres.js
-rw-r--r--view/html/recipe-edit.html48
-rw-r--r--view/static/ceres.js47
2 files changed, 47 insertions, 48 deletions
diff --git a/view/html/recipe-edit.html b/view/html/recipe-edit.html
index f2695f0..fb9cf74 100644
--- a/view/html/recipe-edit.html
+++ b/view/html/recipe-edit.html
@@ -31,54 +31,6 @@
</main>
{{ template "footer" }}
<script src="/static/view/static/ceres.js"></script>
- <script>
- function updateRecipe(event) {
- event.preventDefault();
-
- const form = event.target;
- const url = form.getAttribute('action');
- const data = new FormData(form);
- let obj = Object.fromEntries(data.entries());
-
- obj.steps = [];
- const steps = document.querySelectorAll('form section textarea');
- steps.forEach(step => {
- let s = {};
- s.text = step.value;
- obj.steps.push(s);
- });
-
- fetch(url, {
- method: 'POST',
- headers: {'Content-Type': 'application/json'},
- body: JSON.stringify(obj)
- })
- .then(response => {
- if (response.ok) {
- console.log('Form submitted successfully');
- } else {
- console.error('Form submission failed');
- }
- if (response.redirected) {
- window.location.href = response.url;
- }
- })
- .catch(error => {
- console.error('Network error:', error);
- });
- }
-
- function addNewStep() {
- var newStep = document.createElement("section");
- newStep.innerHTML = `
- <textarea rows="4" cols="50" placeholder="Step description"></textarea>
- <button type="button" onclick="parentNode.remove();">remove</button>
- `;
-
- var steps = document.querySelector("#steps");
- steps.appendChild(newStep);
- }
- </script>
</body>
</html>
{{end}}
diff --git a/view/static/ceres.js b/view/static/ceres.js
index a8326da..abd5f30 100644
--- a/view/static/ceres.js
+++ b/view/static/ceres.js
@@ -49,3 +49,50 @@ function filter() {
}
}
}
+
+function updateRecipe(event) {
+ event.preventDefault();
+
+ const form = event.target;
+ const url = form.getAttribute('action');
+ const data = new FormData(form);
+ let obj = Object.fromEntries(data.entries());
+
+ obj.steps = [];
+ const steps = document.querySelectorAll('form section textarea');
+ steps.forEach(step => {
+ let s = {};
+ s.text = step.value;
+ obj.steps.push(s);
+ });
+
+ fetch(url, {
+ method: 'POST',
+ headers: {'Content-Type': 'application/json'},
+ body: JSON.stringify(obj)
+ })
+ .then(response => {
+ if (response.ok) {
+ console.log('Form submitted successfully');
+ } else {
+ console.error('Form submission failed');
+ }
+ if (response.redirected) {
+ window.location.href = response.url;
+ }
+ })
+ .catch(error => {
+ console.error('Network error:', error);
+ });
+}
+
+function addNewStep() {
+ var newStep = document.createElement("section");
+ newStep.innerHTML = `
+ <textarea rows="4" cols="50" placeholder="Step description"></textarea>
+ <button type="button" onclick="parentNode.remove();">remove</button>
+ `;
+
+ var steps = document.querySelector("#steps");
+ steps.appendChild(newStep);
+}