Browse Source

Migrate publishing schedule dialog field resets to Stimulus

- Remove ...admin/schedule-publishing.js
- Builds on #11043 & #11066
- Closes #11029
Chiemezuo 1 year ago
parent
commit
3df622f2ef

+ 1 - 0
CHANGELOG.txt

@@ -117,6 +117,7 @@ Changelog
  * Maintenance: Migrate select all on focus/click behavior to Stimulus, used on the image URL generator (Chiemezuo Akujobi)
  * Maintenance: Add support for a `reset` method to support Stimulus driven dynamic field resets via the `w-action` controller (Chiemezuo Akujobi)
  * Maintenance: Add support for a `notify` target on the Stimulus dialog for dispatching events internally (Chiemezuo Akujobi)
+ * Maintenance: Migrate publishing schedule dialog field resets to Stimulus (Chiemezuo Akujobi)
 
 5.1.3 (xx.xx.20xx) - IN DEVELOPMENT
 ~~~~~~~~~~~~~~~~~~

+ 0 - 10
client/src/entrypoints/admin/schedule-publishing.js

@@ -1,10 +0,0 @@
-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;
-  });
-});

+ 0 - 1
client/webpack.config.js

@@ -48,7 +48,6 @@ module.exports = function exports(env, argv) {
       'page-editor',
       'preview-panel',
       'privacy-switch',
-      'schedule-publishing',
       'sidebar',
       'task-chooser-modal',
       'task-chooser',

+ 1 - 0
docs/releases/5.2.md

@@ -148,6 +148,7 @@ This feature was developed by Paarth Agarwal and Thibaud Colas as part of the Go
  * Migrate select all on focus/click behavior to Stimulus, used on the image URL generator (Chiemezuo Akujobi)
  * Add support for a `reset` method to support Stimulus driven dynamic field resets via the `w-action` controller (Chiemezuo Akujobi)
  * Add support for a `notify` target on the Stimulus dialog for dispatching events internally (Chiemezuo Akujobi)
+ * Migrate publishing schedule dialog field resets to Stimulus (Chiemezuo Akujobi)
 
 
 ## Upgrade considerations - changes affecting all projects

+ 10 - 9
wagtail/admin/panels/publishing_panel.py

@@ -1,6 +1,3 @@
-from django.forms import Media
-
-from wagtail.admin.staticfiles import versioned_static
 from wagtail.admin.widgets.datetime import AdminDateTimeInput
 from wagtail.models import Page
 
@@ -20,12 +17,22 @@ class PublishingPanel(MultiFieldPanel):
                     "go_live_at",
                     widget=AdminDateTimeInput(
                         js_overlay_parent_selector=js_overlay_parent_selector,
+                        attrs={
+                            "data-controller": "w-action",
+                            "data-action": "w-dialog:hidden->w-action#reset",
+                            "data-w-dialog-target": "notify",
+                        },
                     ),
                 ),
                 FieldPanel(
                     "expire_at",
                     widget=AdminDateTimeInput(
                         js_overlay_parent_selector=js_overlay_parent_selector,
+                        attrs={
+                            "data-controller": "w-action",
+                            "data-action": "w-dialog:hidden->w-action#reset",
+                            "data-w-dialog-target": "notify",
+                        },
                     ),
                 ),
             ],
@@ -53,9 +60,3 @@ 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")],
-            )

+ 11 - 0
wagtail/admin/tests/test_edit_handlers.py

@@ -1987,6 +1987,17 @@ class TestPublishingPanel(WagtailTestUtils, TestCase):
         form = form_class()
         self.assertTrue(form.show_schedule_publishing_toggle)
 
+        # Get the "expire_at" input field from the form
+        expire_at_input = form.fields["expire_at"].widget
+        data_controller = expire_at_input.attrs.get("data-controller", None)
+        data_action = expire_at_input.attrs.get("data-action", None)
+        data_w_dialog_target = expire_at_input.attrs.get("data-w-dialog-target", None)
+
+        # Check that suitable data attributes for resetting the fields on dialog close are added
+        self.assertEqual(data_controller, "w-action")
+        self.assertEqual(data_action, "w-dialog:hidden->w-action#reset")
+        self.assertEqual(data_w_dialog_target, "notify")
+
     def test_form(self):
         """
         Check that the form has the scheduled publishing fields