MDL-67654 mod_forum: formchangechecker for discussion inline replies.
authorPaul Holden <paulh@moodle.com>
Fri, 2 Oct 2020 06:46:45 +0000 (07:46 +0100)
committerPaul Holden <paulh@moodle.com>
Mon, 12 Oct 2020 22:32:50 +0000 (23:32 +0100)
mod/forum/amd/build/discussion_nested_v2.min.js
mod/forum/amd/build/discussion_nested_v2.min.js.map
mod/forum/amd/build/inpage_reply.min.js
mod/forum/amd/build/inpage_reply.min.js.map
mod/forum/amd/build/posts_list.min.js
mod/forum/amd/build/posts_list.min.js.map
mod/forum/amd/src/discussion_nested_v2.js
mod/forum/amd/src/inpage_reply.js
mod/forum/amd/src/posts_list.js

index ebadb62..645ee6e 100644 (file)
Binary files a/mod/forum/amd/build/discussion_nested_v2.min.js and b/mod/forum/amd/build/discussion_nested_v2.min.js differ
index 3cab6b2..a370455 100644 (file)
Binary files a/mod/forum/amd/build/discussion_nested_v2.min.js.map and b/mod/forum/amd/build/discussion_nested_v2.min.js.map differ
index 7a3bc75..997e1c3 100644 (file)
Binary files a/mod/forum/amd/build/inpage_reply.min.js and b/mod/forum/amd/build/inpage_reply.min.js differ
index 8172888..8dd41f9 100644 (file)
Binary files a/mod/forum/amd/build/inpage_reply.min.js.map and b/mod/forum/amd/build/inpage_reply.min.js.map differ
index 12d10bb..b8bb0af 100644 (file)
Binary files a/mod/forum/amd/build/posts_list.min.js and b/mod/forum/amd/build/posts_list.min.js differ
index 0423c5e..a9833ff 100644 (file)
Binary files a/mod/forum/amd/build/posts_list.min.js.map and b/mod/forum/amd/build/posts_list.min.js.map differ
index 6c0e89c..1b8f3d2 100644 (file)
@@ -245,6 +245,21 @@ const buildShowInPageReplyFormFunction = (additionalTemplateContext) => {
             } catch (e) {
                 Notification.exception(e);
             }
             } catch (e) {
                 Notification.exception(e);
             }
+
+            // Load formchangechecker module.
+            import('core/yui')
+                .then(Y => {
+                    return new Promise(resolve => {
+                        Y.use('moodle-core-formchangechecker', Y => {
+                            resolve(Y);
+                        });
+                    });
+                })
+                .then(Y => {
+                    M.core_formchangechecker.init({formid: Y.one(postContainer[0].querySelector('form')).generateID()});
+                    return Y;
+                })
+                .catch();
         }
 
         inPageReplyCreateButton.fadeOut(ANIMATION_DURATION, () => {
         }
 
         inPageReplyCreateButton.fadeOut(ANIMATION_DURATION, () => {
index 0f2d1c9..7a3e524 100644 (file)
@@ -169,6 +169,12 @@ define([
                         submitButton.trigger(EVENTS.POST_CREATED, newid);
                         hideSubmitButtonLoadingIcon(submitButton);
                         allButtons.prop('disabled', false);
                         submitButton.trigger(EVENTS.POST_CREATED, newid);
                         hideSubmitButtonLoadingIcon(submitButton);
                         allButtons.prop('disabled', false);
+
+                        // Tell formchangechecker we submitted the form.
+                        if (typeof M.core_formchangechecker !== 'undefined') {
+                            M.core_formchangechecker.reset_form_dirty_state();
+                        }
+
                         return currentRoot.find(Selectors.post.inpageReplyContent).hide();
                     })
                     .then(function() {
                         return currentRoot.find(Selectors.post.inpageReplyContent).hide();
                     })
                     .then(function() {
index ca92955..fe88af3 100644 (file)
@@ -30,6 +30,7 @@ define([
         'core/templates',
         'core/notification',
         'core/pending',
         'core/templates',
         'core/notification',
         'core/pending',
+        'core/yui',
         'mod_forum/selectors',
         'mod_forum/inpage_reply',
     ], function(
         'mod_forum/selectors',
         'mod_forum/inpage_reply',
     ], function(
@@ -37,6 +38,7 @@ define([
         Templates,
         Notification,
         Pending,
         Templates,
         Notification,
         Pending,
+        Y,
         Selectors,
         InPageReply
     ) {
         Selectors,
         InPageReply
     ) {
@@ -76,6 +78,13 @@ define([
                         return currentRoot.find(Selectors.post.inpageReplyContent)
                             .slideToggle(300, pending.resolve).find('textarea').focus();
                     })
                         return currentRoot.find(Selectors.post.inpageReplyContent)
                             .slideToggle(300, pending.resolve).find('textarea').focus();
                     })
+                    .then(function() {
+                        // Load formchangechecker module.
+                        Y.use('moodle-core-formchangechecker', () => {
+                            M.core_formchangechecker.init({formid: `inpage-reply-${context.postid}`});
+                        });
+                        return;
+                    })
                     .fail(Notification.exception);
             } else {
                 var form = currentRoot.find(Selectors.post.inpageReplyContent);
                     .fail(Notification.exception);
             } else {
                 var form = currentRoot.find(Selectors.post.inpageReplyContent);