weekly release 4.0dev
[moodle.git] / mod / forum / amd / build / inpage_reply.min.js
1 define ("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],function(a,b,c,d,f,g){var h={NESTED_V2:4,THREADED:2,NESTED:3,FLAT_OLDEST_FIRST:1,FLAT_NEWEST_FIRST:-1},i={POST_CREATED:"mod_forum-post-created"},j={MOODLE:0},k=function(a){var b=a.find(f.post.inpageSubmitBtnText),c=a.find(f.post.loadingIconContainer),d=a.outerWidth();a.css("width",d);b.addClass("hidden");c.removeClass("hidden")},l=function(a){var b=a.find(f.post.inpageSubmitBtnText),c=a.find(f.post.loadingIconContainer);a.css("width","");b.removeClass("hidden");c.addClass("hidden")},m=function(m){m.on("click",f.post.inpageSubmitBtn,function(n){n.preventDefault();var e=a(n.currentTarget),o=e.parent().find(f.post.inpageReplyButton),p=e.parents(f.post.inpageReplyForm).get(0),q=p.elements.post.value.trim(),r=j.MOODLE,s=p.elements.reply.value,t=p.elements.subject.value,u=e.closest(f.post.post),v=p.elements.privatereply!=void 0?p.elements.privatereply.checked:!1,w=m.find(f.post.modeSelect),x=w.length?parseInt(w.get(0).value):null,y;if(q.length){k(e);o.prop("disabled",!0);d.addDiscussionPost(s,t,q,r,v,!0).then(function(a){var b=a.messages.reduce(function(a,b){if("success"==b.type){a+="<p>"+b.message+"</p>"}return a},"");c.addNotification({message:b,type:"success"});return a}).then(function(a){p.reset();var c=a.post;y=c.id;switch(x){case h.NESTED_V2:var d=c.capabilities,e=u.children().not(f.post.repliesContainer).find(f.post.authorName).text();c.parentauthorname=e;c.showactionmenu=d.view||d.controlreadstatus||d.edit||d.split||d.delete||d.export||c.urls.viewparent;return b.render("mod_forum/forum_discussion_nested_v2_post_reply",c);case h.THREADED:return b.render("mod_forum/forum_discussion_threaded_post",c);case h.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=u.find(f.post.repliesContainer).first();if(x==h.FLAT_NEWEST_FIRST){return b.prependNodeContents(d,a,c)}else{return b.appendNodeContents(d,a,c)}}).then(function(){e.trigger(i.POST_CREATED,y);l(e);o.prop("disabled",!1);g.resetFormDirtyState(e[0]);return u.find(f.post.inpageReplyContent).hide()}).then(function(){location.href="#p"+y}).catch(function(a){l(e);o.prop("disabled",!1);return c.exception(a)})}})};return{init:function init(a){m(a)},CONTENT_FORMATS:j,EVENTS:i}});
2 //# sourceMappingURL=inpage_reply.min.js.map