AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"expandconversation.min.js","sources":["../../src/grades/expandconversation.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 <http://www.gnu.org/licenses/>.\n\n/**\n * This module handles the creation of a Modal that shows the user's post in context of the entire discussion.\n *\n * @module mod_forum/grades/expandconversation\n * @copyright 2019 Mathew May
<mathew.solutions>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as ForumSelectors from './grader/selectors';\nimport Repository from 'mod_forum/repository';\nimport {exception as showException} from \"core/notification\";\nimport Templates from 'core/templates';\nimport Modal from 'core/modal_cancel';\nimport * as ModalEvents from 'core/modal_events';\n\n/**\n * Find the Node containing the gradable details from the provided node by searching up the tree.\n *\n * @param {HTMLElement} node\n * @returns {HTMLElement}\n */\nconst findGradableNode = node => node.closest(ForumSelectors.expandConversation);\n\n/**\n * Show the post in context in a modal.\n *\n * @param {HTMLElement} rootNode The button that has been clicked\n * @param {object} param\n * @param {bool} [param.focusOnClose=null]\n */\nconst showPostInContext = async(rootNode, {\n focusOnClose = null,\n} = {}) => {\n const postId = rootNode.dataset.postid;\n const discussionId = rootNode.dataset.disc
ussionid;\n const discussionName = rootNode.dataset.name;\n const experimentalDisplayMode = rootNode.dataset.experimentalDisplayMode == \"1\";\n\n const [\n allPosts,\n modal,\n ] = await Promise.all([\n Repository.getDiscussionPosts(parseInt(discussionId)),\n Modal.create({\n title: discussionName,\n large: true,\n removeOnClose: true,\n returnElement: focusOnClose,\n }),\n ]);\n\n const postsById = new Map(allPosts.posts.map(post => {\n post.readonly = true;\n post.hasreplies = false;\n post.replies = [];\n return [post.id, post];\n }));\n\n let posts = [];\n allPosts.posts.forEach(post => {\n if (post.parentid) {\n const parent = postsById.get(post.parentid);\n if (parent) {\n post.parentauthorname = parent.author.fullname;\n parent.hasreplies = true;\n parent.replies.push(post);\n } else {
\n posts.push(post);\n }\n } else {\n posts.push(post);\n }\n });\n\n modal.getRoot().on(ModalEvents.bodyRendered, () => {\n const relevantPost = modal.getRoot()[0].querySelector(`#p${postId}`);\n if (relevantPost) {\n relevantPost.scrollIntoView({behavior: \"smooth\"});\n }\n });\n\n modal.show();\n\n // Note: We do not use await here because it messes with the Modal transitions.\n const templatePromise = Templates.render('mod_forum/grades/grader/discussion/post_modal', {\n posts,\n experimentaldisplaymode: experimentalDisplayMode\n });\n modal.setBody(templatePromise);\n};\n\n/**\n * Register event listeners for the expand conversations button.\n *\n * @param {HTMLElement} rootNode The root to listen to.\n */\nexport const registerEventListeners = (rootNode) => {\n rootNode.addEventListener('click', (e) => {\n const rootNode = findGradableNode(e.target);\n\n if (rootNode
) {\n e.preventDefault();\n\n try {\n showPostInContext(rootNode, {\n focusOnClose: e.target,\n });\n } catch (err) {\n showException(err);\n }\n }\n });\n};\n"],"names":["rootNode","addEventListener","e","target","closest","ForumSelectors","expandConversation","preventDefault","async","focusOnClose","postId","dataset","postid","discussionId","discussionid","discussionName","name","experimentalDisplayMode","allPosts","modal","Promise","all","Repository","getDiscussionPosts","parseInt","Modal","create","title","large","removeOnClose","returnElement","postsById","Map","posts","map","post","readonly","hasreplies","replies","id","forEach","parentid","parent","get","parentauthorname","author","fullname","push","getRoot","on","ModalEvents","bodyRendered","relevantPost","querySelector","scrollIntoView","behavior","show","templatePromise","Templates","render","experimentaldisplaymode","setBody","show
PostInContext","err"],"mappings":";;;;;;;8XA8GuCA,WACnCA,SAASC,iBAAiB,SAAUC,UAC1BF,SAA4BE,EAAEC,OA7ENC,QAAQC,eAAeC,uBA+EjDN,SAAU,CACVE,EAAEK,sBAvEYC,eAAMR,cAAUS,aACtCA,aAAe,6DACf,SACMC,OAASV,SAASW,QAAQC,OAC1BC,aAAeb,SAASW,QAAQG,aAChCC,eAAiBf,SAASW,QAAQK,KAClCC,wBAAsE,KAA5CjB,SAASW,QAAQM,yBAG7CC,SACAC,aACMC,QAAQC,IAAI,CAClBC,oBAAWC,mBAAmBC,SAASX,eACvCY,sBAAMC,OAAO,CACTC,MAAOZ,eACPa,OAAO,EACPC,eAAe,EACfC,cAAerB,iBAIjBsB,UAAY,IAAIC,IAAId,SAASe,MAAMC,KAAIC,OACzCA,KAAKC,UAAW,EAChBD,KAAKE,YAAa,EAClBF,KAAKG,QAAU,GACR,CAACH,KAAKI,GAAIJ,cAGjBF,MAAQ,GACZf,SAASe,MAAMO,SAAQL,UACfA,KAAKM,SAAU,OACTC,OAASX,UAAUY,IAAIR,KAAKM,UAC9BC,QACAP,KAAKS,iBAAmBF,OAAOG,OAAOC,SACtCJ,OAAOL,YAAa,EACpBK,OAAOJ,QAAQS,KAAKZ,OAEpBF,MAAMc,KAAKZ,WAGfF,MAAMc,KAAKZ,SAInBhB,MAAM6B,UAAUC,GAAGC,YAAYC,cAAc,WACnCC,aAAejC,MAAM6B,UAAU,GAAGK,0BAAmB3C,SACvD0C,cACAA,aAAaE,eAAe,CAACC,SAAU,cAI/CpC,MAAMqC,aAGAC,gBAAkBC,mBAAUC,OAAO,gDAAiD,CACtF1B,MAAAA,MACA2B,wBAAyB3C,0BAE7BE,MAAM0C,QAAQJ,iBAgBFK,CAAkB9D,SAAU,CACxBS,aAAcP,EAAEC,SAEtB,MAAO4D,iCACSA"}