diff --git a/mod/forum/amd/build/discussion_list.min.js b/mod/forum/amd/build/discussion_list.min.js index 5cd9d474bb6..858e5967c24 100644 --- a/mod/forum/amd/build/discussion_list.min.js +++ b/mod/forum/amd/build/discussion_list.min.js @@ -5,6 +5,6 @@ * @copyright 2019 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("mod_forum/discussion_list",["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository","core/pubsub","mod_forum/forum_events"],(function($,Templates,Str,Notification,SubscriptionToggle,Selectors,Repository,PubSub,ForumEvents){return{init:function(root){SubscriptionToggle.init(root,!1,(function(toggleElement,context){var toggleId=toggleElement.attr("id"),newTargetState=context.userstate.subscribed?0:1;toggleElement.data("targetstate",newTargetState);var stringKey=context.userstate.subscribed?"unsubscribediscussion":"subscribediscussion";return Str.get_string(stringKey,"mod_forum").then((function(string){return toggleElement.closest("td").find('label[for="'+toggleId+'"]').find("span").text(string),string}))})),function(root){PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED,(function(data){var discussionId=data.discussionId,subscribed=data.subscriptionState,discussionListItem=root.find(Selectors.discussion.item+"[data-discussionid= "+discussionId+"]"),subscribedLabel=discussionListItem.find(Selectors.discussion.subscribedLabel);subscribed?(discussionListItem.addClass("subscribed"),subscribedLabel.removeAttr("hidden")):(discussionListItem.removeClass("subscribed"),subscribedLabel.attr("hidden",!0))})),root.on("click",Selectors.post.inpageCancelButton,(function(){void 0!==M.core_formchangechecker&&M.core_formchangechecker.reset_form_dirty_state()})),root.on("click",Selectors.favourite.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),subscriptionState=toggleElement.data("targetstate");Repository.setFavouriteDiscussionState(forumId,discussionId,subscriptionState).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.pin.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("targetstate");Repository.setPinDiscussionState(forumId,discussionId,state).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.lock.toggle,(function(e){var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("state");Repository.setDiscussionLockState(forumId,discussionId,state).then((function(context){var icon=toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon),lockedLabel=toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);return context.locked?(icon.removeClass("hidden"),lockedLabel.removeAttr("hidden")):(icon.addClass("hidden"),lockedLabel.attr("hidden",!0)),context})).then((function(context){return context.forumid=forumId,Templates.render("mod_forum/discussion_lock_toggle",context)})).then((function(html,js){return Templates.replaceNode(toggleElement,html,js)})).then((function(){return Str.get_string("lockupdated","forum").done((function(s){return Notification.addNotification({message:s,type:"info"})}))})).catch(Notification.exception),e.preventDefault()}))}(root)}}})); +define("mod_forum/discussion_list",["jquery","core/templates","core/str","core/notification","mod_forum/subscription_toggle","mod_forum/selectors","mod_forum/repository","core/pubsub","mod_forum/forum_events","core_form/changechecker"],(function($,Templates,Str,Notification,SubscriptionToggle,Selectors,Repository,PubSub,ForumEvents,FormChangeChecker){return{init:function(root){SubscriptionToggle.init(root,!1,(function(toggleElement,context){var toggleId=toggleElement.attr("id"),newTargetState=context.userstate.subscribed?0:1;toggleElement.data("targetstate",newTargetState);var stringKey=context.userstate.subscribed?"unsubscribediscussion":"subscribediscussion";return Str.get_string(stringKey,"mod_forum").then((function(string){return toggleElement.closest("td").find('label[for="'+toggleId+'"]').find("span").text(string),string}))})),function(root){PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED,(function(data){var discussionId=data.discussionId,subscribed=data.subscriptionState,discussionListItem=root.find(Selectors.discussion.item+"[data-discussionid= "+discussionId+"]"),subscribedLabel=discussionListItem.find(Selectors.discussion.subscribedLabel);subscribed?(discussionListItem.addClass("subscribed"),subscribedLabel.removeAttr("hidden")):(discussionListItem.removeClass("subscribed"),subscribedLabel.attr("hidden",!0))})),root.on("click",Selectors.post.inpageCancelButton,(function(e){FormChangeChecker.resetFormDirtyState(e.currentTarget)})),root.on("click",Selectors.favourite.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),subscriptionState=toggleElement.data("targetstate");Repository.setFavouriteDiscussionState(forumId,discussionId,subscriptionState).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.pin.toggle,(function(e){e.preventDefault();var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("targetstate");Repository.setPinDiscussionState(forumId,discussionId,state).then((function(){return location.reload()})).catch(Notification.exception)})),root.on("click",Selectors.lock.toggle,(function(e){var toggleElement=$(this),forumId=toggleElement.data("forumid"),discussionId=toggleElement.data("discussionid"),state=toggleElement.data("state");Repository.setDiscussionLockState(forumId,discussionId,state).then((function(context){var icon=toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon),lockedLabel=toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);return context.locked?(icon.removeClass("hidden"),lockedLabel.removeAttr("hidden")):(icon.addClass("hidden"),lockedLabel.attr("hidden",!0)),context})).then((function(context){return context.forumid=forumId,Templates.render("mod_forum/discussion_lock_toggle",context)})).then((function(html,js){return Templates.replaceNode(toggleElement,html,js)})).then((function(){return Str.get_string("lockupdated","forum").done((function(s){return Notification.addNotification({message:s,type:"info"})}))})).catch(Notification.exception),e.preventDefault()}))}(root)}}})); //# sourceMappingURL=discussion_list.min.js.map \ No newline at end of file diff --git a/mod/forum/amd/build/discussion_list.min.js.map b/mod/forum/amd/build/discussion_list.min.js.map index eac4c3ab170..93dcd8126e2 100644 --- a/mod/forum/amd/build/discussion_list.min.js.map +++ b/mod/forum/amd/build/discussion_list.min.js.map @@ -1 +1 @@ -{"version":3,"file":"discussion_list.min.js","sources":["../src/discussion_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 * Module for the list of discussions on when viewing a forum.\n *\n * @module mod_forum/discussion_list\n * @copyright 2019 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/str',\n 'core/notification',\n 'mod_forum/subscription_toggle',\n 'mod_forum/selectors',\n 'mod_forum/repository',\n 'core/pubsub',\n 'mod_forum/forum_events',\n], function(\n $,\n Templates,\n Str,\n Notification,\n SubscriptionToggle,\n Selectors,\n Repository,\n PubSub,\n ForumEvents\n) {\n var registerEventListeners = function(root) {\n PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED, function(data) {\n var discussionId = data.discussionId;\n var subscribed = data.subscriptionState;\n var discussionListItem = root.find(Selectors.discussion.item + '[data-discussionid= ' + discussionId + ']');\n var subscribedLabel = discussionListItem.find(Selectors.discussion.subscribedLabel);\n if (subscribed) {\n discussionListItem.addClass('subscribed');\n subscribedLabel.removeAttr('hidden');\n } else {\n discussionListItem.removeClass('subscribed');\n subscribedLabel.attr('hidden', true);\n }\n });\n\n root.on('click', Selectors.post.inpageCancelButton, function() {\n // Tell formchangechecker to reset the form state.\n if (typeof M.core_formchangechecker !== 'undefined') {\n M.core_formchangechecker.reset_form_dirty_state();\n }\n });\n\n root.on('click', Selectors.favourite.toggle, function(e) {\n e.preventDefault();\n\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var subscriptionState = toggleElement.data('targetstate');\n Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)\n .then(function() {\n return location.reload();\n })\n .catch(Notification.exception);\n });\n\n root.on('click', Selectors.pin.toggle, function(e) {\n e.preventDefault();\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var state = toggleElement.data('targetstate');\n Repository.setPinDiscussionState(forumId, discussionId, state)\n .then(function() {\n return location.reload();\n })\n .catch(Notification.exception);\n });\n\n root.on('click', Selectors.lock.toggle, function(e) {\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var state = toggleElement.data('state');\n\n Repository.setDiscussionLockState(forumId, discussionId, state)\n .then(function(context) {\n var icon = toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon);\n var lockedLabel = toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);\n if (context.locked) {\n icon.removeClass('hidden');\n lockedLabel.removeAttr('hidden');\n } else {\n icon.addClass('hidden');\n lockedLabel.attr('hidden', true);\n }\n return context;\n })\n .then(function(context) {\n context.forumid = forumId;\n return Templates.render('mod_forum/discussion_lock_toggle', context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(toggleElement, html, js);\n })\n .then(function() {\n return Str.get_string('lockupdated', 'forum')\n .done(function(s) {\n return Notification.addNotification({\n message: s,\n type: \"info\"\n });\n });\n })\n .catch(Notification.exception);\n\n e.preventDefault();\n });\n };\n\n return {\n init: function(root) {\n SubscriptionToggle.init(root, false, function(toggleElement, context) {\n var toggleId = toggleElement.attr('id');\n var newTargetState = context.userstate.subscribed ? 0 : 1;\n toggleElement.data('targetstate', newTargetState);\n\n var stringKey = context.userstate.subscribed ? 'unsubscribediscussion' : 'subscribediscussion';\n return Str.get_string(stringKey, 'mod_forum')\n .then(function(string) {\n toggleElement.closest('td').find('label[for=\"' + toggleId + '\"]').find('span').text(string);\n return string;\n });\n });\n registerEventListeners(root);\n }\n };\n});\n"],"names":["define","$","Templates","Str","Notification","SubscriptionToggle","Selectors","Repository","PubSub","ForumEvents","init","root","toggleElement","context","toggleId","attr","newTargetState","userstate","subscribed","data","stringKey","get_string","then","string","closest","find","text","subscribe","SUBSCRIPTION_TOGGLED","discussionId","subscriptionState","discussionListItem","discussion","item","subscribedLabel","addClass","removeAttr","removeClass","on","post","inpageCancelButton","M","core_formchangechecker","reset_form_dirty_state","favourite","toggle","e","preventDefault","this","forumId","setFavouriteDiscussionState","location","reload","catch","exception","pin","state","setPinDiscussionState","lock","setDiscussionLockState","icon","parents","summary","actions","lockedLabel","locked","forumid","render","html","js","replaceNode","done","s","addNotification","message","type","registerEventListeners"],"mappings":";;;;;;;AAsBAA,mCAAO,CACH,SACA,iBACA,WACA,oBACA,gCACA,sBACA,uBACA,cACA,2BACD,SACCC,EACAC,UACAC,IACAC,aACAC,mBACAC,UACAC,WACAC,OACAC,mBA4FO,CACHC,KAAM,SAASC,MACXN,mBAAmBK,KAAKC,MAAM,GAAO,SAASC,cAAeC,aACrDC,SAAWF,cAAcG,KAAK,MAC9BC,eAAiBH,QAAQI,UAAUC,WAAa,EAAI,EACxDN,cAAcO,KAAK,cAAeH,oBAE9BI,UAAYP,QAAQI,UAAUC,WAAa,wBAA0B,6BAClEf,IAAIkB,WAAWD,UAAW,aAC5BE,MAAK,SAASC,eACXX,cAAcY,QAAQ,MAAMC,KAAK,cAAgBX,SAAW,MAAMW,KAAK,QAAQC,KAAKH,QAC7EA,aArGE,SAASZ,MAClCH,OAAOmB,UAAUlB,YAAYmB,sBAAsB,SAAST,UACpDU,aAAeV,KAAKU,aACpBX,WAAaC,KAAKW,kBAClBC,mBAAqBpB,KAAKc,KAAKnB,UAAU0B,WAAWC,KAAO,uBAAyBJ,aAAe,KACnGK,gBAAkBH,mBAAmBN,KAAKnB,UAAU0B,WAAWE,iBAC/DhB,YACAa,mBAAmBI,SAAS,cAC5BD,gBAAgBE,WAAW,YAE3BL,mBA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BF,WAEVS,MAAK,SAAST,gBACXA,QAAQqD,QAAUjB,QACX/C,UAAUiE,OAAO,mCAAoCtD,YAE/DS,MAAK,SAAS8C,KAAMC,WACVnE,UAAUoE,YAAY1D,cAAewD,KAAMC,OAErD/C,MAAK,kBACKnB,IAAIkB,WAAW,cAAe,SAChCkD,MAAK,SAASC,UACJpE,aAAaqE,gBAAgB,CAChCC,QAASF,EACTG,KAAM,eAIrBtB,MAAMjD,aAAakD,WAExBR,EAAEC,oBAkBF6B,CAAuBjE"} \ No newline at end of file +{"version":3,"file":"discussion_list.min.js","sources":["../src/discussion_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 * Module for the list of discussions on when viewing a forum.\n *\n * @module mod_forum/discussion_list\n * @copyright 2019 Andrew Nicols \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/templates',\n 'core/str',\n 'core/notification',\n 'mod_forum/subscription_toggle',\n 'mod_forum/selectors',\n 'mod_forum/repository',\n 'core/pubsub',\n 'mod_forum/forum_events',\n 'core_form/changechecker',\n], function(\n $,\n Templates,\n Str,\n Notification,\n SubscriptionToggle,\n Selectors,\n Repository,\n PubSub,\n ForumEvents,\n FormChangeChecker\n) {\n var registerEventListeners = function(root) {\n PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED, function(data) {\n var discussionId = data.discussionId;\n var subscribed = data.subscriptionState;\n var discussionListItem = root.find(Selectors.discussion.item + '[data-discussionid= ' + discussionId + ']');\n var subscribedLabel = discussionListItem.find(Selectors.discussion.subscribedLabel);\n if (subscribed) {\n discussionListItem.addClass('subscribed');\n subscribedLabel.removeAttr('hidden');\n } else {\n discussionListItem.removeClass('subscribed');\n subscribedLabel.attr('hidden', true);\n }\n });\n\n root.on('click', Selectors.post.inpageCancelButton, function(e) {\n // Tell formchangechecker to reset the form state.\n FormChangeChecker.resetFormDirtyState(e.currentTarget);\n });\n\n root.on('click', Selectors.favourite.toggle, function(e) {\n e.preventDefault();\n\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var subscriptionState = toggleElement.data('targetstate');\n Repository.setFavouriteDiscussionState(forumId, discussionId, subscriptionState)\n .then(function() {\n return location.reload();\n })\n .catch(Notification.exception);\n });\n\n root.on('click', Selectors.pin.toggle, function(e) {\n e.preventDefault();\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var state = toggleElement.data('targetstate');\n Repository.setPinDiscussionState(forumId, discussionId, state)\n .then(function() {\n return location.reload();\n })\n .catch(Notification.exception);\n });\n\n root.on('click', Selectors.lock.toggle, function(e) {\n var toggleElement = $(this);\n var forumId = toggleElement.data('forumid');\n var discussionId = toggleElement.data('discussionid');\n var state = toggleElement.data('state');\n\n Repository.setDiscussionLockState(forumId, discussionId, state)\n .then(function(context) {\n var icon = toggleElement.parents(Selectors.summary.actions).find(Selectors.lock.icon);\n var lockedLabel = toggleElement.parents(Selectors.discussion.item).find(Selectors.discussion.lockedLabel);\n if (context.locked) {\n icon.removeClass('hidden');\n lockedLabel.removeAttr('hidden');\n } else {\n icon.addClass('hidden');\n lockedLabel.attr('hidden', true);\n }\n return context;\n })\n .then(function(context) {\n context.forumid = forumId;\n return Templates.render('mod_forum/discussion_lock_toggle', context);\n })\n .then(function(html, js) {\n return Templates.replaceNode(toggleElement, html, js);\n })\n .then(function() {\n return Str.get_string('lockupdated', 'forum')\n .done(function(s) {\n return Notification.addNotification({\n message: s,\n type: \"info\"\n });\n });\n })\n .catch(Notification.exception);\n\n e.preventDefault();\n });\n };\n\n return {\n init: function(root) {\n SubscriptionToggle.init(root, false, function(toggleElement, context) {\n var toggleId = toggleElement.attr('id');\n var newTargetState = context.userstate.subscribed ? 0 : 1;\n toggleElement.data('targetstate', newTargetState);\n\n var stringKey = context.userstate.subscribed ? 'unsubscribediscussion' : 'subscribediscussion';\n return Str.get_string(stringKey, 'mod_forum')\n .then(function(string) {\n toggleElement.closest('td').find('label[for=\"' + toggleId + '\"]').find('span').text(string);\n return string;\n });\n });\n registerEventListeners(root);\n }\n };\n});\n"],"names":["define","$","Templates","Str","Notification","SubscriptionToggle","Selectors","Repository","PubSub","ForumEvents","FormChangeChecker","init","root","toggleElement","context","toggleId","attr","newTargetState","userstate","subscribed","data","stringKey","get_string","then","string","closest","find","text","subscribe","SUBSCRIPTION_TOGGLED","discussionId","subscriptionState","discussionListItem","discussion","item","subscribedLabel","addClass","removeAttr","removeClass","on","post","inpageCancelButton","e","resetFormDirtyState","currentTarget","favourite","toggle","preventDefault","this","forumId","setFavouriteDiscussionState","location","reload","catch","exception","pin","state","setPinDiscussionState","lock","setDiscussionLockState","icon","parents","summary","actions","lockedLabel","locked","forumid","render","html","js","replaceNode","done","s","addNotification","message","type","registerEventListeners"],"mappings":";;;;;;;AAsBAA,mCAAO,CACH,SACA,iBACA,WACA,oBACA,gCACA,sBACA,uBACA,cACA,yBACA,4BACD,SACCC,EACAC,UACAC,IACAC,aACAC,mBACAC,UACAC,WACAC,OACAC,YACAC,yBA0FO,CACHC,KAAM,SAASC,MACXP,mBAAmBM,KAAKC,MAAM,GAAO,SAASC,cAAeC,aACrDC,SAAWF,cAAcG,KAAK,MAC9BC,eAAiBH,QAAQI,UAAUC,WAAa,EAAI,EACxDN,cAAcO,KAAK,cAAeH,oBAE9BI,UAAYP,QAAQI,UAAUC,WAAa,wBAA0B,6BAClEhB,IAAImB,WAAWD,UAAW,aAC5BE,MAAK,SAASC,eACXX,cAAcY,QA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,gBAClCoC,MAAQ3C,cAAcO,KAAK,SAE/Bb,WAAWoD,uBAAuBV,QAASnB,aAAc0B,OACpDjC,MAAK,SAAST,aACP8C,KAAO/C,cAAcgD,QAAQvD,UAAUwD,QAAQC,SAASrC,KAAKpB,UAAUoD,KAAKE,MAC5EI,YAAcnD,cAAcgD,QAAQvD,UAAU2B,WAAWC,MAAMR,KAAKpB,UAAU2B,WAAW+B,oBACzFlD,QAAQmD,QACRL,KAAKtB,YAAY,UACjB0B,YAAY3B,WAAW,YAEvBuB,KAAKxB,SAAS,UACd4B,YAAYhD,KAAK,UAAU,IAExBF,WAEVS,MAAK,SAAST,gBACXA,QAAQoD,QAAUjB,QACX/C,UAAUiE,OAAO,mCAAoCrD,YAE/DS,MAAK,SAAS6C,KAAMC,WACVnE,UAAUoE,YAAYzD,cAAeuD,KAAMC,OAErD9C,MAAK,kBACKpB,IAAImB,WAAW,cAAe,SAChCiD,MAAK,SAASC,UACJpE,aAAaqE,gBAAgB,CAChCC,QAASF,EACTG,KAAM,eAIrBtB,MAAMjD,aAAakD,WAExBZ,EAAEK,oBAkBF6B,CAAuBhE"} \ No newline at end of file diff --git a/mod/forum/amd/build/inpage_reply.min.js b/mod/forum/amd/build/inpage_reply.min.js index cce030ebc45..8421bdfff55 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,location.reload()})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))})),root.on("click",Selectors.post.inpageCancelButton,(function(){void 0!==M.core_formchangechecker&&M.core_formchangechecker.reset_form_dirty_state()}))};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)})))})),root.on("click",Selectors.post.inpageCancelButton,(function(e){FormChangeChecker.resetFormDirtyState(e.currentTarget)}))};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 727649e48e8..679a7753041 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/cancel buttons 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 root.on('click', Selectors.post.inpageCancelButton, function() {\n // Tell formchangechecker to reset the form state.\n if (typeof M.core_formchangechecker !== 'undefined') {\n M.core_formchangechecker.reset_form_dirty_state();\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","inpageCancelButton","M","core_formchangechecker","reset_form_dirty_state","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,WAQ9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AAQZ,KAAKqD,GAELd,WACChD,+BACG+D,aAAetD,KAAKsD,aACpBC,kBAAoBxB,YAAYyB,WACAC,IAAIpE,UAAUW,KAAK0D,kBACnB3D,KAAKV,UAAUW,KAAK2D,YACpBC,cACpC5D,KAAK6D,iBAAmBN,kBACxBvD,KAAK8D,eAAiBR,aAAaS,MACbT,aAAaU,mBACbV,aAAaW,MACbX,aAAaY,OACbZ,aAAaa,QACbb,aAAac,QACbpE,KAAKqE,KAAKC,WACzBpF,UAAUqF,OAAO,kDAAmDvE,WAC1ET,iCACML,UAAUqF,OAAO,2CAA4CvE,WACnET,+BACML,UAAUqF,OAAO,yCAA0CvE,qBAE3Dd,UAAUqF,OAAO,kCAAmCvE,UAGtE6C,MAAK,SAAS2B,KAAMC,QACbC,YAAc3C,YAAYhC,KAAKV,UAAUW,KAAK0D,kBAAkBiB,eAEhEpC,MAAQhD,mCACDL,UAAU0F,oBAAoBF,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,cAK9C/E,KAAKC,GAAG,QAASnB,UAAUW,KAAKwF,oBAAoB,gBAER,IAA7BC,EAAEC,wBACTD,EAAEC,uBAAuBC,mCAK9B,CACHC,KAAM,SAASrF,MACXD,uBAAuBC,OAE3Bb,gBAAiBA,gBACjBF,OAAQA"} \ No newline at end of file +{"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/cancel buttons 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 root.on('click', Selectors.post.inpageCancelButton, function(e) {\n // Tell formchangechecker to reset the form state.\n FormChangeChecker.resetFormDirtyState(e.currentTarget);\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","inpageCancelButton","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,KA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AAKV,UAAUW,KAAK0D,kBAAkBiB,eAEhEpC,MAAQhD,mCACDL,UAAU0F,oBAAoBF,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,cAK9C/E,KAAKC,GAAG,QAASnB,UAAUW,KAAKwF,oBAAoB,SAAS9E,GAEzDpB,kBAAkByF,oBAAoBrE,EAAEK,yBAIzC,CACH0E,KAAM,SAASlF,MACXD,uBAAuBC,OAE3Bb,gBAAiBA,gBACjBF,OAAQA"} \ No newline at end of file diff --git a/mod/forum/amd/src/discussion_list.js b/mod/forum/amd/src/discussion_list.js index 2f6f4f7734d..97bf7273373 100644 --- a/mod/forum/amd/src/discussion_list.js +++ b/mod/forum/amd/src/discussion_list.js @@ -30,6 +30,7 @@ define([ 'mod_forum/repository', 'core/pubsub', 'mod_forum/forum_events', + 'core_form/changechecker', ], function( $, Templates, @@ -39,7 +40,8 @@ define([ Selectors, Repository, PubSub, - ForumEvents + ForumEvents, + FormChangeChecker ) { var registerEventListeners = function(root) { PubSub.subscribe(ForumEvents.SUBSCRIPTION_TOGGLED, function(data) { @@ -56,11 +58,9 @@ define([ } }); - root.on('click', Selectors.post.inpageCancelButton, function() { + root.on('click', Selectors.post.inpageCancelButton, function(e) { // Tell formchangechecker to reset the form state. - if (typeof M.core_formchangechecker !== 'undefined') { - M.core_formchangechecker.reset_form_dirty_state(); - } + FormChangeChecker.resetFormDirtyState(e.currentTarget); }); root.on('click', Selectors.favourite.toggle, function(e) { diff --git a/mod/forum/amd/src/inpage_reply.js b/mod/forum/amd/src/inpage_reply.js index 452b17169da..573201ffe1a 100644 --- a/mod/forum/amd/src/inpage_reply.js +++ b/mod/forum/amd/src/inpage_reply.js @@ -190,11 +190,9 @@ define([ } }); - root.on('click', Selectors.post.inpageCancelButton, function() { + root.on('click', Selectors.post.inpageCancelButton, function(e) { // Tell formchangechecker to reset the form state. - if (typeof M.core_formchangechecker !== 'undefined') { - M.core_formchangechecker.reset_form_dirty_state(); - } + FormChangeChecker.resetFormDirtyState(e.currentTarget); }); };