Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"actions.min.js","sources":["../src/actions.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 * Common javascript for handling actions on the admin page and the user's view of the question bank.\n *\n * @module     qbank_columnsortorder/actions\n * @copyright  2023 onwards Catalyst IT Europe Ltd\n * @author     Mark Johnson <mark.johnson@catalyst-eu.net>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport SortableList from 'core/sortable_list';\nimport $ from 'jquery';\nimport * as repository from 'qbank_columnsortorder/repository';\nimport Notification from \"core/notification\";\nimport RefreshUi from 'core_question/refresh_ui';\n\nexport const SELECTORS = {\n    columnList: '.qbank-column-list',\n    sortableColumn: '.qbank-sortable-column',\n    removeLink: '[data-action=remove]',\n    moveHandler: '[data-drag-type=move]',\n    addColumn: '.addcolumn',\n    addLink: '[data-action=add]',\n    actionLink: '.action-link',\n};\n\n/**\n * Sets up sortable list in the column sort order page.\n *\n * @param {Element} listRoot Element containing the sortable list.\n * @param {Boolean} vertical Is the list in vertical orientation, rather than horizonal?\n * @param {Boolean} global Should changes be saved to global config, rather than user preferences?\n * @return {jQuery} sortable column elements, for attaching additional event listeners.\n */\nexport const setupSortableLists = (listRoot, vertical = false, global = false) => {\n    const sortableList = new SortableList(listRoot, {\n        moveHandlerSelector: SELECTORS.moveHandler,\n        isHorizontal: !vertical,\n    });\n    sortableList.getElementName = element => Promise.resolve(element.data('name'));\n\n    const sortableColumns = $(SELECTORS.sortableColumn);\n\n    sortableColumns.on(SortableList.EVENTS.DROP, () => {\n        repository.setColumnbankOrder(getColumnOrder(listRoot), global).catch(Notification.exception);\n        listRoot.querySelectorAll(SELECTORS.sortableColumn).forEach(item => item.classList.remove('active'));\n    });\n\n    sortableColumns.on(SortableList.EVENTS.DRAGSTART, (event) => {\n        event.currentTarget.classList.add('active');\n    });\n\n    return sortableColumns;\n};\n\n/**\n * Set up event handlers for action buttons.\n *\n * For each action, call the web service to update the appropriate setting or user preference, then call the fragment to\n * refresh the view.\n *\n * @param {Element} uiRoot The root of the question bank UI.\n * @param {Boolean} global Should changes be saved to global config, rather than user preferences?\n */\nexport const setupActionButtons = (uiRoot, global = false) => {\n    uiRoot.addEventListener('click', async(e) => {\n        const actionLink = e.target.closest(SELECTORS.actionLink);\n        if (!actionLink) {\n            return;\n        }\n        try {\n            e.preventDefault();\n            const action = actionLink.dataset.action;\n            if (action === 'add' || action === 'remove') {\n                const hiddenColumns = [];\n                const addColumnList = document.querySelector(SELECTORS.addColumn);\n                if (addColumnList) {\n                    addColumnList.querySelectorAll(SELECTORS.addLink).forEach(item => {\n                        if (action === 'add' && item === actionLink) {\n                            return;\n                        }\n                        hiddenColumns.push(item.dataset.column);\n                    });\n                }\n                if (action === 'remove') {\n                    hiddenColumns.push(actionLink.dataset.column);\n                }\n                await repository.setHiddenColumns(hiddenColumns, global);\n            } else if (action === 'reset') {\n                await repository.resetColumns(global);\n            }\n            const actionUrl = new URL(actionLink.href);\n            const returnUrl = new URL(actionUrl.searchParams.get('returnurl').replaceAll('&amp;', '&'));\n            await RefreshUi.refresh(uiRoot, returnUrl);\n        } catch (ex) {\n            await Notification.exception(ex);\n        }\n    });\n};\n\n/**\n * Gets the newly reordered columns to display in the question bank view.\n * @param {Element} listRoot\n * @returns {Array}\n */\nexport const getColumnOrder = listRoot => {\n    const columns = Array.from(listRoot.querySelectorAll('[data-columnid]'))\n        .map(column => column.dataset.columnid);\n\n    return columns.filter((value, index) => columns.indexOf(value) === index);\n};\n"],"names":["SELECTORS","columnList","sortableColumn","removeLink","moveHandler","addColumn","addLink","actionLink","listRoot","vertical","global","sortableList","SortableList","moveHandlerSelector","isHorizontal","getElementName","element","Promise","resolve","data","sortableColumns","on","EVENTS","DROP","repository","setColumnbankOrder","getColumnOrder","catch","Notification","exception","querySelectorAll","forEach","item","classList","remove","DRAGSTART","event","currentTarget","add","uiRoot","addEventListener","async","e","target","closest","preventDefault","action","dataset","hiddenColumns","addColumnList","document","querySelector","push","column","setHiddenColumns","resetColumns","actionUrl","URL","href","returnUrl","searchParams","get","replaceAll","RefreshUi","refresh","ex","columns","Array","from","map","columnid","filter","value","index","indexOf"],"mappings":";;;;;;;;mhCA8BaA,UAAY,CACrBC,WAAY,qBACZC,eAAgB,yBAChBC,WAAY,uBACZC,YAAa,wBACbC,UAAW,aACXC,QAAS,oBACTC,WAAY,yEAWkB,SAACC,cAAUC,iEAAkBC,qEACrDC,aAAe,IAAIC,uBAAaJ,SAAU,CAC5CK,oBAAqBb,UAAUI,YAC/BU,cAAeL,WAEnBE,aAAaI,eAAiBC,SAAWC,QAAQC,QAAQF,QAAQG,KAAK,eAEhEC,iBAAkB,mBAAEpB,UAAUE,uBAEpCkB,gBAAgBC,GAAGT,uBAAaU,OAAOC,MAAM,KACzCC,WAAWC,mBAAmBC,eAAelB,UAAWE,QAAQiB,MAAMC,sBAAaC,WACnFrB,SAASsB,iBAAiB9B,UAAUE,gBAAgB6B,SAAQC,MAAQA,KAAKC,UAAUC,OAAO,eAG9Fd,gBAAgBC,GAAGT,uBAAaU,OAAOa,WAAYC,QAC/CA,MAAMC,cAAcJ,UAAUK,IAAI,aAG/BlB,6CAYuB,SAACmB,YAAQ7B,+DACvC6B,OAAOC,iBAAiB,SAASC,MAAAA,UACvBlC,WAAamC,EAAEC,OAAOC,QAAQ5C,UAAUO,eACzCA,eAIDmC,EAAEG,uBACIC,OAASvC,WAAWwC,QAAQD,UACnB,QAAXA,QAA+B,WAAX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