feat: can delete your ideas on other's lists
This commit is contained in:
parent
7d46722053
commit
b38e707ae2
|
|
@ -78,6 +78,16 @@ func (ctx *Context) UpdateForeignWishlist(w http.ResponseWriter, r *http.Request
|
||||||
http.Error(w, "Failed to add gift idea to other user...", http.StatusInternalServerError)
|
http.Error(w, "Failed to add gift idea to other user...", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
case "delete":
|
||||||
|
claims := r.Form["unclaimed"]
|
||||||
|
unclaims := r.Form["claimed"]
|
||||||
|
gifts := append(claims, unclaims...)
|
||||||
|
err := user.RemoveGifts(gifts...)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to remove gift idea for other user: %s\n", err)
|
||||||
|
http.Error(w, "Failed to remove gift idea for other user...", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
http.Error(w, "Invalid intent", http.StatusBadRequest)
|
http.Error(w, "Invalid intent", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@
|
||||||
const accepted = submissionNames.length > 0 && submissionNames.every((name) => acceptedNames.includes(name));
|
const accepted = submissionNames.length > 0 && submissionNames.every((name) => acceptedNames.includes(name));
|
||||||
submitter.disabled = !accepted;
|
submitter.disabled = !accepted;
|
||||||
}
|
}
|
||||||
|
function acceptAttribute(form, submitId, acceptedAttribute) {
|
||||||
|
const checkedInputs = Array.from(form.querySelectorAll("input")).filter((i) => i.checked);
|
||||||
|
const submitter = document.getElementById(submitId);
|
||||||
|
const accepted = checkedInputs.length > 0 && checkedInputs.every((i) => i.hasAttribute(acceptedAttribute));
|
||||||
|
submitter.disabled = !accepted;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,26 +33,19 @@
|
||||||
<h2>{{.Username}}'s list</h2>
|
<h2>{{.Username}}'s list</h2>
|
||||||
{{with .Gifts}}
|
{{with .Gifts}}
|
||||||
<form method="post" action="/{{$.UserReference}}/update" autocomplete="off"
|
<form method="post" action="/{{$.UserReference}}/update" autocomplete="off"
|
||||||
onchange="acceptNames(this, 'claimSubmit', 'claimed', 'unclaimed'); acceptNames(this, 'completeSubmit', 'claimed');">
|
onchange="acceptNames(this, 'claimSubmit', 'claimed', 'unclaimed'); acceptNames(this, 'completeSubmit', 'claimed'); acceptAttribute(this, 'deleteSubmit', 'data-deletable')">
|
||||||
<button id="claimSubmit" class="btn btn-warning" type="submit" name="intent" value="claim"
|
<ul class="list-group mb-3">
|
||||||
disabled>Claim/Unclaim</button>
|
|
||||||
<button id="completeSubmit" class="btn btn-success" type="submit" name="intent" value="complete"
|
|
||||||
disabled>Complete</button>
|
|
||||||
<ul class="list-group mt-3">
|
|
||||||
{{range .}}
|
{{range .}}
|
||||||
|
{{$isMine := eq .ClaimantId $.CurrentUserId}}
|
||||||
|
{{$createdByMe := eq .CreatorId $.CurrentUserId}}
|
||||||
|
{{$outsideIdea := ne .RecipientId .CreatorId}}
|
||||||
<li class="list-group-item{{if .Sent}} list-group-item-light{{end}}">
|
<li class="list-group-item{{if .Sent}} list-group-item-light{{end}}">
|
||||||
{{if .ClaimantId}}
|
|
||||||
{{if eq .ClaimantId $.CurrentUserId}}
|
|
||||||
<input id="foreignlist_select_{{.Id}}" class="form-check-input" type="checkbox"
|
<input id="foreignlist_select_{{.Id}}" class="form-check-input" type="checkbox"
|
||||||
aria-describedby="wish_detail_{{.Id}}" name="claimed" value="{{.Id}}" {{if .Sent}}disabled{{end}}>
|
aria-describedby="wish_detail_{{.Id}}" {{if $isMine}} name="claimed" value="{{.Id}}" {{else if
|
||||||
{{else}}
|
.ClaimantId}} disabled {{else}} name="unclaimed" value="{{.Id}}" {{end}} {{if .Sent}} disabled {{end}}
|
||||||
<input id="foreignlist_select_{{.Id}}" class="form-check-input" type="checkbox"
|
{{if $createdByMe}}data-deletable{{end}}>
|
||||||
aria-describedby="wish_detail_{{.Id}}" disabled>
|
|
||||||
{{end}}
|
|
||||||
{{else}}
|
|
||||||
<input id="foreignlist_select_{{.Id}}" class="form-check-input" type="checkbox"
|
|
||||||
aria-describedby="wish_detail_{{.Id}}" name="unclaimed" value="{{.Id}}" {{if .Sent}}disabled{{end}}>
|
|
||||||
{{end}}
|
|
||||||
<label class="form-check-label stretched-link" for="foreignlist_select_{{.Id}}">
|
<label class="form-check-label stretched-link" for="foreignlist_select_{{.Id}}">
|
||||||
{{if .Sent}}
|
{{if .Sent}}
|
||||||
<s>{{.Name}}</s>
|
<s>{{.Name}}</s>
|
||||||
|
|
@ -60,29 +53,30 @@
|
||||||
{{.Name}}
|
{{.Name}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</label>
|
</label>
|
||||||
{{if or .ClaimantId (ne .RecipientId .CreatorId)}}
|
|
||||||
|
{{if or .ClaimantId $outsideIdea}}
|
||||||
<div class="d-inline" id="wish_detail_{{.Id}}">
|
<div class="d-inline" id="wish_detail_{{.Id}}">
|
||||||
{{if .ClaimantId}}
|
{{if .ClaimantId}}
|
||||||
{{if eq .ClaimantId $.CurrentUserId}}
|
<span style="color: {{if $isMine}}blue{{else}}red{{end}};">{{if .Sent}}Completed{{else}}Claimed{{end}}
|
||||||
<span style="color: blue;">{{if .Sent}}Completed{{else}}Claimed{{end}} by
|
by
|
||||||
<em>you</em></span>
|
{{if $isMine}}<em>you</em>{{else}}{{.ClaimantName}}{{end}}</span>
|
||||||
{{else}}
|
|
||||||
<span style="color: red;">{{if .Sent}}Completed{{else}}Claimed{{end}} by
|
|
||||||
{{.ClaimantName}}</span>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if ne .RecipientId .CreatorId}}
|
|
||||||
{{if eq .CreatorId $.CurrentUserId}}
|
|
||||||
<span style="color: green;">Added by <em>you</em></span>
|
|
||||||
{{else}}
|
|
||||||
<span style="color: green;">Added by {{.CreatorName}}</span>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if $outsideIdea}}
|
||||||
|
<span style="color: green;">Added by {{if
|
||||||
|
$createdByMe}}<em>you</em>{{else}}{{.CreatorName}}{{end}}</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
<button id="claimSubmit" class="btn btn-warning" type="submit" name="intent" value="claim"
|
||||||
|
disabled>Claim/Unclaim</button>
|
||||||
|
<button id="completeSubmit" class="btn btn-success" type="submit" name="intent" value="complete"
|
||||||
|
disabled>Complete</button>
|
||||||
|
<button id="deleteSubmit" class="btn btn-danger" type="submit" name="intent" value="delete"
|
||||||
|
disabled>Delete</button>
|
||||||
</form>
|
</form>
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>They don't have any gift ideas. Ask them to think of something, or add an idea yourself! 👇 (everyone
|
<p>They don't have any gift ideas. Ask them to think of something, or add an idea yourself! 👇 (everyone
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@
|
||||||
{{with .Gifts}}
|
{{with .Gifts}}
|
||||||
<form method="post" action="/wishlist/delete" onchange="acceptNames(this, 'deleteSubmit', 'gift')"
|
<form method="post" action="/wishlist/delete" onchange="acceptNames(this, 'deleteSubmit', 'gift')"
|
||||||
autocomplete="off">
|
autocomplete="off">
|
||||||
<button id="deleteSubmit" class="btn btn-danger mb-3" type="submit" name="mode" value="delete"
|
|
||||||
disabled>Delete</button>
|
|
||||||
<ul class="list-group mb-3">
|
<ul class="list-group mb-3">
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
|
|
@ -42,6 +40,8 @@
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
<button id="deleteSubmit" class="btn btn-danger mb-3" type="submit" name="mode" value="delete"
|
||||||
|
disabled>Delete</button>
|
||||||
</form>
|
</form>
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>Your list is empty. Think of some things to add!</p>
|
<p>Your list is empty. Think of some things to add!</p>
|
||||||
|
|
@ -62,11 +62,7 @@
|
||||||
<form method="post" action="/todo/update"
|
<form method="post" action="/todo/update"
|
||||||
onchange="acceptNames(this, 'unclaimSubmit', 'gift'); acceptNames(this, 'completeSubmit', 'gift')"
|
onchange="acceptNames(this, 'unclaimSubmit', 'gift'); acceptNames(this, 'completeSubmit', 'gift')"
|
||||||
autocomplete="off">
|
autocomplete="off">
|
||||||
<button id="unclaimSubmit" class="btn btn-warning" type="submit" name="mode" value="unclaim"
|
<ul class="list-group mb-3">
|
||||||
disabled>Unclaim</button>
|
|
||||||
<button id="completeSubmit" class="btn btn-success" type="submit" name="mode" value="complete"
|
|
||||||
disabled>Complete</button>
|
|
||||||
<ul class="list-group mt-3">
|
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<li class="list-group-item{{if .Sent}} list-group-item-light{{end}}">
|
<li class="list-group-item{{if .Sent}} list-group-item-light{{end}}">
|
||||||
<input id="todo_select_{{.Id}}" class="form-check-input" type="checkbox" {{if .Sent}}
|
<input id="todo_select_{{.Id}}" class="form-check-input" type="checkbox" {{if .Sent}}
|
||||||
|
|
@ -86,6 +82,10 @@
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
<button id="unclaimSubmit" class="btn btn-warning" type="submit" name="mode" value="unclaim"
|
||||||
|
disabled>Unclaim</button>
|
||||||
|
<button id="completeSubmit" class="btn btn-success" type="submit" name="mode" value="complete"
|
||||||
|
disabled>Complete</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue