weekly release 4.0dev
[moodle.git] / user / amd / build / participants.min.js.map
1 {"version":3,"sources":["../src/participants.js"],"names":["Selectors","bulkActionSelect","bulkUserSelectedCheckBoxes","checkCountButton","showCountText","showCountToggle","stateHelpIcon","tableForm","uniqueId","init","uniqueid","noteStateNames","root","document","querySelector","getTableFromUniqueId","DynamicTableSelectors","main","fromRegionId","registerEventListeners","CustomEvents","define","events","accessibleChange","on","e","target","closest","action","value","tableRoot","checkboxes","querySelectorAll","pendingPromise","Pending","indexOf","preventDefault","ids","forEach","checkbox","push","getAttribute","replace","bulkAction","dataset","courseId","pendingBulkAction","then","modal","getRoot","ModalEvents","hidden","focus","resolve","catch","Notification","exception","length","form","submit","resetBulkAction","addEventListener","checkCountButtonClicked","contains","DynamicTable","setPageSize","targetPageSize","CheckboxToggleAll","setGroupState","Events","tableContentRefreshed","defaultPageSize","parseInt","tableDefaultPerPage","currentPageSize","tablePageSize","totalRowCount","tableTotalRows","updateSlavesFromMasterState","pageCountStrings","key","component","param","classList","add","remove","Str","get_strings","showingParticipantCountString","selectCountString","showingParticipantCount","innerHTML"],"mappings":"uqBAwBA,OACA,OACA,OACA,OACA,OACA,OACA,OACA,OACA,O,wjDAGMA,CAAAA,CAAS,CAAG,CACdC,gBAAgB,CAAE,eADJ,CAEdC,0BAA0B,CAAE,2EAFd,CAGdC,gBAAgB,CAAE,WAHJ,CAIdC,aAAa,CAAE,qCAJD,CAKdC,eAAe,CAAE,6BALH,CAMdC,aAAa,CAAE,mCAND,CAOdC,SAAS,CAAE,mBAAAC,CAAQ,8CAAkCA,CAAlC,QAPL,C,QAUE,QAAPC,CAAAA,IAAO,GAGd,IAFFC,CAAAA,CAEE,GAFFA,QAEE,KADFC,cACE,CADFA,CACE,YADe,EACf,GACIC,CAAI,CAAGC,QAAQ,CAACC,aAAT,CAAuBd,CAAS,CAACO,SAAV,CAAoBG,CAApB,CAAvB,CADX,CAEIK,CAAoB,CAAG,SAAAP,CAAQ,QAAII,CAAAA,CAAI,CA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KAAK,CAAEN,CAHW,CAAtB,EAMA,GAAIzE,CAAJ,CAAsB,CAClBA,CAAgB,CAACgF,SAAjB,CAA2BE,MAA3B,CAAkC,QAAlC,CACH,CACJ,CAEDC,CAAG,CAACC,WAAJ,CAAgBR,CAAhB,EACChC,IADD,CACM,WAAwD,cAAtDyC,CAAsD,MAAvBC,CAAuB,MACpDC,CAAuB,CAAG9E,CAAI,CAACE,aAAL,CAAmBd,CAAS,CAACI,aAA7B,CAD0B,CAE1DsF,CAAuB,CAACC,SAAxB,CAAoCH,CAApC,CAEA,GAAIC,CAAiB,EAAItF,CAAzB,CAA2C,CACvCA,CAAgB,CAAC0B,KAAjB,CAAyB4D,CAC5B,CAGJ,CAVD,EAWCnC,KAXD,CAWOC,UAAaC,SAXpB,CAYH,CA3DD,CA4DH,CA/IC,CAiJII,CAAe,CAAG,SAAA3D,CAAgB,CAAI,CACxCA,CAAgB,CAAC4B,KAAjB,CAAyB,EAC5B,CAnJC,CAqJFV,CAAsB,EACzB,C","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 * Some UI stuff for participants page.\n * This is also used by the report/participants/index.php because it has the same functionality.\n *\n * @module     core_user/participants\n * @copyright  2017 Damyon Wiese\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport * as DynamicTable from 'core_table/dynamic';\nimport * as Str from 'core/str';\nimport CheckboxToggleAll from 'core/checkbox-toggleall';\nimport CustomEvents from 'core/custom_interaction_events';\nimport DynamicTableSelectors from 'core_table/local/dynamic/selectors';\nimport ModalEvents from 'core/modal_events';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport jQuery from 'jquery';\nimport {showAddNote, showSendMessage} from 'core_user/local/participants/bulkactions';\n\nconst Selectors = {\n    bulkActionSelect: \"#formactionid\",\n    bulkUserSelectedCheckBoxes: \"input[data-togglegroup='participants-table'][data-toggle='slave']:checked\",\n    checkCountButton: \"#checkall\",\n    showCountText: '[data-region=\"participant-count\"]',\n    showCountToggle: '[data-action=\"showcount\"]',\n    stateHelpIcon: '[data-region=\"state-help-icon\"]',\n    tableForm: uniqueId => `form[data-table-unique-id=\"${uniqueId}\"]`,\n};\n\nexport const init = ({\n    uniqueid,\n    noteStateNames = {},\n}) => {\n    const root = document.querySelector(Selectors.tableForm(uniqueid));\n    const getTableFromUniqueId = uniqueId => root.querySelector(DynamicTableSelectors.main.fromRegionId(uniqueId));\n\n    /**\n     * Private method.\n     *\n     * @method registerEventListeners\n     * @private\n     */\n    const registerEventListeners = () => {\n        CustomEvents.define(Selectors.bulkActionSelect, [CustomEvents.events.accessibleChange]);\n        jQuery(Selectors.bulkActionSelect).on(CustomEvents.events.accessibleChange, e => {\n            const bulkActionSelect = e.target.closest('select');\n            const action = bulkActionSelect.value;\n            const tableRoot = getTableFromUniqueId(uniqueid);\n            const checkboxes = tableRoot.querySelectorAll(Selectors.bulkUserSelectedCheckBoxes);\n            const pendingPromise = new Pending('core_user/participants:bulkActionSelect');\n\n            if (action.indexOf('#') !== -1) {\n                e.preventDefault();\n\n                const ids = [];\n                checkboxes.forEach(checkbox => {\n                    ids.push(checkbox.getAttribute('name').replace('user', ''));\n                });\n\n                let bulkAction;\n                if (action === '#messageselect') {\n                    bulkAction = showSendMessage(ids);\n                } else if (action === '#addgroupnote') {\n                    bulkAction = showAddNote(\n                        root.dataset.courseId,\n                        ids,\n                        noteStateNames,\n                        root.querySelector(Selectors.stateHelpIcon)\n                    );\n                }\n\n                if (bulkAction) {\n                    const pendingBulkAction = new Pending('core_user/participants:bulkActionSelected');\n                    bulkAction\n                    .then(modal => {\n                        modal.getRoot().on(ModalEvents.hidden, () => {\n                            // Focus on the action select when the dialog is closed.\n                            bulkActionSelect.focus();\n                        });\n\n                        pendingBulkAction.resolve();\n                        return modal;\n                    })\n                    .catch(Notification.exception);\n                }\n            } else if (action !== '' && checkboxes.length) {\n                bulkActionSelect.form.submit();\n            }\n\n            resetBulkAction(bulkActionSelect);\n            pendingPromise.resolve();\n        });\n\n        root.addEventListener('click', e => {\n            // Handle clicking of the \"Select all\" actions.\n            const checkCountButton = root.querySelector(Selectors.checkCountButton);\n            const checkCountButtonClicked = checkCountButton && checkCountButton.contains(e.target);\n\n            if (checkCountButtonClicked) {\n                e.preventDefault();\n\n                const tableRoot = getTableFromUniqueId(uniqueid);\n\n                DynamicTable.setPageSize(tableRoot, checkCountButton.dataset.targetPageSize)\n                .then(tableRoot => {\n                    // Update the toggle state.\n                    CheckboxToggleAll.setGroupState(root, 'participants-table', true);\n\n                    return tableRoot;\n                })\n                .catch(Notification.exception);\n            }\n        });\n\n        // When the content is refreshed, update the row counts in various places.\n        root.addEventListener(DynamicTable.Events.tableContentRefreshed, e => {\n            const checkCountButton = root.querySelector(Selectors.checkCountButton);\n\n            const tableRoot = e.target;\n\n            const defaultPageSize = parseInt(tableRoot.dataset.tableDefaultPerPage, 10);\n            const currentPageSize = parseInt(tableRoot.dataset.tablePageSize, 10);\n            const totalRowCount = parseInt(tableRoot.dataset.tableTotalRows, 10);\n\n            CheckboxToggleAll.updateSlavesFromMasterState(root, 'participants-table');\n\n            const pageCountStrings = [\n                {\n                    key: 'countparticipantsfound',\n                    component: 'core_user',\n                    param: totalRowCount,\n                },\n            ];\n\n            if (totalRowCount <= defaultPageSize) {\n                if (checkCountButton) {\n                    checkCountButton.classList.add('hidden');\n                }\n            } else if (totalRowCount <= currentPageSize) {\n                // The are fewer than the current page size.\n                pageCountStrings.push({\n                    key: 'selectalluserswithcount',\n                    component: 'core',\n                    param: defaultPageSize,\n                });\n\n                if (checkCountButton) {\n                    // The 'Check all [x]' button is only visible when there are values to set.\n                    checkCountButton.classList.add('hidden');\n                }\n            } else {\n                pageCountStrings.push({\n                    key: 'selectalluserswithcount',\n                    component: 'core',\n                    param: totalRowCount,\n                });\n\n                if (checkCountButton) {\n                    checkCountButton.classList.remove('hidden');\n                }\n            }\n\n            Str.get_strings(pageCountStrings)\n            .then(([showingParticipantCountString, selectCountString]) => {\n                const showingParticipantCount = root.querySelector(Selectors.showCountText);\n                showingParticipantCount.innerHTML = showingParticipantCountString;\n\n                if (selectCountString && checkCountButton) {\n                    checkCountButton.value = selectCountString;\n                }\n\n                return;\n            })\n            .catch(Notification.exception);\n        });\n    };\n\n    const resetBulkAction = bulkActionSelect => {\n        bulkActionSelect.value = '';\n    };\n\n    registerEventListeners();\n};\n"],"file":"participants.min.js"}