diff --git a/mod/forum/amd/build/inpage_reply.min.js b/mod/forum/amd/build/inpage_reply.min.js index 58ac03dd067..675fa032dd5 100644 --- a/mod/forum/amd/build/inpage_reply.min.js +++ b/mod/forum/amd/build/inpage_reply.min.js @@ -5,6 +5,6 @@ * @copyright 2019 Peter Dias * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="

"+message.message+"

"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}})); +define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="

"+message.message+"

"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid,location.reload()})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}})); //# sourceMappingURL=inpage_reply.min.js.map \ No newline at end of file diff --git a/mod/forum/amd/build/inpage_reply.min.js.map b/mod/forum/amd/build/inpage_reply.min.js.map index 7dd99a73a27..ff857012c65 100644 --- a/mod/forum/amd/build/inpage_reply.min.js.map +++ b/mod/forum/amd/build/inpage_reply.min.js.map @@ -1 +1 @@ -{"version":3,"file":"inpage_reply.min.js","sources":["../src/inpage_reply.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module handles the in page replying to forum posts.\n *\n * @module mod_forum/inpage_reply\n * @copyright 2019 Peter Dias\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'mod_forum/repository',\n 'mod_forum/selectors',\n 'core_form/changechecker',\n], function(\n $,\n Templates,\n Notification,\n Repository,\n Selectors,\n FormChangeChecker\n) {\n\n var DISPLAYCONSTANTS = {\n NESTED_V2: 4,\n THREADED: 2,\n NESTED: 3,\n FLAT_OLDEST_FIRST: 1,\n FLAT_NEWEST_FIRST: -1\n };\n\n var EVENTS = {\n POST_CREATED: 'mod_forum-post-created'\n };\n\n /**\n * Moodle formats taken from the FORMAT_* constants declared in lib/weblib.php.\n * @type {Object}\n */\n var CONTENT_FORMATS = {\n MOODLE: 0\n };\n /**\n * Show the loading icon for the submit button.\n *\n * @param {Object} button The submit button element\n */\n var showSubmitButtonLoadingIcon = function(button) {\n var textContainer = button.find(Selectors.post.inpageSubmitBtnText);\n var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);\n var width = button.outerWidth();\n // Fix the width so that the button size doesn't change when we show the loading icon.\n button.css('width', width);\n textContainer.addClass('hidden');\n loadingIconContainer.removeClass('hidden');\n };\n\n /**\n * Hide the loading icon for the submit button.\n *\n * @param {Object} button The submit button element\n */\n var hideSubmitButtonLoadingIcon = function(button) {\n var textContainer = button.find(Selectors.post.inpageSubmitBtnText);\n var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);\n // Reset the width back to it's default.\n button.css('width', '');\n textContainer.removeClass('hidden');\n loadingIconContainer.addClass('hidden');\n };\n\n /**\n * Register the event listeners for the submit button of the in page reply.\n *\n * @param {Object} root The discussion container element.\n */\n var registerEventListeners = function(root) {\n root.on('click', Selectors.post.inpageSubmitBtn, function(e) {\n e.preventDefault();\n var submitButton = $(e.currentTarget);\n var allButtons = submitButton.parent().find(Selectors.post.inpageReplyButton);\n var form = submitButton.parents(Selectors.post.inpageReplyForm).get(0);\n var message = form.elements.post.value.trim();\n // For now, we consider the inline reply post written using the FORMAT_MOODLE (because a textarea is displayed).\n // In the future, other formats should be supported, letting users to use their preferred editor and format.\n var messageformat = CONTENT_FORMATS.MOODLE;\n // The message post will be converted from messageformat to FORMAT_HTML.\n var topreferredformat = true;\n var postid = form.elements.reply.value;\n var subject = form.elements.subject.value;\n var currentRoot = submitButton.closest(Selectors.post.post);\n var isprivatereply = form.elements.privatereply != undefined ? form.elements.privatereply.checked : false;\n var modeSelector = root.find(Selectors.post.modeSelect);\n var mode = modeSelector.length ? parseInt(modeSelector.get(0).value) : null;\n var newid;\n\n if (message.length) {\n showSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', true);\n\n Repository.addDiscussionPost(postid, subject, message, messageformat, isprivatereply, topreferredformat)\n .then(function(context) {\n var message = context.messages.reduce(function(carry, message) {\n if (message.type == 'success') {\n carry += '

' + message.message + '

';\n }\n return carry;\n }, '');\n Notification.addNotification({\n message: message,\n type: \"success\"\n });\n\n return context;\n })\n .then(function(context) {\n form.reset();\n var post = context.post;\n newid = post.id;\n\n switch (mode) {\n case DISPLAYCONSTANTS.NESTED_V2:\n var capabilities = post.capabilities;\n var currentAuthorName = currentRoot.children()\n .not(Selectors.post.repliesContainer)\n .find(Selectors.post.authorName)\n .text();\n post.parentauthorname = currentAuthorName;\n post.showactionmenu = capabilities.view ||\n capabilities.controlreadstatus ||\n capabilities.edit ||\n capabilities.split ||\n capabilities.delete ||\n capabilities.export ||\n post.urls.viewparent;\n return Templates.render('mod_forum/forum_discussion_nested_v2_post_reply', post);\n case DISPLAYCONSTANTS.THREADED:\n return Templates.render('mod_forum/forum_discussion_threaded_post', post);\n case DISPLAYCONSTANTS.NESTED:\n return Templates.render('mod_forum/forum_discussion_nested_post', post);\n default:\n return Templates.render('mod_forum/forum_discussion_post', post);\n }\n })\n .then(function(html, js) {\n var repliesnode = currentRoot.find(Selectors.post.repliesContainer).first();\n\n if (mode == DISPLAYCONSTANTS.FLAT_NEWEST_FIRST) {\n return Templates.prependNodeContents(repliesnode, html, js);\n } else {\n return Templates.appendNodeContents(repliesnode, html, js);\n }\n })\n .then(function() {\n submitButton.trigger(EVENTS.POST_CREATED, newid);\n hideSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', false);\n\n // Tell formchangechecker we submitted the form.\n FormChangeChecker.resetFormDirtyState(submitButton[0]);\n\n return currentRoot.find(Selectors.post.inpageReplyContent).hide();\n })\n .then(function() {\n location.href = \"#p\" + newid;\n return;\n })\n .catch(function(error) {\n hideSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', false);\n return Notification.exception(error);\n });\n }\n });\n };\n\n return {\n init: function(root) {\n registerEventListeners(root);\n },\n CONTENT_FORMATS: CONTENT_FORMATS,\n EVENTS: EVENTS\n };\n});\n"],"names":["define","$","Templates","Notification","Repository","Selectors","FormChangeChecker","DISPLAYCONSTANTS","EVENTS","POST_CREATED","CONTENT_FORMATS","MOODLE","hideSubmitButtonLoadingIcon","button","textContainer","find","post","inpageSubmitBtnText","loadingIconContainer","css","removeClass","addClass","registerEventListeners","root","on","inpageSubmitBtn","e","preventDefault","newid","width","submitButton","currentTarget","allButtons","parent","inpageReplyButton","form","parents","inpageReplyForm","get","message","elements","value","trim","messageformat","postid","reply","subject","currentRoot","closest","isprivatereply","undefined","privatereply","checked","modeSelector","modeSelect","mode","length","parseInt","outerWidth","prop","addDiscussionPost","then","context","messages","reduce","carry","type","addNotification","reset","id","capabilities","currentAuthorName","children","not","repliesContainer","authorName","text","parentauthorname","showactionmenu","view","controlreadstatus","edit","split","delete","export","urls","viewparent","render","html","js","repliesnode","first","prependNodeContents","appendNodeContents","trigger","resetFormDirtyState","inpageReplyContent","hide","location","href","catch","error","exception","init"],"mappings":";;;;;;;AAsBAA,gCAAO,CACH,SACA,iBACA,oBACA,uBACA,sBACA,4BACD,SACCC,EACAC,UACAC,aACAC,WACAC,UACAC,uBAGIC,2BACW,EADXA,0BAEU,EAFVA,wBAGQ,EAHRA,oCAKoB,EAGpBC,OAAS,CACTC,aAAc,0BAOdC,gBAAkB,CAClBC,OAAQ,GAsBRC,4BAA8B,SAASC,YACnCC,cAAgBD,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sources":["../src/inpage_reply.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module handles the in page replying to forum posts.\n *\n * @module mod_forum/inpage_reply\n * @copyright 2019 Peter Dias\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'mod_forum/repository',\n 'mod_forum/selectors',\n 'core_form/changechecker',\n], function(\n $,\n Templates,\n Notification,\n Repository,\n Selectors,\n FormChangeChecker\n) {\n\n var DISPLAYCONSTANTS = {\n NESTED_V2: 4,\n THREADED: 2,\n NESTED: 3,\n FLAT_OLDEST_FIRST: 1,\n FLAT_NEWEST_FIRST: -1\n };\n\n var EVENTS = {\n POST_CREATED: 'mod_forum-post-created'\n };\n\n /**\n * Moodle formats taken from the FORMAT_* constants declared in lib/weblib.php.\n * @type {Object}\n */\n var CONTENT_FORMATS = {\n MOODLE: 0\n };\n /**\n * Show the loading icon for the submit button.\n *\n * @param {Object} button The submit button element\n */\n var showSubmitButtonLoadingIcon = function(button) {\n var textContainer = button.find(Selectors.post.inpageSubmitBtnText);\n var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);\n var width = button.outerWidth();\n // Fix the width so that the button size doesn't change when we show the loading icon.\n button.css('width', width);\n textContainer.addClass('hidden');\n loadingIconContainer.removeClass('hidden');\n };\n\n /**\n * Hide the loading icon for the submit button.\n *\n * @param {Object} button The submit button element\n */\n var hideSubmitButtonLoadingIcon = function(button) {\n var textContainer = button.find(Selectors.post.inpageSubmitBtnText);\n var loadingIconContainer = button.find(Selectors.post.loadingIconContainer);\n // Reset the width back to it's default.\n button.css('width', '');\n textContainer.removeClass('hidden');\n loadingIconContainer.addClass('hidden');\n };\n\n /**\n * Register the event listeners for the submit button of the in page reply.\n *\n * @param {Object} root The discussion container element.\n */\n var registerEventListeners = function(root) {\n root.on('click', Selectors.post.inpageSubmitBtn, function(e) {\n e.preventDefault();\n var submitButton = $(e.currentTarget);\n var allButtons = submitButton.parent().find(Selectors.post.inpageReplyButton);\n var form = submitButton.parents(Selectors.post.inpageReplyForm).get(0);\n var message = form.elements.post.value.trim();\n // For now, we consider the inline reply post written using the FORMAT_MOODLE (because a textarea is displayed).\n // In the future, other formats should be supported, letting users to use their preferred editor and format.\n var messageformat = CONTENT_FORMATS.MOODLE;\n // The message post will be converted from messageformat to FORMAT_HTML.\n var topreferredformat = true;\n var postid = form.elements.reply.value;\n var subject = form.elements.subject.value;\n var currentRoot = submitButton.closest(Selectors.post.post);\n var isprivatereply = form.elements.privatereply != undefined ? form.elements.privatereply.checked : false;\n var modeSelector = root.find(Selectors.post.modeSelect);\n var mode = modeSelector.length ? parseInt(modeSelector.get(0).value) : null;\n var newid;\n\n if (message.length) {\n showSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', true);\n\n Repository.addDiscussionPost(postid, subject, message, messageformat, isprivatereply, topreferredformat)\n .then(function(context) {\n var message = context.messages.reduce(function(carry, message) {\n if (message.type == 'success') {\n carry += '

