From 3f5f45e32156d4a50a4ab38b336aca932bbad8e0 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Sat, 23 Dec 2023 11:59:12 +0000 Subject: [PATCH] Coding style fixes --- amd/build/local/content/actions.min.js.map | 2 +- amd/src/local/content/actions.js | 2 ++ classes/courseformat/stateactions.php | 12 ++++++------ classes/output/courseformat/content.php | 1 + .../courseformat/content/section/controlmenu.php | 10 +++++----- format.js | 1 + 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/amd/build/local/content/actions.min.js.map b/amd/build/local/content/actions.min.js.map index c24b8b2..6e20758 100644 --- a/amd/build/local/content/actions.min.js.map +++ b/amd/build/local/content/actions.min.js.map @@ -1 +1 @@ -{"version":3,"file":"actions.min.js","sources":["../../../src/local/content/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 .\n\nimport {BaseComponent} from 'core/reactive';\nimport {get_string as getString, get_strings as getStrings} from \"core/str\";\nimport Notification from \"core/notification\";\nimport ModalFactory from \"core/modal_factory\";\nimport Templates from \"core/templates\";\nimport Pending from \"core/pending\";\n\n/**\n * Actions\n *\n * @module format_flexsections/local/content/actions\n * @copyright 2022 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class extends BaseComponent {\n // Example: course/format/amd/src/local/content/actions.js\n\n /**\n * Constructor hook.\n */\n create() {\n // Optional component name for debugging.\n this.name = 'content_actions_flexsections';\n // Default query selectors.\n this.selectors = {\n ACTIONLINK: `[data-action-flexsections]`,\n SECTIONLINK: `[data-for='section']`,\n };\n // Component css classes.\n this.classes = {\n DISABLED: `disabled`,\n };\n }\n\n /**\n * Initial state ready method.\n *\n * @param {Object} state the state data.\n *\n */\n stateReady(state) {\n super.stateReady(state);\n // Delegate dispatch clicks.\n this.addEventListener(\n this.element,\n 'click',\n this._dispatchClick\n );\n }\n\n _dispatchClick(event) {\n const target = event.target.closest(this.selectors.ACTIONLINK);\n if (!target) {\n return;\n }\n if (target.classList.contains(this.classes.DISABLED)) {\n event.preventDefault();\n return;\n }\n\n // Invoke proper method.\n const methodName = this._actionMethodName(target.getAttribute('data-action-flexsections'));\n\n if (this[methodName] !== undefined) {\n this[methodName](target, event);\n }\n }\n\n _actionMethodName(name) {\n const requestName = name.charAt(0).toUpperCase() + name.slice(1);\n return `_request${requestName}`;\n }\n\n /**\n * Handle a section delete request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestDelete(target, event) {\n const sectionId = target.dataset.id;\n if (!sectionId) {\n return;\n }\n event.preventDefault();\n\n const sectionInfo = this.reactive.get('section', sectionId);\n\n const cmList = sectionInfo.cmlist ?? [];\n if (cmList.length || sectionInfo.hassummary || sectionInfo.rawtitle || sectionInfo.children.length) {\n getStrings([\n {key: 'confirm', component: 'moodle'},\n {key: 'confirmdelete', component: 'format_flexsections'},\n {key: 'yes', component: 'moodle'},\n {key: 'no', component: 'moodle'}\n ]).done((strings) => {\n Notification.confirm(\n strings[0], // Confirm.\n strings[1], // Are you sure you want to delete.\n strings[2], // Yes.\n strings[3], // No.\n () => {\n this.reactive.dispatch('sectionDelete', [sectionId]);\n }\n );\n }).fail(Notification.exception);\n } else {\n // We don't need confirmation to merge empty sections.\n this.reactive.dispatch('sectionDelete', [sectionId]);\n }\n }\n\n /**\n * Handle a merge section request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMergeup(target, event) {\n const sectionId = target.dataset.id;\n if (!sectionId) {\n return;\n }\n event.preventDefault();\n\n const sectionInfo = this.reactive.get('section', sectionId);\n\n const cmList = sectionInfo.cmlist ?? [];\n if (cmList.length || sectionInfo.hassummary || sectionInfo.rawtitle || sectionInfo.children.length) {\n getStrings([\n {key: 'confirm', component: 'moodle'},\n {key: 'confirmmerge', component: 'format_flexsections'},\n {key: 'yes', component: 'moodle'},\n {key: 'no', component: 'moodle'}\n ]).done((strings) => {\n Notification.confirm(\n strings[0], // Confirm.\n strings[1], // Are you sure you want to merge.\n strings[2], // Yes.\n strings[3], // No.\n () => {\n this.reactive.dispatch('sectionMergeUp', sectionId);\n }\n );\n }).fail(Notification.exception);\n } else {\n // We don't need confirmation to merge empty sections.\n this.reactive.dispatch('sectionMergeUp', sectionId);\n }\n }\n\n /**\n * Handle a move section request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMoveSection(target, event) {\n event.preventDefault();\n const sectionId = target.dataset.id;\n const sectionInfo = this.reactive.get('section', sectionId);\n const exporter = this.reactive.getExporter();\n const data = exporter.course(this.reactive.state);\n data.sectiontitle = sectionInfo.title;\n\n if (data.sections.length === 1 && `${data.sections[0].singlesection}` === '1') {\n // We are on a page of a collapsed section. Do not show \"move before\" and \"move after\" controls.\n data.singlesectionmode = 1;\n data.sections[0].contentcollapsed = false;\n // TODO allow to move from collapsed section up level.\n }\n const buildParents = (sections, parents) => {\n for (var i in sections) {\n sections[i].parents = parents;\n sections[i].aftersectionid = (i > 0) ? sections[i - 1].id : 0;\n buildParents(sections[i].children, parents + ',' + sections[i].id);\n sections[i].lastchildid = sections[i].children.length ?\n sections[i].children[sections[i].children.length - 1].id : 0;\n }\n };\n buildParents(data.sections, '');\n data.lastchildid = data.sections.length ? data.sections[data.sections.length - 1].id : 0;\n\n ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: getString('movecoursesection', 'core'),\n large: true,\n buttons: {cancel: getString('closebuttontitle', 'core')},\n removeOnClose: true,\n })\n .then(modal => {\n Templates.render('format_flexsections/local/content/movesection', data).\n then((body) => {\n modal.setBody(body);\n this._setupMoveSection(modal, modal.getBody()[0], sectionId, data);\n return null;\n })\n .fail(() => null);\n modal.show();\n return modal;\n })\n .fail(() => null);\n }\n\n /**\n * Handle a move activity request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMoveCm(target, event) {\n event.preventDefault();\n const cmId = target.dataset.id;\n if (!cmId) {\n return;\n }\n const cmInfo = this.reactive.get('cm', cmId);\n\n const exporter = this.reactive.getExporter();\n const data = exporter.course(this.reactive.state);\n\n // TODO set before and after current as disabled.\n // TODO allow to move from collapsed section up level.\n\n data.cmid = cmInfo.id;\n data.cmname = cmInfo.name;\n\n ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: getString('movecoursemodule', 'core'),\n large: true,\n buttons: {cancel: getString('closebuttontitle', 'core')},\n removeOnClose: true,\n })\n .then(modal => {\n Templates.render('format_flexsections/local/content/movecm', data).\n then((body) => {\n modal.setBody(body);\n this._setupMoveCm(modal, modal.getBody()[0], cmId, data);\n return null;\n })\n .fail(() => null);\n modal.show();\n return modal;\n })\n .fail(() => null);\n }\n\n /**\n * Set up a popup window for moving activity\n *\n * @param {Modal} modal\n * @param {Element} modalBody\n * @param {Number} cmId\n * @param {Object} data\n * @param {Element} element\n */\n _setupMoveCm(modal, modalBody, cmId, data, element = null) {\n\n // Capture click.\n modalBody.addEventListener('click', (event) => {\n const target = event.target;\n if (!target.matches('a') || target.dataset.for === undefined || target.dataset.id === undefined) {\n return;\n }\n if (target.getAttribute('aria-disabled')) {\n return;\n }\n event.preventDefault();\n\n const targetSectionId = (target.dataset.for === 'section') ? target.dataset.id : 0;\n const targetCmId = (target.dataset.for === 'cm') ? target.dataset.id : 0;\n this.reactive.dispatch('cmMove', [cmId], targetSectionId, targetCmId);\n this._destroyModal(modal, element);\n });\n }\n\n /**\n * Destroy modal popup\n *\n * @param {Modal} modal\n * @param {Element} element\n */\n _destroyModal(modal, element = null) {\n\n // Destroy\n modal.hide();\n const pendingDestroy = new Pending(`courseformat/actions:destroyModal`);\n if (element) {\n element.focus();\n }\n setTimeout(() =>{\n modal.destroy();\n pendingDestroy.resolve();\n }, 500);\n\n }\n\n /**\n * Set up a popup window for moving section\n *\n * @param {Modal} modal\n * @param {Element} modalBody\n * @param {Number} sectionId\n * @param {Object} data\n * @param {Element} element\n */\n _setupMoveSection(modal, modalBody, sectionId, data, element = null) {\n\n // Disable moving before or after itself or under one of its own children.\n const links = modalBody.querySelectorAll(`${this.selectors.SECTIONLINK}`);\n for (let i = 0; i < links.length; ++i) {\n const re = new RegExp(`,${sectionId},`, \"g\");\n if (links[i].getAttribute('data-before') === `${sectionId}` || links[i].getAttribute('data-after') === `${sectionId}` ||\n `${links[i].getAttribute('data-parents')},`.match(re)) {\n this._disableLink(links[i]);\n }\n // Disable moving to the depth that exceeds the maxsectiondepth setting.\n const depth = (`${links[i].getAttribute('data-parents')}`.match(/,/g) || []).length;\n if (data.maxsectiondepth && depth >= data.maxsectiondepth) {\n this._disableLink(links[i]);\n }\n }\n\n // TODO.\n // Setup keyboard navigation.\n // new ContentTree(\n // modalBody.querySelector(this.selectors.CONTENTTREE),\n // {\n // SECTION: this.selectors.SECTIONNODE,\n // TOGGLER: this.selectors.MODALTOGGLER,\n // COLLAPSE: this.selectors.MODALTOGGLER,\n // },\n // true\n // );\n\n // Capture click.\n modalBody.addEventListener('click', (event) => {\n\n const target = event.target;\n if (!target.matches('a') || target.dataset.for !== 'section' || target.dataset.after === undefined) {\n return;\n }\n if (target.getAttribute('aria-disabled')) {\n return;\n }\n event.preventDefault();\n const afterId = parseInt(target.dataset.after);\n const parentId = parseInt(target.dataset.parentid);\n this.reactive.dispatch('sectionMove', [sectionId], afterId ? afterId : -parentId);\n\n this._destroyModal(modal, element);\n });\n }\n\n /**\n * Disable link\n *\n * @param {Element} element\n */\n _disableLink(element) {\n if (element) {\n element.style.pointerEvents = 'none';\n element.style.userSelect = 'none';\n element.classList.add('disabled');\n element.setAttribute('aria-disabled', true);\n element.addEventListener('click', event => event.preventDefault());\n }\n }\n\n /**\n * Handle a request to add a subsection as the last child of the parent\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestAddSubSection(target, event) {\n event.preventDefault();\n this.reactive.dispatch('addSubSection', parseInt(target.dataset.parentid ?? 0));\n }\n\n /**\n * Handle a request to add a subsection as the first child of the parent\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestInsertSubSection(target, event) {\n event.preventDefault();\n this.reactive.dispatch('insertSubSection', parseInt(target.dataset.parentid ?? 0));\n }\n\n /**\n * Handle a request to switch the section mode (displayed on the same page vs as a link).\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestSectionSwitchCollapsed(target, event) {\n event.preventDefault();\n this.reactive.dispatch('sectionSwitchCollapsed', target.dataset.id ?? 0);\n }\n}\n"],"names":["BaseComponent","create","name","selectors","ACTIONLINK","SECTIONLINK","classes","DISABLED","stateReady","state","addEventListener","this","element","_dispatchClick","event","target","closest","classList","contains","preventDefault","methodName","_actionMethodName","getAttribute","undefined","requestName","charAt","toUpperCase","slice","_requestDelete","sectionId","dataset","id","sectionInfo","reactive","get","cmlist","length","hassummary","rawtitle","children","key","component","done","strings","confirm","dispatch","fail","Notification","exception","_requestMergeup","_requestMoveSection","data","getExporter","course","sectiontitle","title","sections","singlesection","singlesectionmode","contentcollapsed","buildParents","parents","i","aftersectionid","lastchildid","type","ModalFactory","types","CANCEL","large","buttons","cancel","removeOnClose","then","modal","render","body","setBody","_setupMoveSection","getBody","show","_requestMoveCm","cmId","cmInfo","cmid","cmname","_setupMoveCm","modalBody","matches","for","targetSectionId","targetCmId","_destroyModal","hide","pendingDestroy","Pending","focus","setTimeout","destroy","resolve","links","querySelectorAll","re","RegExp","match","_disableLink","depth","maxsectiondepth","after","afterId","parseInt","parentId","parentid","style","pointerEvents","userSelect","add","setAttribute","_requestAddSubSection","_requestInsertSubSection","_requestSectionSwitchCollapsed"],"mappings":";;;;;;;8SA6B6BA,wB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OAAOe,QAAQkF,gEAAY,IAShFO,yBAAyBxG,OAAQD,kCAC7BA,MAAMK,sBACDc,SAASY,SAAS,mBAAoBiE,wCAAS/F,OAAOe,QAAQkF,kEAAY,IASnFQ,+BAA+BzG,OAAQD,8BACnCA,MAAMK,sBACDc,SAASY,SAAS,oDAA0B9B,OAAOe,QAAQC,oDAAM"} \ No newline at end of file +{"version":3,"file":"actions.min.js","sources":["../../../src/local/content/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 .\n\nimport {BaseComponent} from 'core/reactive';\nimport {get_string as getString, get_strings as getStrings} from \"core/str\";\nimport Notification from \"core/notification\";\nimport ModalFactory from \"core/modal_factory\";\nimport Templates from \"core/templates\";\nimport Pending from \"core/pending\";\n\n/**\n * Actions\n *\n * @module format_flexsections/local/content/actions\n * @copyright 2022 Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class extends BaseComponent {\n // Example: course/format/amd/src/local/content/actions.js\n\n /**\n * Constructor hook.\n */\n create() {\n // Optional component name for debugging.\n this.name = 'content_actions_flexsections';\n // Default query selectors.\n this.selectors = {\n ACTIONLINK: `[data-action-flexsections]`,\n SECTIONLINK: `[data-for='section']`,\n };\n // Component css classes.\n this.classes = {\n DISABLED: `disabled`,\n };\n }\n\n /**\n * Initial state ready method.\n *\n * @param {Object} state the state data.\n *\n */\n stateReady(state) {\n super.stateReady(state);\n // Delegate dispatch clicks.\n this.addEventListener(\n this.element,\n 'click',\n this._dispatchClick\n );\n }\n\n _dispatchClick(event) {\n const target = event.target.closest(this.selectors.ACTIONLINK);\n if (!target) {\n return;\n }\n if (target.classList.contains(this.classes.DISABLED)) {\n event.preventDefault();\n return;\n }\n\n // Invoke proper method.\n const methodName = this._actionMethodName(target.getAttribute('data-action-flexsections'));\n\n if (this[methodName] !== undefined) {\n this[methodName](target, event);\n }\n }\n\n _actionMethodName(name) {\n const requestName = name.charAt(0).toUpperCase() + name.slice(1);\n return `_request${requestName}`;\n }\n\n /**\n * Handle a section delete request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestDelete(target, event) {\n const sectionId = target.dataset.id;\n if (!sectionId) {\n return;\n }\n event.preventDefault();\n\n const sectionInfo = this.reactive.get('section', sectionId);\n\n const cmList = sectionInfo.cmlist ?? [];\n if (cmList.length || sectionInfo.hassummary || sectionInfo.rawtitle || sectionInfo.children.length) {\n getStrings([\n {key: 'confirm', component: 'moodle'},\n {key: 'confirmdelete', component: 'format_flexsections'},\n {key: 'yes', component: 'moodle'},\n {key: 'no', component: 'moodle'}\n ]).done((strings) => {\n Notification.confirm(\n strings[0], // Confirm.\n strings[1], // Are you sure you want to delete.\n strings[2], // Yes.\n strings[3], // No.\n () => {\n this.reactive.dispatch('sectionDelete', [sectionId]);\n }\n );\n }).fail(Notification.exception);\n } else {\n // We don't need confirmation to merge empty sections.\n this.reactive.dispatch('sectionDelete', [sectionId]);\n }\n }\n\n /**\n * Handle a merge section request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMergeup(target, event) {\n const sectionId = target.dataset.id;\n if (!sectionId) {\n return;\n }\n event.preventDefault();\n\n const sectionInfo = this.reactive.get('section', sectionId);\n\n const cmList = sectionInfo.cmlist ?? [];\n if (cmList.length || sectionInfo.hassummary || sectionInfo.rawtitle || sectionInfo.children.length) {\n getStrings([\n {key: 'confirm', component: 'moodle'},\n {key: 'confirmmerge', component: 'format_flexsections'},\n {key: 'yes', component: 'moodle'},\n {key: 'no', component: 'moodle'}\n ]).done((strings) => {\n Notification.confirm(\n strings[0], // Confirm.\n strings[1], // Are you sure you want to merge.\n strings[2], // Yes.\n strings[3], // No.\n () => {\n this.reactive.dispatch('sectionMergeUp', sectionId);\n }\n );\n }).fail(Notification.exception);\n } else {\n // We don't need confirmation to merge empty sections.\n this.reactive.dispatch('sectionMergeUp', sectionId);\n }\n }\n\n /**\n * Handle a move section request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMoveSection(target, event) {\n event.preventDefault();\n const sectionId = target.dataset.id;\n const sectionInfo = this.reactive.get('section', sectionId);\n const exporter = this.reactive.getExporter();\n const data = exporter.course(this.reactive.state);\n data.sectiontitle = sectionInfo.title;\n\n if (data.sections.length === 1 && `${data.sections[0].singlesection}` === '1') {\n // We are on a page of a collapsed section. Do not show \"move before\" and \"move after\" controls.\n data.singlesectionmode = 1;\n data.sections[0].contentcollapsed = false;\n // TODO allow to move from collapsed section up level.\n }\n const buildParents = (sections, parents) => {\n for (var i in sections) {\n sections[i].parents = parents;\n sections[i].aftersectionid = (i > 0) ? sections[i - 1].id : 0;\n buildParents(sections[i].children, parents + ',' + sections[i].id);\n sections[i].lastchildid = sections[i].children.length ?\n sections[i].children[sections[i].children.length - 1].id : 0;\n }\n };\n buildParents(data.sections, '');\n data.lastchildid = data.sections.length ? data.sections[data.sections.length - 1].id : 0;\n\n ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: getString('movecoursesection', 'core'),\n large: true,\n buttons: {cancel: getString('closebuttontitle', 'core')},\n removeOnClose: true,\n })\n .then(modal => {\n // eslint-disable-next-line promise/no-nesting\n Templates.render('format_flexsections/local/content/movesection', data).\n then((body) => {\n modal.setBody(body);\n this._setupMoveSection(modal, modal.getBody()[0], sectionId, data);\n return null;\n })\n .fail(() => null);\n modal.show();\n return modal;\n })\n .fail(() => null);\n }\n\n /**\n * Handle a move activity request.\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestMoveCm(target, event) {\n event.preventDefault();\n const cmId = target.dataset.id;\n if (!cmId) {\n return;\n }\n const cmInfo = this.reactive.get('cm', cmId);\n\n const exporter = this.reactive.getExporter();\n const data = exporter.course(this.reactive.state);\n\n // TODO set before and after current as disabled.\n // TODO allow to move from collapsed section up level.\n\n data.cmid = cmInfo.id;\n data.cmname = cmInfo.name;\n\n ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: getString('movecoursemodule', 'core'),\n large: true,\n buttons: {cancel: getString('closebuttontitle', 'core')},\n removeOnClose: true,\n })\n .then(modal => {\n // eslint-disable-next-line promise/no-nesting\n Templates.render('format_flexsections/local/content/movecm', data).\n then((body) => {\n modal.setBody(body);\n this._setupMoveCm(modal, modal.getBody()[0], cmId, data);\n return null;\n })\n .fail(() => null);\n modal.show();\n return modal;\n })\n .fail(() => null);\n }\n\n /**\n * Set up a popup window for moving activity\n *\n * @param {Modal} modal\n * @param {Element} modalBody\n * @param {Number} cmId\n * @param {Object} data\n * @param {Element} element\n */\n _setupMoveCm(modal, modalBody, cmId, data, element = null) {\n\n // Capture click.\n modalBody.addEventListener('click', (event) => {\n const target = event.target;\n if (!target.matches('a') || target.dataset.for === undefined || target.dataset.id === undefined) {\n return;\n }\n if (target.getAttribute('aria-disabled')) {\n return;\n }\n event.preventDefault();\n\n const targetSectionId = (target.dataset.for === 'section') ? target.dataset.id : 0;\n const targetCmId = (target.dataset.for === 'cm') ? target.dataset.id : 0;\n this.reactive.dispatch('cmMove', [cmId], targetSectionId, targetCmId);\n this._destroyModal(modal, element);\n });\n }\n\n /**\n * Destroy modal popup\n *\n * @param {Modal} modal\n * @param {Element} element\n */\n _destroyModal(modal, element = null) {\n\n // Destroy\n modal.hide();\n const pendingDestroy = new Pending(`courseformat/actions:destroyModal`);\n if (element) {\n element.focus();\n }\n setTimeout(() =>{\n modal.destroy();\n pendingDestroy.resolve();\n }, 500);\n\n }\n\n /**\n * Set up a popup window for moving section\n *\n * @param {Modal} modal\n * @param {Element} modalBody\n * @param {Number} sectionId\n * @param {Object} data\n * @param {Element} element\n */\n _setupMoveSection(modal, modalBody, sectionId, data, element = null) {\n\n // Disable moving before or after itself or under one of its own children.\n const links = modalBody.querySelectorAll(`${this.selectors.SECTIONLINK}`);\n for (let i = 0; i < links.length; ++i) {\n const re = new RegExp(`,${sectionId},`, \"g\");\n if (links[i].getAttribute('data-before') === `${sectionId}` || links[i].getAttribute('data-after') === `${sectionId}` ||\n `${links[i].getAttribute('data-parents')},`.match(re)) {\n this._disableLink(links[i]);\n }\n // Disable moving to the depth that exceeds the maxsectiondepth setting.\n const depth = (`${links[i].getAttribute('data-parents')}`.match(/,/g) || []).length;\n if (data.maxsectiondepth && depth >= data.maxsectiondepth) {\n this._disableLink(links[i]);\n }\n }\n\n // TODO.\n // Setup keyboard navigation.\n // new ContentTree(\n // modalBody.querySelector(this.selectors.CONTENTTREE),\n // {\n // SECTION: this.selectors.SECTIONNODE,\n // TOGGLER: this.selectors.MODALTOGGLER,\n // COLLAPSE: this.selectors.MODALTOGGLER,\n // },\n // true\n // );\n\n // Capture click.\n modalBody.addEventListener('click', (event) => {\n\n const target = event.target;\n if (!target.matches('a') || target.dataset.for !== 'section' || target.dataset.after === undefined) {\n return;\n }\n if (target.getAttribute('aria-disabled')) {\n return;\n }\n event.preventDefault();\n const afterId = parseInt(target.dataset.after);\n const parentId = parseInt(target.dataset.parentid);\n this.reactive.dispatch('sectionMove', [sectionId], afterId ? afterId : -parentId);\n\n this._destroyModal(modal, element);\n });\n }\n\n /**\n * Disable link\n *\n * @param {Element} element\n */\n _disableLink(element) {\n if (element) {\n element.style.pointerEvents = 'none';\n element.style.userSelect = 'none';\n element.classList.add('disabled');\n element.setAttribute('aria-disabled', true);\n element.addEventListener('click', event => event.preventDefault());\n }\n }\n\n /**\n * Handle a request to add a subsection as the last child of the parent\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestAddSubSection(target, event) {\n event.preventDefault();\n this.reactive.dispatch('addSubSection', parseInt(target.dataset.parentid ?? 0));\n }\n\n /**\n * Handle a request to add a subsection as the first child of the parent\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestInsertSubSection(target, event) {\n event.preventDefault();\n this.reactive.dispatch('insertSubSection', parseInt(target.dataset.parentid ?? 0));\n }\n\n /**\n * Handle a request to switch the section mode (displayed on the same page vs as a link).\n *\n * @param {Element} target the dispatch action element\n * @param {Event} event the triggered event\n */\n _requestSectionSwitchCollapsed(target, event) {\n event.preventDefault();\n this.reactive.dispatch('sectionSwitchCollapsed', target.dataset.id ?? 0);\n }\n}\n"],"names":["BaseComponent","create","name","selectors","ACTIONLINK","SECTIONLINK","classes","DISABLED","stateReady","state","addEventListener","this","element","_dispatchClick","event","target","closest","classList","contains","preventDefault","methodName","_actionMethodName","getAttribute","undefined","requestName","charAt","toUpperCase","slice","_requestDelete","sectionId","dataset","id","sectionInfo","reactive","get","cmlist","length","hassummary","rawtitle","children","key","component","done","strings","confirm","dispatch","fail","Notification","exception","_requestMergeup","_requestMoveSection","data","getExporter","course","sectiontitle","title","sections","singlesection","singlesectionmode","contentcollapsed","buildParents","parents","i","aftersectionid","lastchildid","type","ModalFactory","types","CANCEL","large","buttons","cancel","removeOnClose","then","modal","render","body","setBody","_setupMoveSection","getBody","show","_requestMoveCm","cmId","cmInfo","cmid","cmname","_setupMoveCm","modalBody","matches","for","targetSectionId","targetCmId","_destroyModal","hide","pendingDestroy","Pending","focus","setTimeout","destroy","resolve","links","querySelectorAll","re","RegExp","match","_disableLink","depth","maxsectiondepth","after","afterId","parseInt","parentId","parentid","style","pointerEvents","userSelect","add","setAttribute","_requestAddSubSection","_requestInsertSubSection","_requestSectionSwitchCollapsed"],"mappings":";;;;;;;8SA6B6BA,wBAMzBC,cAESC,KAAO,oCAEPC,UAAY,CACbC,wCACAC,yCAGCC,QAAU,CACXC,qBAURC,WAAWC,aACDD,WAAWC,YAEZC,iBACDC,KAAKC,QACL,QACAD,KAAKE,gBAIbA,eAAeC,a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AQD,8BACnCA,MAAMK,sBACDc,SAASY,SAAS,oDAA0B9B,OAAOe,QAAQC,oDAAM"} \ No newline at end of file diff --git a/amd/src/local/content/actions.js b/amd/src/local/content/actions.js index 94b8a34..d28ded6 100644 --- a/amd/src/local/content/actions.js +++ b/amd/src/local/content/actions.js @@ -204,6 +204,7 @@ export default class extends BaseComponent { removeOnClose: true, }) .then(modal => { + // eslint-disable-next-line promise/no-nesting Templates.render('format_flexsections/local/content/movesection', data). then((body) => { modal.setBody(body); @@ -248,6 +249,7 @@ export default class extends BaseComponent { removeOnClose: true, }) .then(modal => { + // eslint-disable-next-line promise/no-nesting Templates.render('format_flexsections/local/content/movecm', data). then((body) => { modal.setBody(body); diff --git a/classes/courseformat/stateactions.php b/classes/courseformat/stateactions.php index 6b0ab94..0902ff8 100644 --- a/classes/courseformat/stateactions.php +++ b/classes/courseformat/stateactions.php @@ -33,7 +33,7 @@ class stateactions extends \core_courseformat\stateactions { /** * Moving a section * - * @param \core_courseformat\stateupdates $updates + * @param stateupdates $updates * @param stdClass $course * @param array $ids * @param int|null $targetsectionid if positive number, move AFTER this section under the same parent @@ -43,7 +43,7 @@ class stateactions extends \core_courseformat\stateactions { * @param int|null $targetcmid * @return void */ - public function section_move(\core_courseformat\stateupdates $updates, stdClass $course, array $ids, + public function section_move(stateupdates $updates, stdClass $course, array $ids, ?int $targetsectionid = null, ?int $targetcmid = null): void { $this->validate_sections($course, $ids, __FUNCTION__); @@ -137,7 +137,7 @@ public function section_mergeup( ?int $targetcmid = null ): void { if (!$targetsectionid) { - throw new \moodle_exception("Action section_mergeup requires targetsectionid"); + throw new moodle_exception("Action section_mergeup requires targetsectionid"); } $coursecontext = context_course::instance($course->id); @@ -150,7 +150,7 @@ public function section_mergeup( $this->validate_sections($course, [$targetsectionid], __FUNCTION__); $targetsection = $modinfo->get_section_info_by_id($targetsectionid, MUST_EXIST); if (!$targetsection->parent) { - throw new \moodle_exception("Action section_mergeup can't merge top level parentless sections"); + throw new moodle_exception("Action section_mergeup can't merge top level parentless sections"); } $format->mergeup_section($targetsection); @@ -291,14 +291,14 @@ public function section_add_subsection(\core_courseformat\stateupdates $updates, /** * Adding a subsection as the first child of the parent * - * @param \core_courseformat\stateupdates $updates + * @param stateupdates $updates * @param stdClass $course * @param array $ids not used * @param int|null $targetsectionid parent section id * @param int|null $targetcmid not used * @return void */ - public function section_insert_subsection(\core_courseformat\stateupdates $updates, stdClass $course, array $ids, + public function section_insert_subsection(stateupdates $updates, stdClass $course, array $ids, ?int $targetsectionid = null, ?int $targetcmid = null): void { require_capability('moodle/course:update', context_course::instance($course->id)); /** @var \format_flexsections $format */ diff --git a/classes/output/courseformat/content.php b/classes/output/courseformat/content.php index ae81eb6..9cf1481 100644 --- a/classes/output/courseformat/content.php +++ b/classes/output/courseformat/content.php @@ -52,6 +52,7 @@ public function get_template_name(\renderer_base $renderer): string { * @return \stdClass data context for a mustache template */ public function export_for_template(\renderer_base $output) { + /** @var \stdClass $data */ $data = parent::export_for_template($output); // If we are on course view page for particular section. diff --git a/classes/output/courseformat/content/section/controlmenu.php b/classes/output/courseformat/content/section/controlmenu.php index 1bc80ef..bb08f94 100644 --- a/classes/output/courseformat/content/section/controlmenu.php +++ b/classes/output/courseformat/content/section/controlmenu.php @@ -69,7 +69,7 @@ public function section_control_items() { if (has_capability('moodle/course:update', $coursecontext) && $section->section && $sectiondepth < $format->get_max_section_depth() && (!$section->collapsed || $section->section == $this->format->get_viewed_section())) { - $addsubsectionurl = new \moodle_url($url, ['addchildsection' => $section->section]); + $addsubsectionurl = new moodle_url($url, ['addchildsection' => $section->section]); $controls['addsubsection'] = [ 'url' => $addsubsectionurl, 'icon' => 't/add', @@ -84,7 +84,7 @@ public function section_control_items() { } if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) { - $markerurl = new \moodle_url($url); + $markerurl = new moodle_url($url); if ($course->marker == $section->section) { // Show the "light globe" on/off. $markerurl->param('marker', 0); $highlightoff = get_string('highlightoff'); @@ -116,7 +116,7 @@ public function section_control_items() { if ($section->section && has_capability('moodle/course:update', $coursecontext) && $section->section != $this->format->get_viewed_section()) { - $collapseurl = new \moodle_url($url, ['switchcollapsed' => $section->section]); + $collapseurl = new moodle_url($url, ['switchcollapsed' => $section->section]); $attrs = [ 'data-action-flexsections' => 'sectionSwitchCollapsed', 'class' => 'editing_collapsed', @@ -143,7 +143,7 @@ public function section_control_items() { if ($section->parent && has_capability('moodle/course:update', $coursecontext) && $section->section != $this->format->get_viewed_section()) { - $mergeupurl = new \moodle_url($url, ['mergeup' => $section->section]); + $mergeupurl = new moodle_url($url, ['mergeup' => $section->section]); $controls['mergeup'] = [ 'url' => $mergeupurl, 'icon' => 'mergeup', @@ -213,7 +213,7 @@ public function section_control_items() { * @param renderer_base $output typically, the renderer that's calling this function * @return array data context for a mustache template */ - public function export_for_template(\renderer_base $output): stdClass { + public function export_for_template(renderer_base $output): stdClass { $section = $this->section; diff --git a/format.js b/format.js index 0e34445..33ae584 100644 --- a/format.js +++ b/format.js @@ -1,3 +1,4 @@ +/* eslint-disable camelcase */ // Javascript functions for Flexible sections course format. // This is no longer used but there are errors in console if this file is missing.