mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
create recipe form created but not linked to database yet
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Create Thyme Crunch Recipe</title>
|
||||
<link rel="stylesheet" th:href="@{css/create-recipe.css}">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<div class="form-wrap">
|
||||
<div class="form-split">
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="form-section">
|
||||
<div class="section-title">New Recipe</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="title">Title <span class="required">*</span></label>
|
||||
<input type="text" id="title" placeholder="Your recipe title...">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="desc">Description <span class="required">*</span></label>
|
||||
<textarea id="desc" rows="3" placeholder="Briefly describe your recipe. Who or where is it from?"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Ingredients <span class="required">*</span></label>
|
||||
<div id="ingredients-container"></div>
|
||||
<button class="btn-add" id="add-ingredient-btn">+ Add ingredient</button>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Instructions <span class="required">*</span></label>
|
||||
<div id="steps-container"></div>
|
||||
<button class="btn-add" id="add-step-btn">+ Add step</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Cover image / Right -->
|
||||
<div class="form-section">
|
||||
<div class="field">
|
||||
<div class="image-drop" id="drop-zone">
|
||||
<p class="upload-title">Click to upload or drag and drop an image.</p>
|
||||
</div>
|
||||
<div class="image-preview" id="preview">
|
||||
<img id="preview-img" src="" alt="Cover preview">
|
||||
<button class="remove-img" id="remove-img-btn">Remove</button>
|
||||
</div>
|
||||
<input type="file" id="img-input" accept="image/*" style="display: none;">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="prep">Preparation Time: <span class="required">*</span></label>
|
||||
<input type="text" id="prep" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="cooking">Cooking Time: <span class="required">*</span></label>
|
||||
<input type="text" id="cooking" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="servings">Servings: <span class="required">*</span></label>
|
||||
<input type="text" id="servings" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="cost">Estimated Cost: <span class="required">*</span></label>
|
||||
<input type="text" id="cost" placeholder="0">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<div class="form-section">
|
||||
|
||||
<div class="field">
|
||||
<label>Tags</label>
|
||||
<div class="tag-input-row">
|
||||
<input type="text" id="tag-input" placeholder="Type in a tag and click Add">
|
||||
<button class="btn" id="add-tag-btn">Add</button>
|
||||
</div>
|
||||
<div class="tag-wrap" id="tag-wrap"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn-create" id="publish-btn">CREATE</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
// ---- Ingredients ----
|
||||
const ingredientContainer = document.getElementById('ingredients-container');
|
||||
document.getElementById('add-ingredient-btn').addEventListener('click', addIngredient);
|
||||
addIngredient(); // start with one
|
||||
|
||||
function addIngredient() {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'dynamic-row';
|
||||
row.innerHTML = `
|
||||
<input type="text" placeholder="e.g. 3 tbsp of sugar">
|
||||
<button class="btn-remove" title="Remove">✕</button>`;
|
||||
row.querySelector('.btn-remove').addEventListener('click', () => {
|
||||
row.remove();
|
||||
});
|
||||
ingredientContainer.appendChild(row);
|
||||
}
|
||||
|
||||
// ---- Steps ----
|
||||
const stepsContainer = document.getElementById('steps-container');
|
||||
document.getElementById('add-step-btn').addEventListener('click', addStep);
|
||||
addStep(); // start with one
|
||||
|
||||
function addStep() {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'dynamic-row';
|
||||
row.innerHTML = `
|
||||
<div class="step-bubble">?</div>
|
||||
<textarea placeholder="Describe this step..."></textarea>
|
||||
<button class="btn-remove" title="Remove">✕</button>
|
||||
`;
|
||||
row.querySelector('.btn-remove').addEventListener('click', () => {
|
||||
row.remove();
|
||||
renumberSteps();
|
||||
});
|
||||
stepsContainer.appendChild(row);
|
||||
renumberSteps();
|
||||
}
|
||||
|
||||
function renumberSteps() {
|
||||
stepsContainer.querySelectorAll('.step-bubble').forEach((bubble, i) => {
|
||||
bubble.textContent = i + 1;
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Collecting on submit ----
|
||||
// Call this wherever you build your POST payload:
|
||||
function getIngredients() {
|
||||
return [...ingredientContainer.querySelectorAll('input')]
|
||||
.map((el, i) => ({ order: i + 1, name: el.value.trim() }))
|
||||
.filter(item => item.name);
|
||||
}
|
||||
|
||||
function getSteps() {
|
||||
return [...stepsContainer.querySelectorAll('textarea')]
|
||||
.map((el, i) => ({ step_number: i + 1, instruction: el.value.trim() }))
|
||||
.filter(item => item.instruction);
|
||||
}
|
||||
|
||||
// --- Image upload ---
|
||||
const dropZone = document.getElementById('drop-zone');
|
||||
const imgInput = document.getElementById('img-input');
|
||||
|
||||
dropZone.addEventListener('click', () => imgInput.click());
|
||||
|
||||
imgInput.addEventListener('change', function () {
|
||||
if (!this.files || !this.files[0]) return;
|
||||
const url = URL.createObjectURL(this.files[0]);
|
||||
document.getElementById('preview-img').src = url;
|
||||
dropZone.style.display = 'none';
|
||||
document.getElementById('preview').style.display = 'block';
|
||||
});
|
||||
|
||||
document.getElementById('remove-img-btn').addEventListener('click', function () {
|
||||
imgInput.value = '';
|
||||
document.getElementById('preview').style.display = 'none';
|
||||
dropZone.style.display = 'block';
|
||||
});
|
||||
|
||||
// --- Tags ---
|
||||
const tags = [];
|
||||
|
||||
document.getElementById('tag-input').addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
addTag();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('add-tag-btn').addEventListener('click', addTag);
|
||||
|
||||
function addTag() {
|
||||
const input = document.getElementById('tag-input');
|
||||
const val = input.value.trim().toLowerCase().replace(/\s+/g, '-');
|
||||
if (!val || tags.includes(val)) { input.value = ''; return; }
|
||||
tags.push(val);
|
||||
input.value = '';
|
||||
renderTags();
|
||||
}
|
||||
|
||||
function removeTag(t) {
|
||||
tags.splice(tags.indexOf(t), 1);
|
||||
renderTags();
|
||||
}
|
||||
|
||||
function renderTags() {
|
||||
document.getElementById('tag-wrap').innerHTML = tags
|
||||
.map(t => `<div class="tag">${t} <span class="remove-tag" data-tag="${t}">✕</span></div>`)
|
||||
.join('');
|
||||
|
||||
document.querySelectorAll('.remove-tag').forEach(btn => {
|
||||
btn.addEventListener('click', () => removeTag(btn.dataset.tag));
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user