' + message.message + '

';\n }\n return carry;\n }, '');\n Notification.addNotification({\n message: message,\n type: \"success\"\n });\n\n return context;\n })\n .then(function(context) {\n form.reset();\n var post = context.post;\n newid = post.id;\n\n switch (mode) {\n case DISPLAYCONSTANTS.NESTED_V2:\n var capabilities = post.capabilities;\n var currentAuthorName = currentRoot.children()\n .not(Selectors.post.repliesContainer)\n .find(Selectors.post.authorName)\n .text();\n post.parentauthorname = currentAuthorName;\n post.showactionmenu = capabilities.view ||\n capabilities.controlreadstatus ||\n capabilities.edit ||\n capabilities.split ||\n capabilities.delete ||\n capabilities.export ||\n post.urls.viewparent;\n return Templates.render('mod_forum/forum_discussion_nested_v2_post_reply', post);\n case DISPLAYCONSTANTS.THREADED:\n return Templates.render('mod_forum/forum_discussion_threaded_post', post);\n case DISPLAYCONSTANTS.NESTED:\n return Templates.render('mod_forum/forum_discussion_nested_post', post);\n default:\n return Templates.render('mod_forum/forum_discussion_post', post);\n }\n })\n .then(function(html, js) {\n var repliesnode = currentRoot.find(Selectors.post.repliesContainer).first();\n\n if (mode == DISPLAYCONSTANTS.FLAT_NEWEST_FIRST) {\n return Templates.prependNodeContents(repliesnode, html, js);\n } else {\n return Templates.appendNodeContents(repliesnode, html, js);\n }\n })\n .then(function() {\n submitButton.trigger(EVENTS.POST_CREATED, newid);\n hideSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', false);\n\n // Tell formchangechecker we submitted the form.\n FormChangeChecker.resetFormDirtyState(submitButton[0]);\n\n return currentRoot.find(Selectors.post.inpageReplyContent).hide();\n })\n .then(function() {\n location.href = \"#p\" + newid;\n\n // Reload the page, say if threshold is being set by user those would get reflected through the templates.\n location.reload();\n })\n .catch(function(error) {\n hideSubmitButtonLoadingIcon(submitButton);\n allButtons.prop('disabled', false);\n return Notification.exception(error);\n });\n }\n });\n };\n\n return {\n init: function(root) {\n registerEventListeners(root);\n },\n CONTENT_FORMATS: CONTENT_FORMATS,\n EVENTS: EVENTS\n };\n});\n"],"names":["define","$","Templates","Notification","Repository","Selectors","FormChangeChecker","DISPLAYCONSTANTS","EVENTS","POST_CREATED","CONTENT_FORMATS","MOODLE","hideSubmitButtonLoadingIcon","button","textContainer","find","post","inpageSubmitBtnText","loadingIconContainer","css","removeClass","addClass","registerEventListeners","root","on","inpageSubmitBtn","e","preventDefault","newid","width","submitButton","currentTarget","allButtons","parent","inpageReplyButton","form","parents","inpageReplyForm","get","message","elements","value","trim","messageformat","postid","reply","subject","currentRoot","closest","isprivatereply","undefined","privatereply","checked","modeSelector","modeSelect","mode","length","parseInt","outerWidth","prop","addDiscussionPost","then","context","messages","reduce","carry","type","addNotification","reset","id","capabilities","currentAuthorName","children","not","repliesContainer","authorName","text","parentauthorname","showactionmenu","view","controlreadstatus","edit","split","delete","export","urls","viewparent","render","html","js","repliesnode","first","prependNodeContents","appendNodeContents","trigger","resetFormDirtyState","inpageReplyContent","hide","location","href","reload","catch","error","exception","init"],"mappings":";;;;;;;AAsBAA,gCAAO,CACH,SACA,iBACA,oBACA,uBACA,sBACA,4BACD,SACCC,EACAC,UACAC,aACAC,WACAC,UACAC,uBAGIC,2BACW,EADXA,0BAEU,EAFVA,wBAGQ,EAHRA,oCAKoB,EAGpBC,OAAS,CACTC,aAAc,0BAOdC,gBAAkB,CAClBC,OAAQ,GAsBRC,4BAA8B,SAASC,YACnCC,cAAgBD,OAAOE,KAAKV,UAAUW,KAAKC,qBAC3CC,qBAAuBL,OAAOE,KAAKV,UAAUW,KAAKE,sBAEtDL,OAAOM,IAAI,QAAS,IACpBL,cAAcM,YAAY,UAC1BF,qBAAqBG,SAAS,WAQ9BC,uBAAyB,SAASC,MAClCA,KAAKC,GAAG,QAASnB,UAAUW,KAAKS,iBAAiB,SAASC,GACtDA,EAAEC,qBAgBEC,MA/C+Bf,OACnCC,cACAI,qBACAW,MA6BIC,aAAe7B,EAAEyB,EAAEK,eACnBC,WAAaF,aAAaG,SAASlB,KAAKV,UAAUW,KAAKkB,mBACvDC,KAAOL,aAAaM,QAAQ/B,UAAUW,KAAKqB,iBAAiBC,IAAI,GAChEC,QAAUJ,KAAKK,SAASxB,KAAKyB,MAAMC,OAGnCC,cAAgBjC,gBAAgBC,OAGhCiC,OAAST,KAAKK,SAASK,MAAMJ,MAC7BK,QAAUX,KAAKK,SAASM,QAAQL,MAChCM,YAAcjB,aAAakB,QAAQ3C,UAAUW,KAAKA,MAClDiC,eAA+CC,MAA9Bf,KAAKK,SAASW,cAA4BhB,KAAKK,SAASW,aAAaC,QACtFC,aAAe9B,KAAKR,KAAKV,UAAU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YAAaF,KAAMC,IAEjDvF,UAAU2F,mBAAmBH,YAAaF,KAAMC,OAG9D5B,MAAK,kBACF/B,aAAagE,QAAQtF,OAAOC,aAAcmB,OAC1ChB,4BAA4BkB,cAC5BE,WAAW2B,KAAK,YAAY,GAG5BrD,kBAAkByF,oBAAoBjE,aAAa,IAE5CiB,YAAYhC,KAAKV,UAAUW,KAAKgF,oBAAoBC,UAE9DpC,MAAK,WACFqC,SAASC,KAAO,KAAOvE,MAGvBsE,SAASE,YAEZC,OAAM,SAASC,cACZ1F,4BAA4BkB,cAC5BE,WAAW2B,KAAK,YAAY,GACrBxD,aAAaoG,UAAUD,qBAM3C,CACHE,KAAM,SAASjF,MACXD,uBAAuBC,OAE3Bb,gBAAiBA,gBACjBF,OAAQA"} \ No newline at end of file diff --git a/mod/forum/amd/build/posts_list.min.js b/mod/forum/amd/build/posts_list.min.js index d0ad0b9d2ed..63f1f87160f 100644 --- a/mod/forum/amd/build/posts_list.min.js +++ b/mod/forum/amd/build/posts_list.min.js @@ -9,6 +9,6 @@ * @copyright 2019 Peter Dias * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_forum/posts_list",["jquery","core/templates","core/notification","core/pending","mod_forum/selectors","mod_forum/inpage_reply","core_form/changechecker"],(function($,Templates,Notification,Pending,Selectors,InPageReply,FormChangeChecker){return{init:function(root){!function(root){root.on("click",Selectors.post.inpageReplyLink,(function(e){if(e.preventDefault(),window.location.hash){var url=window.location.href.split("#")[0];history.pushState({},document.title,url)}var pending=new Pending("inpage-reply"),currentTarget=$(e.currentTarget).parents(Selectors.post.forumCoreContent),currentSubject=currentTarget.find(Selectors.post.forumSubject),currentRoot=$(e.currentTarget).parents(Selectors.post.forumContent),context={postid:$(currentRoot).data("post-id"),reply_url:$(e.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:currentSubject.data("replySubject"),canreplyprivately:$(e.currentTarget).data("can-reply-privately"),postformat:InPageReply.CONTENT_FORMATS.MOODLE};if(currentRoot.find(Selectors.post.inpageReplyContent).length){var form=currentRoot.find(Selectors.post.inpageReplyContent);form.slideToggle(300,pending.resolve),form.is(":visible")&&form.find("textarea").focus()}else Templates.render("mod_forum/inpage_reply",context).then((function(html,js){return Templates.appendNodeContents(currentTarget,html,js)})).then((function(){return currentRoot.find(Selectors.post.inpageReplyContent).slideToggle(300,pending.resolve).find("textarea").focus()})).then((function(){FormChangeChecker.watchFormById("inpage-reply-".concat(context.postid))})).catch(Notification.exception)}))}(root),InPageReply.init(root)}}})); +define("mod_forum/posts_list",["jquery","core/templates","core/notification","core/pending","mod_forum/selectors","mod_forum/inpage_reply","core_form/changechecker"],(function($,Templates,Notification,Pending,Selectors,InPageReply,FormChangeChecker){return{init:function(root,throttlingwarningmsg){!function(root,throttlingwarningmsg){root.on("click",Selectors.post.inpageReplyLink,(function(e){if(e.preventDefault(),window.location.hash){var url=window.location.href.split("#")[0];history.pushState({},document.title,url)}var pending=new Pending("inpage-reply"),currentTarget=$(e.currentTarget).parents(Selectors.post.forumCoreContent),currentSubject=currentTarget.find(Selectors.post.forumSubject),currentRoot=$(e.currentTarget).parents(Selectors.post.forumContent),context={postid:$(currentRoot).data("post-id"),reply_url:$(e.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:currentSubject.data("replySubject"),canreplyprivately:$(e.currentTarget).data("can-reply-privately"),postformat:InPageReply.CONTENT_FORMATS.MOODLE,throttlingwarningmsg:throttlingwarningmsg};if(currentRoot.find(Selectors.post.inpageReplyContent).length){var form=currentRoot.find(Selectors.post.inpageReplyContent);form.slideToggle(300,pending.resolve),form.is(":visible")&&form.find("textarea").focus()}else Templates.render("mod_forum/inpage_reply",context).then((function(html,js){return Templates.appendNodeContents(currentTarget,html,js)})).then((function(){return currentRoot.find(Selectors.post.inpageReplyContent).slideToggle(300,pending.resolve).find("textarea").focus()})).then((function(){FormChangeChecker.watchFormById("inpage-reply-".concat(context.postid))})).catch(Notification.exception)}))}(root,throttlingwarningmsg),InPageReply.init(root)}}})); //# sourceMappingURL=posts_list.min.js.map \ No newline at end of file diff --git a/mod/forum/amd/build/posts_list.min.js.map b/mod/forum/amd/build/posts_list.min.js.map index 5859541c1c1..f33d30b38d3 100644 --- a/mod/forum/amd/build/posts_list.min.js.map +++ b/mod/forum/amd/build/posts_list.min.js.map @@ -1 +1 @@ -{"version":3,"file":"posts_list.min.js","sources":["../src/posts_list.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module is the highest level module for the calendar. It is\n * responsible for initialising all of the components required for\n * the calendar to run. It also coordinates the interaction between\n * components by listening for and responding to different events\n * triggered within the calendar UI.\n *\n * @module mod_forum/posts_list\n * @copyright 2019 Peter Dias\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/pending',\n 'mod_forum/selectors',\n 'mod_forum/inpage_reply',\n 'core_form/changechecker',\n], function(\n $,\n Templates,\n Notification,\n Pending,\n Selectors,\n InPageReply,\n FormChangeChecker\n) {\n\n var registerEventListeners = function(root) {\n root.on('click', Selectors.post.inpageReplyLink, function(e) {\n e.preventDefault();\n // After adding a reply a url hash is being generated that scrolls (points) to the newly added reply.\n // The hash being present causes this scrolling behavior to the particular reply to persists even when\n // another, non-related in-page replay link is being clicked which ultimately causes a bad user experience.\n // A particular solution for this problem would be changing the browser's history state when a url hash is\n // present.\n if (window.location.hash) {\n // Remove the fragment identifier from the url.\n var url = window.location.href.split('#')[0];\n history.pushState({}, document.title, url);\n }\n var pending = new Pending('inpage-reply');\n var currentTarget = $(e.currentTarget).parents(Selectors.post.forumCoreContent);\n var currentSubject = currentTarget.find(Selectors.post.forumSubject);\n var currentRoot = $(e.currentTarget).parents(Selectors.post.forumContent);\n var context = {\n postid: $(currentRoot).data('post-id'),\n \"reply_url\": $(e.currentTarget).attr('href'),\n sesskey: M.cfg.sesskey,\n parentsubject: currentSubject.data('replySubject'),\n canreplyprivately: $(e.currentTarget).data('can-reply-privately'),\n postformat: InPageReply.CONTENT_FORMATS.MOODLE\n };\n\n if (!currentRoot.find(Selectors.post.inpageReplyContent).length) {\n Templates.render('mod_forum/inpage_reply', context)\n .then(function(html, js) {\n return Templates.appendNodeContents(currentTarget, html, js);\n })\n .then(function() {\n return currentRoot.find(Selectors.post.inpageReplyContent)\n .slideToggle(300, pending.resolve).find('textarea').focus();\n })\n .then(function() {\n FormChangeChecker.watchFormById(`inpage-reply-${context.postid}`);\n return;\n })\n .catch(Notification.exception);\n } else {\n var form = currentRoot.find(Selectors.post.inpageReplyContent);\n form.slideToggle(300, pending.resolve);\n if (form.is(':visible')) {\n form.find('textarea').focus();\n }\n }\n });\n };\n\n return {\n init: function(root) {\n registerEventListeners(root);\n InPageReply.init(root);\n }\n };\n});\n"],"names":["define","$","Templates","Notification","Pending","Selectors","InPageReply","FormChangeChecker","init","root","on","post","inpageReplyLink","e","preventDefault","window","location","hash","url","href","split","history","pushState","document","title","pending","currentTarget","parents","forumCoreContent","currentSubject","find","forumSubject","currentRoot","forumContent","context","postid","data","attr","sesskey","M","cfg","parentsubject","canreplyprivately","postformat","CONTENT_FORMATS","MOODLE","inpageReplyContent","length","form","slideToggle","resolve","is","focus","render","then","html","js","appendNodeContents","watchFormById","catch","exception","registerEventListeners"],"mappings":";;;;;;;;;;;AA0BAA,8BAAO,CACH,SACA,iBACA,oBACA,eACA,sBACA,yBACA,4BACD,SACCC,EACAC,UACAC,aACAC,QACAC,UACAC,YACAC,yBAqDO,CACHC,KAAM,SAASC,OAnDU,SAASA,MAClCA,KAAKC,GAAG,QAASL,UAAUM,KAAKC,iBAAiB,SAASC,MACtDA,EAAEC,iBAMEC,OAAOC,SAASC,KAAM,KAElBC,IAAMH,OAAOC,SAASG,KAAKC,MAAM,KAAK,GAC1CC,QAAQC,UAAU,GAAIC,SAASC,MAAON,SAEtCO,QAAU,IAAIrB,QAAQ,gBACtBsB,cAAgBzB,EAAEY,EAAEa,eAAeC,QAAQtB,UAAUM,KAAKiB,kBAC1DC,eAAiBH,cAAcI,KAAKzB,UAAUM,KAAKoB,cACnDC,YAAc/B,EAAEY,EAAEa,eAAeC,QAAQtB,UAAUM,KAAKsB,cACxDC,QAAU,CACVC,OAAQlC,EAAE+B,aAAaI,KAAK,qBACfnC,EAAEY,EAAEa,eAAeW,KAAK,QACrCC,QAASC,EAAEC,IAAIF,QACfG,cAAeZ,eAAeO,KAAK,gBACnCM,kBAAmBzC,EAAEY,EAAEa,eAAeU,KAAK,uBAC3CO,WAAYrC,YAAYsC,gBAAgBC,WAGvCb,YAAYF,KAAKzB,UAAUM,KAAKmC,oBAAoBC,OAclD,KACCC,KAAOhB,YAAYF,KAAKzB,UAAUM,KAAKmC,oBAC3CE,KAAKC,YAAY,IAAKxB,QAAQyB,SAC1BF,KAAKG,GAAG,aACRH,KAAKlB,KAAK,YAAYsB,aAjB1BlD,UAAUmD,OAAO,yBAA0BnB,SACtCoB,MAAK,SAASC,KAAMC,WACVtD,UAAUuD,mBAAmB/B,cAAe6B,KAAMC,OAE5DF,MAAK,kBACKtB,YAAYF,KAAKzB,UAAUM,KAAKmC,oBAClCG,YAAY,IAAKxB,QAAQyB,SAASpB,KAAK,YAAYsB,WAE3DE,MAAK,WACF/C,kBAAkBmD,qCAA8BxB,QAAQC,YAG3DwB,MAAMxD,aAAayD,cAa5BC,CAAuBpD,MACvBH,YAAYE,KAAKC"} \ No newline at end of file +{"version":3,"file":"posts_list.min.js","sources":["../src/posts_list.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module is the highest level module for the calendar. It is\n * responsible for initialising all of the components required for\n * the calendar to run. It also coordinates the interaction between\n * components by listening for and responding to different events\n * triggered within the calendar UI.\n *\n * @module mod_forum/posts_list\n * @copyright 2019 Peter Dias\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/notification',\n 'core/pending',\n 'mod_forum/selectors',\n 'mod_forum/inpage_reply',\n 'core_form/changechecker',\n], function(\n $,\n Templates,\n Notification,\n Pending,\n Selectors,\n InPageReply,\n FormChangeChecker\n) {\n\n var registerEventListeners = function(root, throttlingwarningmsg) {\n root.on('click', Selectors.post.inpageReplyLink, function(e) {\n e.preventDefault();\n // After adding a reply a url hash is being generated that scrolls (points) to the newly added reply.\n // The hash being present causes this scrolling behavior to the particular reply to persists even when\n // another, non-related in-page replay link is being clicked which ultimately causes a bad user experience.\n // A particular solution for this problem would be changing the browser's history state when a url hash is\n // present.\n if (window.location.hash) {\n // Remove the fragment identifier from the url.\n var url = window.location.href.split('#')[0];\n history.pushState({}, document.title, url);\n }\n var pending = new Pending('inpage-reply');\n var currentTarget = $(e.currentTarget).parents(Selectors.post.forumCoreContent);\n var currentSubject = currentTarget.find(Selectors.post.forumSubject);\n var currentRoot = $(e.currentTarget).parents(Selectors.post.forumContent);\n var context = {\n postid: $(currentRoot).data('post-id'),\n \"reply_url\": $(e.currentTarget).attr('href'),\n sesskey: M.cfg.sesskey,\n parentsubject: currentSubject.data('replySubject'),\n canreplyprivately: $(e.currentTarget).data('can-reply-privately'),\n postformat: InPageReply.CONTENT_FORMATS.MOODLE,\n throttlingwarningmsg: throttlingwarningmsg\n };\n\n if (!currentRoot.find(Selectors.post.inpageReplyContent).length) {\n Templates.render('mod_forum/inpage_reply', context)\n .then(function(html, js) {\n return Templates.appendNodeContents(currentTarget, html, js);\n })\n .then(function() {\n return currentRoot.find(Selectors.post.inpageReplyContent)\n .slideToggle(300, pending.resolve).find('textarea').focus();\n })\n .then(function() {\n FormChangeChecker.watchFormById(`inpage-reply-${context.postid}`);\n return;\n })\n .catch(Notification.exception);\n } else {\n var form = currentRoot.find(Selectors.post.inpageReplyContent);\n form.slideToggle(300, pending.resolve);\n if (form.is(':visible')) {\n form.find('textarea').focus();\n }\n }\n });\n };\n\n return {\n init: function(root, throttlingwarningmsg) {\n registerEventListeners(root, throttlingwarningmsg);\n InPageReply.init(root);\n }\n };\n});\n"],"names":["define","$","Templates","Notification","Pending","Selectors","InPageReply","FormChangeChecker","init","root","throttlingwarningmsg","on","post","inpageReplyLink","e","preventDefault","window","location","hash","url","href","split","history","pushState","document","title","pending","currentTarget","parents","forumCoreContent","currentSubject","find","forumSubject","currentRoot","forumContent","context","postid","data","attr","sesskey","M","cfg","parentsubject","canreplyprivately","postformat","CONTENT_FORMATS","MOODLE","inpageReplyContent","length","form","slideToggle","resolve","is","focus","render","then","html","js","appendNodeContents","watchFormById","catch","exception","registerEventListeners"],"mappings":";;;;;;;;;;;AA0BAA,8BAAO,CACH,SACA,iBACA,oBACA,eACA,sBACA,yBACA,4BACD,SACCC,EACAC,UACAC,aACAC,QACAC,UACAC,YACAC,yBAsDO,CACHC,KAAM,SAASC,KAAMC,uBApDI,SAASD,KAAMC,sBACxCD,KAAKE,GAAG,QAASN,UAAUO,KAAKC,iBAAiB,SAASC,MACtDA,EAAEC,iBAMEC,OAAOC,SAASC,KAAM,KAElBC,IAAMH,OAAOC,SAASG,KAAKC,MAAM,KAAK,GAC1CC,QAAQC,UAAU,GAAIC,SAASC,MAAON,SAEtCO,QAAU,IAAItB,QAAQ,gBACtBuB,cAAgB1B,EAAEa,EAAEa,eAAeC,QAAQvB,UAAUO,KAAKiB,kBAC1DC,eAAiBH,cAAcI,KAAK1B,UAAUO,KAAKoB,cACnDC,YAAchC,EAAEa,EAAEa,eAAeC,QAAQvB,UAAUO,KAAKsB,cACxDC,QAAU,CACVC,OAAQnC,EAAEgC,aAAaI,KAAK,qBACfpC,EAAEa,EAAEa,eAAeW,KAAK,QACrCC,QAASC,EAAEC,IAAIF,QACfG,cAAeZ,eAAeO,KAAK,gBACnCM,kBAAmB1C,EAAEa,EAAEa,eAAeU,KAAK,uBAC3CO,WAAYtC,YAAYuC,gBAAgBC,OACxCpC,qBAAsBA,yBAGrBuB,YAAYF,KAAK1B,UAAUO,KAAKmC,oBAAoBC,OAclD,KACCC,KAAOhB,YAAYF,KAAK1B,UAAUO,KAAKmC,oBAC3CE,KAAKC,YAAY,IAAKxB,QAAQyB,SAC1BF,KAAKG,GAAG,aACRH,KAAKlB,KAAK,YAAYsB,aAjB1BnD,UAAUoD,OAAO,yBAA0BnB,SACtCoB,MAAK,SAASC,KAAMC,WACVvD,UAAUwD,mBAAmB/B,cAAe6B,KAAMC,OAE5DF,MAAK,kBACKtB,YAAYF,KAAK1B,UAAUO,KAAKmC,oBAClCG,YAAY,IAAKxB,QAAQyB,SAASpB,KAAK,YAAYsB,WAE3DE,MAAK,WACFhD,kBAAkBoD,qCAA8BxB,QAAQC,YAG3DwB,MAAMzD,aAAa0D,cAa5BC,CAAuBrD,KAAMC,sBAC7BJ,YAAYE,KAAKC"} \ 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 2133840663a..0a817653456 100644 --- a/mod/forum/amd/src/inpage_reply.js +++ b/mod/forum/amd/src/inpage_reply.js @@ -178,7 +178,9 @@ define([ }) .then(function() { location.href = "#p" + newid; - return; + + // Reload the page, say if threshold is being set by user those would get reflected through the templates. + location.reload(); }) .catch(function(error) { hideSubmitButtonLoadingIcon(submitButton); diff --git a/mod/forum/amd/src/posts_list.js b/mod/forum/amd/src/posts_list.js index 83de16840b7..3024fa70ddd 100644 --- a/mod/forum/amd/src/posts_list.js +++ b/mod/forum/amd/src/posts_list.js @@ -42,7 +42,7 @@ define([ FormChangeChecker ) { - var registerEventListeners = function(root) { + var registerEventListeners = function(root, throttlingwarningmsg) { root.on('click', Selectors.post.inpageReplyLink, function(e) { e.preventDefault(); // After adding a reply a url hash is being generated that scrolls (points) to the newly added reply. @@ -65,7 +65,8 @@ define([ sesskey: M.cfg.sesskey, parentsubject: currentSubject.data('replySubject'), canreplyprivately: $(e.currentTarget).data('can-reply-privately'), - postformat: InPageReply.CONTENT_FORMATS.MOODLE + postformat: InPageReply.CONTENT_FORMATS.MOODLE, + throttlingwarningmsg: throttlingwarningmsg }; if (!currentRoot.find(Selectors.post.inpageReplyContent).length) { @@ -93,8 +94,8 @@ define([ }; return { - init: function(root) { - registerEventListeners(root); + init: function(root, throttlingwarningmsg) { + registerEventListeners(root, throttlingwarningmsg); InPageReply.init(root); } }; diff --git a/mod/forum/classes/local/managers/capability.php b/mod/forum/classes/local/managers/capability.php index b5304b1679b..5e440fb06db 100644 --- a/mod/forum/classes/local/managers/capability.php +++ b/mod/forum/classes/local/managers/capability.php @@ -119,6 +119,11 @@ class capability { } } + // If the user reaches the number of posts equal to warning/blocking setting then return the value of canpost in $warningobj. + if ($warningobj = forum_check_throttling($this->forumrecord)) { + return $warningobj->canpost; + } + switch ($this->forum->get_type()) { case 'news': $capability = 'mod/forum:addnews'; @@ -316,12 +321,19 @@ class capability { public function can_post_in_discussion(stdClass $user, discussion_entity $discussion) : bool { $forum = $this->get_forum(); $forumrecord = $this->get_forum_record(); + $discussionrecord = $this->get_discussion_record($discussion); $context = $this->get_context(); $coursemodule = $forum->get_course_module_record(); $course = $forum->get_course_record(); - return forum_user_can_post($forumrecord, $discussionrecord, $user, $coursemodule, $course, $context); + $status = forum_user_can_post($forumrecord, $discussionrecord, $user, $coursemodule, $course, $context); + + // If the user reaches the number of posts equal to warning/blocking setting then logically and canpost value with $status. + if ($warningobj = forum_check_throttling($forumrecord)) { + return $status && $warningobj->canpost; + } + return $status; } /** diff --git a/mod/forum/classes/local/renderers/discussion.php b/mod/forum/classes/local/renderers/discussion.php index 9b659b9f9d5..2ed95e04bec 100644 --- a/mod/forum/classes/local/renderers/discussion.php +++ b/mod/forum/classes/local/renderers/discussion.php @@ -235,6 +235,14 @@ class discussion { ]; } + $exporteddiscussion['throttlingwarningmsg'] = ''; + if (($warningobj = forum_check_throttling($this->forumrecord)) && $warningobj->canpost) { + $throttlewarnnotification = (new notification( + get_string($warningobj->errorcode, $warningobj->module, $warningobj->additional) + ))->set_show_closebutton(); + $exporteddiscussion['throttlingwarningmsg'] = $throttlewarnnotification->get_message(); + } + if ($this->displaymode === FORUM_MODE_NESTED_V2) { $template = 'mod_forum/forum_discussion_nested_v2'; } else { @@ -429,6 +437,7 @@ class discussion { 'blockperiod' => get_string('secondstotime' . $forum->get_block_period()) ]) ))->set_show_closebutton(); + } return array_map(function($notification) { diff --git a/mod/forum/templates/forum_discussion.mustache b/mod/forum/templates/forum_discussion.mustache index 2ae6d025703..f3e05a31f69 100644 --- a/mod/forum/templates/forum_discussion.mustache +++ b/mod/forum/templates/forum_discussion.mustache @@ -27,6 +27,17 @@ Example context (json): { + "html": { + "hasanyactions": true, + "posts": "
", + "modeselectorform": "
", + "subscribe": null, + "movediscussion": null, + "pindiscussion": null, + "neighbourlinks": "
", + "exportdiscussion": null + }, + "throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts." } }} @@ -78,7 +89,7 @@ function( ) { var root = $("[data-content='forum-discussion']"); Discussion.init(root); - PostsList.init(root); + PostsList.init(root, {{#quote}}{{throttlingwarningmsg}}{{/quote}}); root = $('[data-container="discussion-tools"]'); LockToggle.init(root, true); FavouriteToggle.init(root, true, function(toggleElement, context) { diff --git a/mod/forum/templates/forum_discussion_nested_v2.mustache b/mod/forum/templates/forum_discussion_nested_v2.mustache index 90b36f972d5..f69f5d651e5 100644 --- a/mod/forum/templates/forum_discussion_nested_v2.mustache +++ b/mod/forum/templates/forum_discussion_nested_v2.mustache @@ -27,6 +27,17 @@ Example context (json): { + "html": { + "hasanyactions": true, + "posts": "
", + "modeselectorform": "
", + "subscribe": null, + "movediscussion": null, + "pindiscussion": null, + "neighbourlinks": "
", + "exportdiscussion": null + }, + "throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts." } }} @@ -47,6 +58,9 @@ require(['jquery', 'mod_forum/discussion_nested_v2'], function($, Discussion) { var root = $('#discussion-container-{{uniqid}}'); Discussion.init(root, { + {{#throttlingwarningmsg}} + throttlingwarningmsg: {{#quote}}{{throttlingwarningmsg}}{{/quote}}, + {{/throttlingwarningmsg}} {{#loggedinuser}} loggedinuser: { profileimageurl: '{{{profileimageurl}}}', diff --git a/mod/forum/templates/inpage_reply.mustache b/mod/forum/templates/inpage_reply.mustache index 0a6a2d3582f..c1250899f69 100644 --- a/mod/forum/templates/inpage_reply.mustache +++ b/mod/forum/templates/inpage_reply.mustache @@ -30,11 +30,17 @@ "postid": 0, "reply_url": "", "sesskey": "", - "parentsubject": "" + "parentsubject": "", + "throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts." } }}