From 41c8512789119be914af67a638c68ebc9d75decf Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Mon, 1 Aug 2022 23:20:26 +0700 Subject: [PATCH] Reset scheduled publishing fields when dialog is closed --- client/src/entrypoints/admin/schedule-publishing.js | 10 ++++++++++ client/webpack.config.js | 1 + wagtail/admin/panels.py | 7 +++++++ 3 files changed, 18 insertions(+) create mode 100644 client/src/entrypoints/admin/schedule-publishing.js diff --git a/client/src/entrypoints/admin/schedule-publishing.js b/client/src/entrypoints/admin/schedule-publishing.js new file mode 100644 index 0000000000..d187e9c95f --- /dev/null +++ b/client/src/entrypoints/admin/schedule-publishing.js @@ -0,0 +1,10 @@ +document.addEventListener('DOMContentLoaded', () => { + const dialog = document.getElementById('schedule-publishing-dialog'); + + dialog.addEventListener('hide', () => { + const goLiveAt = document.getElementById('id_go_live_at'); + const expireAt = document.getElementById('id_expire_at'); + goLiveAt.value = goLiveAt.defaultValue; + expireAt.value = expireAt.defaultValue; + }); +}); diff --git a/client/webpack.config.js b/client/webpack.config.js index 1e6319c06e..65f1079112 100644 --- a/client/webpack.config.js +++ b/client/webpack.config.js @@ -47,6 +47,7 @@ module.exports = function exports(env, argv) { 'page-editor', 'preview-panel', 'privacy-switch', + 'schedule-publishing', 'sidebar', 'task-chooser-modal', 'task-chooser', diff --git a/wagtail/admin/panels.py b/wagtail/admin/panels.py index 3fe09c33de..67750dfd3d 100644 --- a/wagtail/admin/panels.py +++ b/wagtail/admin/panels.py @@ -18,6 +18,7 @@ from modelcluster.models import get_serializable_data_for_fields from wagtail.admin import compare from wagtail.admin.forms.comments import CommentForm +from wagtail.admin.staticfiles import versioned_static from wagtail.admin.templatetags.wagtailadmin_tags import avatar_url, user_display_name from wagtail.admin.ui.components import Component from wagtail.admin.widgets import AdminPageChooser @@ -1094,6 +1095,12 @@ class PublishingPanel(MultiFieldPanel): def show_panel_furniture(self): return False + @property + def media(self): + return super().media + Media( + js=[versioned_static("wagtailadmin/js/schedule-publishing.js")], + ) + class CommentPanel(Panel): def get_form_options(self):