MDL-65635 forum: Add messageformat and tohtml params to inline-reply
authorSara Arjona <sara@moodle.com>
Fri, 17 May 2019 17:55:29 +0000 (19:55 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 19 May 2019 08:42:59 +0000 (10:42 +0200)
The messageformat and tohtml params have been added to the addDiscussionPost
method to send the original format the contents are written and to force
to convert them from "messageformat" to HTML.

mod/forum/amd/build/inpage_reply.min.js
mod/forum/amd/build/repository.min.js
mod/forum/amd/src/inpage_reply.js
mod/forum/amd/src/repository.js

index 33b572b..135ddbb 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 019d014..16de861 100644 (file)
Binary files a/mod/forum/amd/build/repository.min.js and b/mod/forum/amd/build/repository.min.js differ
index 7b03f1d..7b9edd3 100644 (file)
@@ -42,6 +42,13 @@ define([
         FLAT_NEWEST_FIRST: -1
     };
 
+     /**
+      * Moodle formats taken from the FORMAT_* constants declared in lib/weblib.php.
+      * @type {Object}
+      */
+    var CONTENT_FORMATS = {
+        MOODLE: 0
+    };
     /**
      * Show the loading icon for the submit button.
      *
@@ -83,6 +90,11 @@ define([
             var allButtons = submitButton.parent().find(Selectors.post.inpageReplyButton);
             var form = submitButton.parents(Selectors.post.inpageReplyForm).get(0);
             var message = form.elements.post.value.trim();
+            // For now, we consider the inline reply post written using the FORMAT_MOODLE (because a textarea is displayed).
+            // In the future, other formats should be supported, letting users to use their preferred editor and format.
+            var messageformat = CONTENT_FORMATS.MOODLE;
+            // The message post will be converted from messageformat to FORMAT_HTML.
+            var tohtml = true;
             var postid = form.elements.reply.value;
             var subject = form.elements.subject.value;
             var currentRoot = submitButton.parents(Selectors.post.forumContent);
@@ -94,7 +106,7 @@ define([
                 showSubmitButtonLoadingIcon(submitButton);
                 allButtons.prop('disabled', true);
 
-                Repository.addDiscussionPost(postid, subject, message, isprivatereply)
+                Repository.addDiscussionPost(postid, subject, message, messageformat, isprivatereply, tohtml)
                     .then(function(context) {
                         var message = context.messages.reduce(function(carry, message) {
                             if (message.type == 'success') {
@@ -161,6 +173,7 @@ define([
     return {
         init: function(root) {
             registerEventListeners(root);
-        }
+        },
+        CONTENT_FORMATS: CONTENT_FORMATS
     };
 });
index 0533160..e63fb48 100644 (file)
@@ -43,16 +43,20 @@ define(['core/ajax'], function(Ajax) {
         return Ajax.call([request])[0];
     };
 
-    var addDiscussionPost = function(postid, subject, message, isprivatereply) {
+    var addDiscussionPost = function(postid, subject, message, messageformat, isprivatereply, tohtml) {
         var request = {
             methodname: 'mod_forum_add_discussion_post',
             args: {
                 postid: postid,
                 message: message,
+                messageformat: messageformat,
                 subject: subject,
                 options: [{
                     name: "private",
                     value: isprivatereply,
+                }, {
+                    name: "tohtml",
+                    value: tohtml,
                 }]
             }
         };