MDL-65635 forum: Add messageformat and tohtml params to inline-reply

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.
This commit is contained in:
Sara Arjona 2019-05-17 19:55:29 +02:00 committed by Eloy Lafuente (stronk7)
parent f2eb04c170
commit 88f6ca6cbe
4 changed files with 22 additions and 5 deletions

View file

@ -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+="<p>"+b.message+"</p>"),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)}}});
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+="<p>"+b.message+"</p>"),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}});

View file

@ -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}});
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}});