summaryrefslogtreecommitdiff
path: root/views/recipe/edit.ejs
blob: d72b3e4ce50824996d5a6cb1e949cc953abfc73f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<%- include('../partials/header') %>
<%- include('../partials/nav') %>

<div class='content'>
    <%- include('../partials/categories') %>
    <div class='main'>
        <div class='editCard'>
            <h4 style='text-align: center'>Edit Recipe Details and Ingredients</h4>
            <form id='createForm' action="/recipe/<%= recipe._id %>?_method=PUT" method='POST'>
                <label for="">Title:</label>
                <input type="text" name='recipe[title]' value='<%= recipe.title %>'>
                <label for="">Image:</label>
                <a href='/recipe/image/upload'>Upload image</a>
                <% if(files) { %>
                    <select id="" name="recipe[picture]">
                        <option value='<%= recipe.picture %>' selected disabled> <%= recipe.picture %>
                        <% files.map(f => { %>
                            <option value='<%= f %>'><%= f %></option>
                        <% }) %>
                    </select>
                <% } %>
                <label for="">Category:</label>
                <input type="text" name='recipe[category]' value='<%= recipe.category %>'>
                <label for="">Ingredients:</label>
                <input type="text" name='recipe[ingridients]' value='<%= recipe.ingridients %>'>
                <label for="">Number of steps:</label>
                <div class='stepControl'>
                    <input id='stpnum' type="number" value='<%= recipe.steps.length %>' name='recipe[nsteps]'>
                </div>
                <button id='sub' type="submit">Edit</button>
            </form>
        </div>
        <div class='stepsToEd'>
            <h4>Instructions (<%= recipe.steps.length %> steps)</h4>
            <% recipe.steps.map(s => { %>
                <div class='stepToEd' style='display: flex; padding: 0'>
                    <div style='display:flex; flex-direction: column; width: 100%;'>
                        <h5>Step <%= s.number %>:</h5>
                        <p><%= s.step %></p>
                    </div>
                    <div class='edtr' style="display: flex; flex-direction: column; align-items: right; justify-content: center; margin: 0; padding: 0">
                        <form action="/recipe/<%= recipe._id %>/step/<%= s._id %>/edit" onclick="(e) => e.preventDefult()">
                            <button class='editStpBtns' style='margin: 0; padding: .25rem'>
                                <i class='fas fa-edit'></i>
                            </button>
                        </form>
                        <form action="/recipe/<%= recipe._id %>/step/<%= s._id %>?_method=DELETE" method='POST'>
                            <button class='editStpBtns' style='margin: 0; padding: .25rem'>
                                <i class='fas fa-trash'></i>
                            </button>
                        </form>
                    </div>
                </div>
            <% }) %>
        </div>
        <form style='margin-top: 0;' id='createForm' action="/recipe/<%= recipe._id %>/step/create">
            <button id='addStep'>Add a step</button>
        </form>
    </div>
    <%- include('../partials/popular') %> 
</div>

<script type='text/javascript'>
    const prevent = (e) => {
        e.preventDefault();
    }
</script>

<%- include('../partials/magicCats') %>
<%- include('../partials/magicPops') %>
<%- include('../partials/footer') %>