diff --git a/mod/forum/amd/build/inpage_reply.min.js b/mod/forum/amd/build/inpage_reply.min.js index 33b572babbb..135ddbbb0de 100644 --- a/mod/forum/amd/build/inpage_reply.min.js +++ b/mod/forum/amd/build/inpage_reply.min.js @@ -1 +1 @@ -define(["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors"],function(a,b,c,d,e){var f={THREADED:2,NESTED:3,FLAT_OLDEST_FIRST:1,FLAT_NEWEST_FIRST:-1},g=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer),d=a.outerWidth();a.css("width",d),b.addClass("hidden"),c.removeClass("hidden")},h=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer);a.css("width",""),b.removeClass("hidden"),c.addClass("hidden")},i=function(i){i.on("click",e.post.inpageSubmitBtn,function(j){j.preventDefault();var k,l=a(j.currentTarget),m=l.parent().find(e.post.inpageReplyButton),n=l.parents(e.post.inpageReplyForm).get(0),o=n.elements.post.value.trim(),p=n.elements.reply.value,q=n.elements.subject.value,r=l.parents(e.post.forumContent),s=void 0!=n.elements.privatereply&&n.elements.privatereply.checked,t=parseInt(i.find(e.post.modeSelect).get(0).value);o.length&&(g(l),m.prop("disabled",!0),d.addDiscussionPost(p,q,o,s).then(function(a){var b=a.messages.reduce(function(a,b){return"success"==b.type&&(a+="

"+b.message+"

"),a},"");return c.addNotification({message:b,type:"success"}),a}).then(function(a){n.reset();var c=a.post;switch(k=c.id,t){case f.THREADED:return b.render("mod_forum/forum_discussion_threaded_post",c);case f.NESTED:return b.render("mod_forum/forum_discussion_nested_post",c);default:return b.render("mod_forum/forum_discussion_post",c)}}).then(function(a,c){var d;return t!=f.FLAT_OLDEST_FIRST&&t!=f.FLAT_NEWEST_FIRST||(d=r.parents(e.post.repliesContainer).children().get(0)),void 0==d&&(d=r.siblings(e.post.repliesContainer).children().get(0)),t==f.FLAT_NEWEST_FIRST?b.prependNodeContents(d,a,c):b.appendNodeContents(d,a,c)}).then(function(){return h(l),m.prop("disabled",!1),r.find(e.post.inpageReplyContent).hide()}).then(function(){location.href="#p"+k})["catch"](function(a){return h(l),m.prop("disabled",!1),c.exception(a)}))})};return{init:function(a){i(a)}}}); \ No newline at end of file +define(["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors"],function(a,b,c,d,e){var f={THREADED:2,NESTED:3,FLAT_OLDEST_FIRST:1,FLAT_NEWEST_FIRST:-1},g={MOODLE:0},h=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer),d=a.outerWidth();a.css("width",d),b.addClass("hidden"),c.removeClass("hidden")},i=function(a){var b=a.find(e.post.inpageSubmitBtnText),c=a.find(e.post.loadingIconContainer);a.css("width",""),b.removeClass("hidden"),c.addClass("hidden")},j=function(j){j.on("click",e.post.inpageSubmitBtn,function(k){k.preventDefault();var l,m=a(k.currentTarget),n=m.parent().find(e.post.inpageReplyButton),o=m.parents(e.post.inpageReplyForm).get(0),p=o.elements.post.value.trim(),q=g.MOODLE,r=!0,s=o.elements.reply.value,t=o.elements.subject.value,u=m.parents(e.post.forumContent),v=void 0!=o.elements.privatereply&&o.elements.privatereply.checked,w=parseInt(j.find(e.post.modeSelect).get(0).value);p.length&&(h(m),n.prop("disabled",!0),d.addDiscussionPost(s,t,p,q,v,r).then(function(a){var b=a.messages.reduce(function(a,b){return"success"==b.type&&(a+="

"+b.message+"

"),a},"");return c.addNotification({message:b,type:"success"}),a}).then(function(a){o.reset();var c=a.post;switch(l=c.id,w){case f.THREADED:return b.render("mod_forum/forum_discussion_threaded_post",c);case f.NESTED:return b.render("mod_forum/forum_discussion_nested_post",c);default:return b.render("mod_forum/forum_discussion_post",c)}}).then(function(a,c){var d;return w!=f.FLAT_OLDEST_FIRST&&w!=f.FLAT_NEWEST_FIRST||(d=u.parents(e.post.repliesContainer).children().get(0)),void 0==d&&(d=u.siblings(e.post.repliesContainer).children().get(0)),w==f.FLAT_NEWEST_FIRST?b.prependNodeContents(d,a,c):b.appendNodeContents(d,a,c)}).then(function(){return i(m),n.prop("disabled",!1),u.find(e.post.inpageReplyContent).hide()}).then(function(){location.href="#p"+l})["catch"](function(a){return i(m),n.prop("disabled",!1),c.exception(a)}))})};return{init:function(a){j(a)},CONTENT_FORMATS:g}}); \ No newline at end of file diff --git a/mod/forum/amd/build/repository.min.js b/mod/forum/amd/build/repository.min.js index 019d014aefe..16de8615ee1 100644 --- a/mod/forum/amd/build/repository.min.js +++ b/mod/forum/amd/build/repository.min.js @@ -1 +1 @@ -define(["core/ajax"],function(a){var b=function(b,c,d){var e={methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},c=function(b,c,d,e){var f={methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,subject:c,options:[{name:"private",value:e}]}};return a.call([f])[0]},d=function(b,c,d){var e={methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]},e=function(b,c,d){var e={methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},f=function(b,c,d){var e={methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]};return{setDiscussionSubscriptionState:b,addDiscussionPost:c,setDiscussionLockState:e,setFavouriteDiscussionState:d,setPinDiscussionState:f}}); \ No newline at end of file +define(["core/ajax"],function(a){var b=function(b,c,d){var e={methodname:"mod_forum_set_subscription_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},c=function(b,c,d,e,f,g){var h={methodname:"mod_forum_add_discussion_post",args:{postid:b,message:d,messageformat:e,subject:c,options:[{name:"private",value:f},{name:"tohtml",value:g}]}};return a.call([h])[0]},d=function(b,c,d){var e={methodname:"mod_forum_toggle_favourite_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]},e=function(b,c,d){var e={methodname:"mod_forum_set_lock_state",args:{forumid:b,discussionid:c,targetstate:d}};return a.call([e])[0]},f=function(b,c,d){var e={methodname:"mod_forum_set_pin_state",args:{discussionid:c,targetstate:d}};return a.call([e])[0]};return{setDiscussionSubscriptionState:b,addDiscussionPost:c,setDiscussionLockState:e,setFavouriteDiscussionState:d,setPinDiscussionState:f}}); \ No newline at end of file diff --git a/mod/forum/amd/src/inpage_reply.js b/mod/forum/amd/src/inpage_reply.js index 7b03f1d13ef..7b9edd3b20f 100644 --- a/mod/forum/amd/src/inpage_reply.js +++ b/mod/forum/amd/src/inpage_reply.js @@ -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 }; }); diff --git a/mod/forum/amd/src/repository.js b/mod/forum/amd/src/repository.js index 05331605da2..e63fb48387a 100644 --- a/mod/forum/amd/src/repository.js +++ b/mod/forum/amd/src/repository.js @@ -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, }] } };