{"version":3,"sources":["https:\/\/moodle.dyslexiaaction.org.uk\/mod\/forum\/amd\/src\/discussion_list.js"],"names":["define","$","Templates","Str","Notification","SubscriptionToggle","Selectors","Repository","PubSub","ForumEvents","registerEventListeners","root","subscribe","SUBSCRIPTION_TOGGLED","data","discussionId","subscribed","subscriptionState","discussionListItem","find","discussion","item","subscribedLabel","addClass","removeAttr","removeClass","attr","on","favourite","toggle","toggleElement","forumId","setFavouriteDiscussionState","then","location","reload","catch","exception","pin","e","preventDefault","state","setPinDiscussionState","lock","setDiscussionLockState","context","icon","parents","summary","actions","lockedLabel","locked","forumid","render","html","js","replaceNode","get_string","done","s","addNotification","message","type","init","toggleId","newTargetState","userstate","stringKey","string","closest","text"],"mappings":"AAsBAA,OAAM,6BAAC,CACH,QADG,CAEH,gBAFG,CAGH,UAHG,CAIH,mBAJG,CAKH,+BALG,CAMH,qBANG,CAOH,sBAPG,CAQH,aARG,CASH,wBATG,CAAD,CAUH,SACCC,CADD,CAECC,CAFD,CAGCC,CAHD,CAICC,CAJD,CAKCC,CALD,CAMCC,CAND,CAOCC,CAPD,CAQCC,CARD,CASCC,CATD,CAUD,CACE,GAAIC,CAAAA,CAAsB,CAAG,SAASC,CAAT,CAAe,CACxCH,CAAM,CAACI,SAAP,CAAiBH,CAAW,CAACI,oBAA7B,CAAmD,SAASC,CAAT,CAAe,IAC1DC,CAAAA,CAAY,CAAGD,CAAI,CAACC,YADsC,CAE1DC,CAAU,CAAGF,CAAI,CAACG,iBAFwC,CAG1DC,CAAkB,CAAGP,CAAI,CAACQ,IAAL,CAAUb,CAAS,CAACc,UAAV,CAAqBC,IAArB,CAA4B,sBAA5B,CAAqDN,CAArD,CAAoE,GAA9E,CAHqC,CAI1DO,CAAe,CAAGJ,CAAkB,CAACC,IAAnB,CAAwBb,CAAS,CAACc,UAAV,CAAqBE,eAA7C,CAJwC,CAK9D,GAAIN,CAAJ,CAAgB,CACZE,CAAkB,CAACK,QAAnB,CAA4B,YAA5B,EACAD,C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E,MAAvE,EAA+EmD,IAA\/E,CAAoFF,CAApF,EACA,MAAOA,CAAAA,CACV,CAJE,CAKV,CAXD,EAYA1D,CAAsB,CAACC,CAAD,CACzB,CAfE,CAiBV,CAvHK,CAAN","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.favourite.toggle, function() {\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"],"file":"discussion_list.min.js"}