{"version":3,"file":"discussion_list.min.js","sources":["https:\/\/www.alsg.org\/home\/mod\/forum\/amd\/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.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","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,mBAqFO,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,aA9FE,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,mBAAmBM,YAAY,cAC\/BH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