mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
1 line
No EOL
1.9 KiB
JavaScript
1 line
No EOL
1.9 KiB
JavaScript
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=parseInt(i.find(e.post.modeSelect).get(0).value);o.length&&(g(l),m.prop("disabled",!0),d.addDiscussionPost(p,q,o).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,s){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 s!=f.FLAT_OLDEST_FIRST&&s!=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)),s==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)}}}); |