mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +00:00
Allow deletion of draft news articles
When somebody posts a news article, make it possible to delete it before it's submitted to moderation (or after it's been withdrawn or bounced), instead of forcing the user to leave it around ForEver (TM). Do this by adding some generic functionality for confirmation popups, that can also be used for other things in the future.
This commit is contained in:
@ -98,3 +98,18 @@ function showDistros(btn, osDiv) {
|
||||
btn.style.background = active_color;
|
||||
document.getElementById(osDiv).style.display = 'block';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Register a confirm handler for forms that, well, requires confirmation
|
||||
* for someting.
|
||||
*/
|
||||
document.querySelectorAll('button[data-confirm]').forEach((button) => {
|
||||
button.addEventListener('click', (event) => {
|
||||
if (confirm(event.target.dataset.confirm)) {
|
||||
return true;
|
||||
}
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
@ -45,6 +45,11 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
|
||||
raise PermissionDenied("You cannot edit this item")
|
||||
|
||||
if request.method == 'POST':
|
||||
if 'modstate' in (f.name for f in instance._meta.get_fields()) and instance.modstate == ModerationState.CREATED and request.POST.get('delete', '') == 'delete':
|
||||
# Don't care to validate, just delete.
|
||||
instance.delete()
|
||||
return HttpResponseRedirect(redirect)
|
||||
|
||||
# Process this form
|
||||
form = formclass(data=request.POST, instance=instance)
|
||||
for fn in form.fields:
|
||||
@ -183,6 +188,7 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
|
||||
form_intro = None
|
||||
|
||||
savebutton = 'Save'
|
||||
deletebutton = None
|
||||
if itemid == 'new':
|
||||
if 'modstate' in (f.name for f in instance._meta.get_fields()):
|
||||
# This is a three-state moderated entry, so don't say "submit new" for new
|
||||
@ -194,6 +200,7 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
|
||||
if 'modstate' in (f.name for f in instance._meta.get_fields()):
|
||||
if instance.modstate == ModerationState.CREATED:
|
||||
savebutton = 'Save draft'
|
||||
deletebutton = 'Delete draft'
|
||||
|
||||
ctx = {
|
||||
'form': form,
|
||||
@ -201,6 +208,7 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for
|
||||
'form_intro': form_intro,
|
||||
'described_checkboxes': getattr(form, 'described_checkboxes', {}),
|
||||
'savebutton': savebutton,
|
||||
'deletebutton': deletebutton,
|
||||
'operation': (itemid == "new") and "New" or "Edit",
|
||||
}
|
||||
ctx.update(extracontext)
|
||||
|
@ -21,4 +21,7 @@
|
||||
{%endfor%}
|
||||
{%endif%}
|
||||
<button type="submit" class="btn btn-primary">{{savebutton|default:"Save"}}</button>
|
||||
{%if deletebutton%}
|
||||
<button type="submit" name="delete" value="delete" class="btn btn-secondary" data-confirm="Are you sure you want to permanently delete this draft?">{{deletebutton}}</button>
|
||||
{%endif%}
|
||||
</form>
|
||||
|
Reference in New Issue
Block a user