Edit Note: s/Note/Item

This commit is contained in:
Sam Wing 2019-11-18 15:07:57 -05:00
parent 23b1c5480c
commit 90c2c09c57
3 changed files with 29 additions and 22 deletions

View file

@ -193,8 +193,10 @@ module.exports = (db) => {
req.flash('error', 'Invalid user'); req.flash('error', 'Invalid user');
return res.redirect(`/wishlist/${req.params.user}`); return res.redirect(`/wishlist/${req.params.user}`);
} }
wishlistItem.note = req.body.note; wishlistItem.name = req.body.name;
wishlist[i] = wishlistItem; wishlistItem.note = req.body.note;
wishlistItem.url = req.body.url;
wishlist[i] = wishlistItem;
} }
doc.wishlist = wishlist; doc.wishlist = wishlist;
await db.put(doc); await db.put(doc);

View file

@ -3,17 +3,23 @@ extends layout.pug
block content block content
a(href='..') <i class="fas fa-arrow-left"></i> Back to #{req.params.user}'s wishlist a(href='..') <i class="fas fa-arrow-left"></i> Back to #{req.params.user}'s wishlist
form.inline(method='POST', action=`/wishlist/${req.params.user}/note/${req.params.id}`) form.inline(method='POST', action=`/wishlist/${req.params.user}/note/${req.params.id}`)
.columns
.column
.field
label.label Name
.control
input.input(name='name', value=req.query.name)
.column
.field
label.label URL
.control
input.input(name='url', value=req.query.url)
.field .field
label.label Note label.label Note
.control .control
textarea.textarea( textarea.textarea(
name='note' name='note'
)= req.query.current )= req.query.note
.field.inline .field.inline
.control.inline .control.inline
input.button.is-primary(type='submit' value='Save Note') input.button.is-primary(type='submit' value='Save Item')
if req.query.current
form.inline(method='POST', style='margin-left: 1em;')
.field.inline
.control.inline
input.button.is-danger(type='submit', value='Delete Note')

View file

@ -8,7 +8,7 @@ block content
thead thead
th(style='width: 25%;') Name th(style='width: 25%;') Name
th(style='width: 50%;') Note th(style='width: 50%;') Note
th Edit Note th Edit Item
th Added By th Added By
if req.params.user === req.user._id if req.params.user === req.user._id
th Move Up th Move Up
@ -30,9 +30,11 @@ block content
else else
td.ugc(data-label='Name')= item.name td.ugc(data-label='Name')= item.name
td.ugc(data-label='Note')= item.note td.ugc(data-label='Note')= item.note
td(data-label='Edit Note') td(data-label='Edit Item')
form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`)
input(type='hidden', name='current', value=item.note) input(type='hidden', name='name', value=item.name)
input(type='hidden', name='note', value=item.note)
input(type='hidden', name='url', value=item.url)
.field.inline .field.inline
.control.inline .control.inline
button.button.is-text( button.button.is-text(
@ -133,16 +135,13 @@ block content
.control.inline .control.inline
input.inline.button.is-warning(type='submit' value='Remove') input.inline.button.is-warning(type='submit' value='Remove')
if req.user._id === req.params.user || req.user._id === item.addedBy if req.user._id === req.params.user || req.user._id === item.addedBy
if (item.note) form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`)
form.inline(method='POST', action=`/wishlist/${req.params.user}/note/remove/${item.id}`) input(type='hidden', name='name', value=item.name)
.field.inline input(type='hidden', name='note', value=item.note)
.control.inline input(type='hidden', name='url', value=item.url)
input.inline.button.is-warning(type='submit', value='Remove note') .field.inline
else .control.inline
form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) input.inline.button(type='submit', value='Edit item')
.field.inline
.control.inline
input.inline.button(type='submit', value='Add note')
if index !== firstCanSee && req.user._id === req.params.user if index !== firstCanSee && req.user._id === req.params.user
form.inline(method='POST', action=`/wishlist/${req.params.user}/move/up/${item.id}`) form.inline(method='POST', action=`/wishlist/${req.params.user}/move/up/${item.id}`)
.field.inline .field.inline