Added cancel button for snippet edit

This commit is contained in:
Asaf Gartner 2022-08-07 00:51:29 +03:00
parent dc94262bfb
commit b995df4533
2 changed files with 17 additions and 2 deletions

View File

@ -55,6 +55,21 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen
}
updateProjectSelector();
if (originalSnippetEl) {
snippetEdit.cancelLink.addEventListener("click", function() {
cancel();
});
} else {
snippetEdit.cancelLink.remove();
}
function cancel() {
if (originalSnippetEl) {
snippetEdit.root.parentElement.insertBefore(originalSnippetEl, snippetEdit.root);
}
snippetEdit.root.remove();
}
function addProject(proj) {
let projEl = snippetEditProjectTemplate();
projEl.projectId.value = proj.id;
@ -328,8 +343,7 @@ function makeSnippetEdit(ownerName, ownerAvatar, ownerUrl, date, text, attachmen
if (originalSnippetEl && (!attachmentChanged && originalText == snippetEdit.text.value.trim() && !projectsChanged)) {
// NOTE(asaf): We're in edit mode and nothing changed, so no need to submit to the server.
ev.preventDefault();
snippetEdit.root.parentElement.insertBefore(originalSnippetEl, snippetEdit.root);
snippetEdit.root.remove();
cancel();
}
});

View File

@ -10,6 +10,7 @@
<a data-tmpl="username" class="flex-shrink-0"></a>
<div class="spacer flex-grow-1"></div>
<span data-tmpl="date" class="flex-shrink-0">Date</span>
<a data-tmpl="cancelLink" href="javascript:;" class="ml2 flex-shrink-0">&#10006;</a>
</div>
<textarea data-tmpl="text" placeholder="Description and/or links" class="w-100 h4 mt3" name="text"></textarea>
<div class="mv3">