diff --git a/backup/util/ui/amd/build/schema_backup_form.min.js b/backup/util/ui/amd/build/schema_backup_form.min.js new file mode 100644 index 00000000000..db8aee7a61d --- /dev/null +++ b/backup/util/ui/amd/build/schema_backup_form.min.js @@ -0,0 +1,14 @@ +define("core_backup/schema_backup_form",["exports","core/notification","core/templates"],(function(_exports,_notification,Templates){var obj; +/** + * Schema selector javascript controls. + * + * This module controls: + * - The select all feature. + * - Disabling activities checkboxes when the section is not selected. + * + * @module core_backup/schema_backup_form + * @copyright 2024 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj},Templates=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Templates);const Selectors_action="[data-mdl-action]",Selectors_checkboxes='#id_coursesettings input[type="checkbox"]',Selectors_firstSection="fieldset#id_coursesettings .fcontainer .grouped_settings.section_level",Selectors_modCheckboxes=modName=>"setting_activity_".concat(modName,"_"),Suffixes_userData="_userdata",Suffixes_userInfo="_userinfo",Suffixes_included="_included";class BackupFormController{static init(modNames){return new BackupFormController(modNames)}constructor(modNames){this.modNames=modNames,this.scanFormUserData(),this.addSelectorsToPage()}scanFormUserData(){this.withuserdata=!1,this.userDataSuffix=Suffixes_userData;const checkboxes=document.querySelectorAll(Selectors_checkboxes);if(checkboxes)for(const checkbox of checkboxes){const name=checkbox.name;if(name.endsWith(Suffixes_userData)){this.withuserdata=!0;break}if(name.endsWith(Suffixes_userInfo)){this.withuserdata=!0,this.userDataSuffix=Suffixes_userInfo;break}}}initEvents(element){element.addEventListener("click",(event=>{var _action$dataset,_action$dataset$mdlMo,_action$dataset2;const action=event.target.closest(Selectors_action);if(!action)return;event.preventDefault();const suffix="userdata"==(null===(_action$dataset=action.dataset)||void 0===_action$dataset?void 0:_action$dataset.mdlType)?this.userDataSuffix:Suffixes_included;this.changeSelection("selectall"==action.dataset.mdlAction,suffix,null!==(_action$dataset$mdlMo=null===(_action$dataset2=action.dataset)||void 0===_action$dataset2?void 0:_action$dataset2.mdlMod)&&void 0!==_action$dataset$mdlMo?_action$dataset$mdlMo:null)}))}changeSelection(checked,suffix,modName){const prefix=modName?Selectors_modCheckboxes(modName):null;let formId;const checkboxes=document.querySelectorAll(Selectors_checkboxes);for(const checkbox of checkboxes){var _formId;formId=null!==(_formId=formId)&&void 0!==_formId?_formId:checkbox.closest("form").getAttribute("id"),prefix&&!checkbox.name.startsWith(prefix)||checkbox.name.endsWith(suffix)&&(checkbox.checked=checked)}formId&&M.form&&M.form.updateFormState(formId)}generateSelectorsElement(){const links=document.createElement("div");return links.id="backup_selectors",this.initEvents(links),this.renderSelectorsTemplate(links),links}renderSelectorsTemplate(element){const data={modules:this.getModulesTemplateData(),withuserdata:!!this.withuserdata||void 0};Templates.renderForPromise("core_backup/formselectall",data).then((_ref=>{let{html:html,js:js}=_ref;return Templates.replaceNodeContents(element,html,js)})).catch(_notification.default.exception)}getModulesTemplateData(){const modules=[];for(const modName in this.modNames)this.modNames.hasOwnProperty(modName)&&modules.push({modname:modName,heading:this.modNames[modName]});return modules}addSelectorsToPage(){const firstSection=document.querySelector(Selectors_firstSection);if(!firstSection)return;if(!firstSection.querySelector(Selectors_checkboxes))return;const selector=this.generateSelectorsElement();firstSection.parentNode.insertBefore(selector,firstSection)}}return _exports.default=BackupFormController,_exports.default})); + +//# sourceMappingURL=schema_backup_form.min.js.map \ No newline at end of file diff --git a/backup/util/ui/amd/build/schema_backup_form.min.js.map b/backup/util/ui/amd/build/schema_backup_form.min.js.map new file mode 100644 index 00000000000..a7dd9eb9760 --- /dev/null +++ b/backup/util/ui/amd/build/schema_backup_form.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"schema_backup_form.min.js","sources":["../src/schema_backup_form.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 * Schema selector javascript controls.\n *\n * This module controls:\n * - The select all feature.\n * - Disabling activities checkboxes when the section is not selected.\n *\n * @module core_backup/schema_backup_form\n * @copyright 2024 Ferran Recio \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Notification from 'core/notification';\nimport * as Templates from 'core/templates';\n\nconst Selectors = {\n action: '[data-mdl-action]',\n checkboxes: '#id_coursesettings input[type=\"checkbox\"]',\n firstSection: 'fieldset#id_coursesettings .fcontainer .grouped_settings.section_level',\n modCheckboxes: (modName) => `setting_activity_${modName}_`,\n};\n\nconst Suffixes = {\n userData: '_userdata',\n userInfo: '_userinfo',\n included: '_included',\n};\n\n/**\n * Adds select all/none links to the top of the backup/restore/import schema page.\n */\nexport default class BackupFormController {\n\n /**\n * Static module init method.\n * @param {Array} modNames - The names of the modules.\n * @returns {BackupFormController}\n */\n static init(modNames) {\n return new BackupFormController(modNames);\n }\n\n /**\n * Creates a new instance of the SchemaBackupForm class.\n * @param {Array} modNames - The names of the modules.\n */\n constructor(modNames) {\n this.modNames = modNames;\n this.scanFormUserData();\n this.addSelectorsToPage();\n }\n\n /**\n * Detect the user data attribute from the form.\n *\n * @private\n */\n scanFormUserData() {\n this.withuserdata = false;\n this.userDataSuffix = Suffixes.userData;\n\n const checkboxes = document.querySelectorAll(Selectors.checkboxes);\n if (!checkboxes) {\n return;\n }\n // Depending on the form, user data inclusion is called userinfo or userdata.\n for (const checkbox of checkboxes) {\n const name = checkbox.name;\n if (name.endsWith(Suffixes.userData)) {\n this.withuserdata = true;\n break;\n } else if (name.endsWith(Suffixes.userInfo)) {\n this.withuserdata = true;\n this.userDataSuffix = Suffixes.userInfo;\n break;\n }\n }\n }\n\n /**\n * Initializes all related events.\n *\n * @private\n * @param {HTMLElement} element - The element to attach the events to.\n */\n initEvents(element) {\n element.addEventListener('click', (event) => {\n const action = event.target.closest(Selectors.action);\n if (!action) {\n return;\n }\n event.preventDefault();\n\n const suffix = (action.dataset?.mdlType == 'userdata') ? this.userDataSuffix : Suffixes.included;\n\n this.changeSelection(\n action.dataset.mdlAction == 'selectall',\n suffix,\n action.dataset?.mdlMod ?? null\n );\n });\n }\n\n /**\n * Changes the selection according to the params.\n *\n * @private\n * @param {boolean} checked - The checked state for the checkboxes.\n * @param {string} suffix - The checkboxes suffix\n * @param {string} [modName] - The module name.\n */\n changeSelection(checked, suffix, modName) {\n const prefix = modName ? Selectors.modCheckboxes(modName) : null;\n\n let formId;\n\n const checkboxes = document.querySelectorAll(Selectors.checkboxes);\n for (const checkbox of checkboxes) {\n formId = formId ?? checkbox.closest('form').getAttribute('id');\n\n if (prefix && !checkbox.name.startsWith(prefix)) {\n continue;\n }\n if (checkbox.name.endsWith(suffix)) {\n checkbox.checked = checked;\n }\n }\n\n // At this point, we really need to persuade the form we are part of to\n // update all of its disabledIf rules. However, as far as I can see,\n // given the way that lib/form/form.js is written, that is impossible.\n if (formId && M.form) {\n M.form.updateFormState(formId);\n }\n }\n\n /**\n * Generates the full selectors element to add to the page.\n *\n * @private\n * @returns {HTMLElement} The selectors element.\n */\n generateSelectorsElement() {\n const links = document.createElement('div');\n links.id = 'backup_selectors';\n this.initEvents(links);\n this.renderSelectorsTemplate(links);\n return links;\n }\n\n /**\n * Load the select all template.\n *\n * @private\n * @param {HTMLElement} element the container\n */\n renderSelectorsTemplate(element) {\n const data = {\n modules: this.getModulesTemplateData(),\n withuserdata: (this.withuserdata) ? true : undefined,\n };\n Templates.renderForPromise(\n 'core_backup/formselectall',\n data\n ).then(({html, js}) => {\n return Templates.replaceNodeContents(element, html, js);\n }).catch(Notification.exception);\n }\n\n /**\n * Generate the modules template data.\n *\n * @private\n * @returns {Array} of modules data.\n */\n getModulesTemplateData() {\n const modules = [];\n for (const modName in this.modNames) {\n if (!this.modNames.hasOwnProperty(modName)) {\n continue;\n }\n modules.push({\n modname: modName,\n heading: this.modNames[modName],\n });\n }\n return modules;\n }\n\n /**\n * Adds select all/none functionality to the backup form.\n *\n * @private\n */\n addSelectorsToPage() {\n const firstSection = document.querySelector(Selectors.firstSection);\n if (!firstSection) {\n // This is not a relevant page.\n return;\n }\n if (!firstSection.querySelector(Selectors.checkboxes)) {\n // No checkboxes.\n return;\n }\n\n // Add global select all/none options.\n const selector = this.generateSelectorsElement();\n firstSection.parentNode.insertBefore(selector, firstSection);\n }\n}\n"],"names":["Selectors","modName","Suffixes","BackupFormController","modNames","constructor","scanFormUserData","addSelectorsToPage","withuserdata","userDataSuffix","checkboxes","document","querySelectorAll","checkbox","name","endsWith","initEvents","element","addEventListener","event","action","target","closest","preventDefault","suffix","dataset","mdlType","this","changeSelection","mdlAction","_action$dataset2","mdlMod","checked","prefix","formId","getAttribute","startsWith","M","form","updateFormState","generateSelectorsElement","links","createElement","id","renderSelectorsTemplate","data","modules","getModulesTemplateData","undefined","Templates","renderForPromise","then","_ref","html","js","replaceNodeContents","catch","Notification","exception","hasOwnProperty","push","modname","heading","firstSection","querySelector","selector","parentNode","insertBefore"],"mappings":";;;;;;;;;;;olCA8BMA,iBACM,oBADNA,qBAEU,4CAFVA,uBAGY,yEAHZA,wBAIcC,oCAAgCA,aAG9CC,kBACQ,YADRA,kBAEQ,YAFRA,kBAGQ,kBAMOC,iCAOLC,iBACD,IAAID,qBAAqBC,UAOpCC,YAAYD,eACHA,SAAWA,cACXE,wBACAC,qBAQTD,wBACSE,cAAe,OACfC,eAAiBP,wBAEhBQ,WAAaC,SAASC,iBAAiBZ,yBACxCU,eAIA,MAAMG,YAAYH,WAAY,OACzBI,KAAOD,SAASC,QAClBA,KAAKC,SAASb,mBAAoB,MAC7BM,cAAe,QAEjB,GAAIM,KAAKC,SAASb,mBAAoB,MACpCM,cAAe,OACfC,eAAiBP,0BAYlCc,WAAWC,SACPA,QAAQC,iBAAiB,SAAUC,yEACzBC,OAASD,MAAME,OAAOC,QAAQtB,sBAC/BoB,cAGLD,MAAMI,uBAEAC,OAAqC,qCAA3BJ,OAAOK,0DAASC,SAAyBC,KAAKlB,eAAiBP,uBAE1E0B,gBAC2B,aAA5BR,OAAOK,QAAQI,UACfL,8DACAJ,OAAOK,2CAAPK,iBAAgBC,8DAAU,SAatCH,gBAAgBI,QAASR,OAAQvB,eACvBgC,OAAShC,QAAUD,wBAAwBC,SAAW,SAExDiC,aAEExB,WAAaC,SAASC,iBAAiBZ,0BACxC,MAAMa,YAAYH,WAAY,aAC/BwB,uBAASA,kCAAUrB,SAASS,QAAQ,QAAQa,aAAa,MAErDF,SAAWpB,SAASC,KAAKsB,WAAWH,SAGpCpB,SAASC,KAAKC,SAASS,UACvBX,SAASmB,QAAUA,SAOvBE,QAAUG,EAAEC,MACZD,EAAEC,KAAKC,gBAAgBL,QAU/BM,iCACUC,MAAQ9B,SAAS+B,cAAc,cACrCD,MAAME,GAAK,wBACN3B,WAAWyB,YACXG,wBAAwBH,OACtBA,MASXG,wBAAwB3B,eACd4B,KAAO,CACTC,QAASnB,KAAKoB,yBACdvC,eAAemB,KAAKnB,mBAAuBwC,GAE/CC,UAAUC,iBACN,4BACAL,MACFM,MAAKC,WAACC,KAACA,KAADC,GAAOA,gBACJL,UAAUM,oBAAoBtC,QAASoC,KAAMC,OACrDE,MAAMC,sBAAaC,WAS1BX,+BACUD,QAAU,OACX,MAAM7C,WAAW0B,KAAKvB,SAClBuB,KAAKvB,SAASuD,eAAe1D,UAGlC6C,QAAQc,KAAK,CACTC,QAAS5D,QACT6D,QAASnC,KAAKvB,SAASH,kBAGxB6C,QAQXvC,2BACUwD,aAAepD,SAASqD,cAAchE,4BACvC+D,wBAIAA,aAAaC,cAAchE,mCAM1BiE,SAAWtC,KAAKa,2BACtBuB,aAAaG,WAAWC,aAAaF,SAAUF"} \ No newline at end of file diff --git a/backup/util/ui/amd/src/schema_backup_form.js b/backup/util/ui/amd/src/schema_backup_form.js new file mode 100644 index 00000000000..cc4dcecbef2 --- /dev/null +++ b/backup/util/ui/amd/src/schema_backup_form.js @@ -0,0 +1,225 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Schema selector javascript controls. + * + * This module controls: + * - The select all feature. + * - Disabling activities checkboxes when the section is not selected. + * + * @module core_backup/schema_backup_form + * @copyright 2024 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import Notification from 'core/notification'; +import * as Templates from 'core/templates'; + +const Selectors = { + action: '[data-mdl-action]', + checkboxes: '#id_coursesettings input[type="checkbox"]', + firstSection: 'fieldset#id_coursesettings .fcontainer .grouped_settings.section_level', + modCheckboxes: (modName) => `setting_activity_${modName}_`, +}; + +const Suffixes = { + userData: '_userdata', + userInfo: '_userinfo', + included: '_included', +}; + +/** + * Adds select all/none links to the top of the backup/restore/import schema page. + */ +export default class BackupFormController { + + /** + * Static module init method. + * @param {Array} modNames - The names of the modules. + * @returns {BackupFormController} + */ + static init(modNames) { + return new BackupFormController(modNames); + } + + /** + * Creates a new instance of the SchemaBackupForm class. + * @param {Array} modNames - The names of the modules. + */ + constructor(modNames) { + this.modNames = modNames; + this.scanFormUserData(); + this.addSelectorsToPage(); + } + + /** + * Detect the user data attribute from the form. + * + * @private + */ + scanFormUserData() { + this.withuserdata = false; + this.userDataSuffix = Suffixes.userData; + + const checkboxes = document.querySelectorAll(Selectors.checkboxes); + if (!checkboxes) { + return; + } + // Depending on the form, user data inclusion is called userinfo or userdata. + for (const checkbox of checkboxes) { + const name = checkbox.name; + if (name.endsWith(Suffixes.userData)) { + this.withuserdata = true; + break; + } else if (name.endsWith(Suffixes.userInfo)) { + this.withuserdata = true; + this.userDataSuffix = Suffixes.userInfo; + break; + } + } + } + + /** + * Initializes all related events. + * + * @private + * @param {HTMLElement} element - The element to attach the events to. + */ + initEvents(element) { + element.addEventListener('click', (event) => { + const action = event.target.closest(Selectors.action); + if (!action) { + return; + } + event.preventDefault(); + + const suffix = (action.dataset?.mdlType == 'userdata') ? this.userDataSuffix : Suffixes.included; + + this.changeSelection( + action.dataset.mdlAction == 'selectall', + suffix, + action.dataset?.mdlMod ?? null + ); + }); + } + + /** + * Changes the selection according to the params. + * + * @private + * @param {boolean} checked - The checked state for the checkboxes. + * @param {string} suffix - The checkboxes suffix + * @param {string} [modName] - The module name. + */ + changeSelection(checked, suffix, modName) { + const prefix = modName ? Selectors.modCheckboxes(modName) : null; + + let formId; + + const checkboxes = document.querySelectorAll(Selectors.checkboxes); + for (const checkbox of checkboxes) { + formId = formId ?? checkbox.closest('form').getAttribute('id'); + + if (prefix && !checkbox.name.startsWith(prefix)) { + continue; + } + if (checkbox.name.endsWith(suffix)) { + checkbox.checked = checked; + } + } + + // At this point, we really need to persuade the form we are part of to + // update all of its disabledIf rules. However, as far as I can see, + // given the way that lib/form/form.js is written, that is impossible. + if (formId && M.form) { + M.form.updateFormState(formId); + } + } + + /** + * Generates the full selectors element to add to the page. + * + * @private + * @returns {HTMLElement} The selectors element. + */ + generateSelectorsElement() { + const links = document.createElement('div'); + links.id = 'backup_selectors'; + this.initEvents(links); + this.renderSelectorsTemplate(links); + return links; + } + + /** + * Load the select all template. + * + * @private + * @param {HTMLElement} element the container + */ + renderSelectorsTemplate(element) { + const data = { + modules: this.getModulesTemplateData(), + withuserdata: (this.withuserdata) ? true : undefined, + }; + Templates.renderForPromise( + 'core_backup/formselectall', + data + ).then(({html, js}) => { + return Templates.replaceNodeContents(element, html, js); + }).catch(Notification.exception); + } + + /** + * Generate the modules template data. + * + * @private + * @returns {Array} of modules data. + */ + getModulesTemplateData() { + const modules = []; + for (const modName in this.modNames) { + if (!this.modNames.hasOwnProperty(modName)) { + continue; + } + modules.push({ + modname: modName, + heading: this.modNames[modName], + }); + } + return modules; + } + + /** + * Adds select all/none functionality to the backup form. + * + * @private + */ + addSelectorsToPage() { + const firstSection = document.querySelector(Selectors.firstSection); + if (!firstSection) { + // This is not a relevant page. + return; + } + if (!firstSection.querySelector(Selectors.checkboxes)) { + // No checkboxes. + return; + } + + // Add global select all/none options. + const selector = this.generateSelectorsElement(); + firstSection.parentNode.insertBefore(selector, firstSection); + } +} diff --git a/backup/util/ui/base_moodleform.class.php b/backup/util/ui/base_moodleform.class.php index af011480baa..88925ce8cdc 100644 --- a/backup/util/ui/base_moodleform.class.php +++ b/backup/util/ui/base_moodleform.class.php @@ -416,8 +416,7 @@ abstract class base_moodleform extends moodleform { $modinfo = get_fast_modinfo($COURSE); $modnames = array_map('strval', $modinfo->get_used_module_names(true)); core_collator::asort($modnames); - $PAGE->requires->yui_module('moodle-backup-backupselectall', 'M.core_backup.backupselectall', - array($modnames)); + $PAGE->requires->js_call_amd('core_backup/schema_backup_form', 'init', [$modnames]); $PAGE->requires->strings_for_js(array('select', 'all', 'none'), 'moodle'); $PAGE->requires->strings_for_js(array('showtypes', 'hidetypes'), 'backup'); diff --git a/backup/util/ui/templates/formselectall.mustache b/backup/util/ui/templates/formselectall.mustache new file mode 100644 index 00000000000..cde4fd2ac1e --- /dev/null +++ b/backup/util/ui/templates/formselectall.mustache @@ -0,0 +1,131 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_backup/formselectall + + TODO describe template formselectall + + Example context (json): + { + "withuserdata": true, + "modules": [ + { + "modname": "assign", + "heading": "Assignments" + }, + { + "modname": "book", + "heading": "Books" + } + ] + } +}} +
+ + {{#withuserdata}} + + {{/withuserdata}} + +
diff --git a/backup/util/ui/tests/behat/schema_select_all.feature b/backup/util/ui/tests/behat/schema_select_all.feature new file mode 100644 index 00000000000..90e491c0086 --- /dev/null +++ b/backup/util/ui/tests/behat/schema_select_all.feature @@ -0,0 +1,280 @@ +@core @core_backup +Feature: Schema form selectors + In order to quickly select schema elements + As an admin + I need to use the selectors UI to toggle selection of schema elements + + Background: + Given the following "courses" exist: + | fullname | shortname | category | numsections | initsections | + | Course 1 | C1 | 0 | 2 | 1 | + And the following "activities" exist: + | activity | course | idnumber | name | intro | section | + | assign | C1 | assign1 | Test assign 1 | Assign description | 1 | + | data | C1 | data1 | Test data 1 | Database description | 1 | + | assign | C1 | assign2 | Test assign 2 | Assign description | 2 | + | data | C1 | data2 | Test data 2 | Database description | 2 | + And I am on the "C1" "Course" page logged in as "admin" + And I navigate to "Course reuse" in current page administration + And I follow "Backup" + And I click on "Next" "button" in the "page-content" "region" + + @javascript + Scenario: Select all and none should toggle backup schema checkboxes + Given the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test select none. + When I click on "None" "link" in the "backup_selectors_included" "region" + Then the field "Section 1" matches value "" + And the field "Test assign 1" matches value "" + And the field "Test data 1" matches value "" + And the field "Section 2" matches value "" + And the field "Test assign 2" matches value "" + And the field "Test data 2" matches value "" + And the "Section 1: User data" "checkbox" should be disabled + And the "Include Test assign 1 user data" "checkbox" should be disabled + And the "Include Test data 1 user data" "checkbox" should be disabled + And the "Section 2: User data" "checkbox" should be disabled + And the "Include Test assign 2 user data" "checkbox" should be disabled + And the "Include Test data 2 user data" "checkbox" should be disabled + # Test select all. + And I click on "All" "link" in the "backup_selectors_included" "region" + And the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + + @javascript + Scenario: The type options panell allow to select all and none of one activity type + Given the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test select none assignment. + When I click on "Show type options" "link" in the "backup_selectors_included" "region" + And I click on "None" "link" in the "backup_selectors_mod_assign" "region" + Then the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be disabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be disabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test select all assignments. + And I click on "All" "link" in the "backup_selectors_mod_assign" "region" + And the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + + @javascript + Scenario: Select all or none in user data should toggle backup schema checkboxes + Given the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "1" + And the field "Include Test assign 1 user data" matches value "1" + And the field "Include Test data 1 user data" matches value "1" + And the field "Section 2: User data" matches value "1" + And the field "Include Test assign 2 user data" matches value "1" + And the field "Include Test data 2 user data" matches value "1" + # Test select none. + When I click on "None" "link" in the "backup_selectors_userdata" "region" + Then the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "" + And the field "Include Test assign 1 user data" matches value "" + And the field "Include Test data 1 user data" matches value "" + And the field "Section 2: User data" matches value "" + And the field "Include Test assign 2 user data" matches value "" + And the field "Include Test data 2 user data" matches value "" + # Test select all. + And I click on "All" "link" in the "backup_selectors_userdata" "region" + And the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "1" + And the field "Include Test assign 1 user data" matches value "1" + And the field "Include Test data 1 user data" matches value "1" + And the field "Section 2: User data" matches value "1" + And the field "Include Test assign 2 user data" matches value "1" + And the field "Include Test data 2 user data" matches value "1" + + @javascript + Scenario: The type options panell allow to select all and none user data for an activity type + Given the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "1" + And the field "Include Test assign 1 user data" matches value "1" + And the field "Include Test data 1 user data" matches value "1" + And the field "Section 2: User data" matches value "1" + And the field "Include Test assign 2 user data" matches value "1" + And the field "Include Test data 2 user data" matches value "1" + # Test select none assignment. + When I click on "Show type options" "link" in the "backup_selectors_included" "region" + And I click on "None" "link" in the "backup_selectors_userdata-mod_assign" "region" + Then the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "1" + And the field "Include Test assign 1 user data" matches value "" + And the field "Include Test data 1 user data" matches value "1" + And the field "Section 2: User data" matches value "1" + And the field "Include Test assign 2 user data" matches value "" + And the field "Include Test data 2 user data" matches value "1" + # Test select all assignments. + And I click on "All" "link" in the "backup_selectors_userdata-mod_assign" "region" + And the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the field "Section 1: User data" matches value "1" + And the field "Include Test assign 1 user data" matches value "1" + And the field "Include Test data 1 user data" matches value "1" + And the field "Section 2: User data" matches value "1" + And the field "Include Test assign 2 user data" matches value "1" + And the field "Include Test data 2 user data" matches value "1" + + @javascript + Scenario: Select or unselect a section schema disable the activities checkboxes + Given the field "Section 1" matches value "1" + And the field "Test assign 1" matches value "1" + And the field "Test data 1" matches value "1" + And the field "Section 2" matches value "1" + And the field "Test assign 2" matches value "1" + And the field "Test data 2" matches value "1" + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test unselect section 1. + When I set the field "Section 1" to "" + Then the field "Section 1" matches value "" + And the "Test assign 1" "checkbox" should be disabled + And the "Test data 1" "checkbox" should be disabled + And the "Section 2" "checkbox" should be enabled + And the "Test assign 2" "checkbox" should be enabled + And the "Test data 2" "checkbox" should be enabled + And the "Section 1: User data" "checkbox" should be disabled + And the "Include Test assign 1 user data" "checkbox" should be disabled + And the "Include Test data 1 user data" "checkbox" should be disabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test select section 1. + And I set the field "Section 1" to "1" + And the field "Section 1" matches value "1" + And the "Test assign 1" "checkbox" should be enabled + And the "Test data 1" "checkbox" should be enabled + And the "Section 2" "checkbox" should be enabled + And the "Test assign 2" "checkbox" should be enabled + And the "Test data 2" "checkbox" should be enabled + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + + @javascript + Scenario: Select or unselect a section user data disable the activities checkboxes + Given the "Section 1" "checkbox" should be enabled + And the "Test assign 1" "checkbox" should be enabled + And the "Test data 1" "checkbox" should be enabled + And the "Section 2" "checkbox" should be enabled + And the "Test assign 2" "checkbox" should be enabled + And the "Test data 2" "checkbox" should be enabled + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test unselect section 1. + When I set the field "Section 1: User data" to "" + Then the "Section 1" "checkbox" should be enabled + And the "Test assign 1" "checkbox" should be enabled + And the "Test data 1" "checkbox" should be enabled + And the "Section 2" "checkbox" should be enabled + And the "Test assign 2" "checkbox" should be enabled + And the "Test data 2" "checkbox" should be enabled + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be disabled + And the "Include Test data 1 user data" "checkbox" should be disabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled + # Test select section 1. + And I set the field "Section 1: User data" to "1" + And the "Section 1" "checkbox" should be enabled + And the "Test assign 1" "checkbox" should be enabled + And the "Test data 1" "checkbox" should be enabled + And the "Section 2" "checkbox" should be enabled + And the "Test assign 2" "checkbox" should be enabled + And the "Test data 2" "checkbox" should be enabled + And the "Section 1: User data" "checkbox" should be enabled + And the "Include Test assign 1 user data" "checkbox" should be enabled + And the "Include Test data 1 user data" "checkbox" should be enabled + And the "Section 2: User data" "checkbox" should be enabled + And the "Include Test assign 2 user data" "checkbox" should be enabled + And the "Include Test data 2 user data" "checkbox" should be enabled diff --git a/backup/util/ui/yui/build/moodle-backup-backupselectall/moodle-backup-backupselectall-debug.js b/backup/util/ui/yui/build/moodle-backup-backupselectall/moodle-backup-backupselectall-debug.js deleted file mode 100644 index 258eb3f92ce..00000000000 --- a/backup/util/ui/yui/build/moodle-backup-backupselectall/moodle-backup-backupselectall-debug.js +++ /dev/null @@ -1,193 +0,0 @@ -YUI.add('moodle-backup-backupselectall', function (Y, NAME) { - -/** - * Adds select all/none links to the top of the backup/restore/import schema page. - * - * @module moodle-backup-backupselectall - */ - -// Namespace for the backup -M.core_backup = M.core_backup || {}; - -/** - * Adds select all/none links to the top of the backup/restore/import schema page. - * - * @class M.core_backup.backupselectall - */ -M.core_backup.backupselectall = function(modnames) { - var formid = null; - - var helper = function(e, check, type, mod) { - e.preventDefault(); - var prefix = ''; - if (typeof mod !== 'undefined') { - prefix = 'setting_activity_' + mod + '_'; - } - - var len = type.length; - Y.all('input[type="checkbox"]').each(function(checkbox) { - var name = checkbox.get('name'); - // If a prefix has been set, ignore checkboxes which don't have that prefix. - if (prefix && name.substring(0, prefix.length) !== prefix) { - return; - } - if (name.substring(name.length - len) === type) { - checkbox.set('checked', check); - } - }); - - // At this point, we really need to persuade the form we are part of to - // update all of its disabledIf rules. However, as far as I can see, - // given the way that lib/form/form.js is written, that is impossible. - if (formid && M.form) { - M.form.updateFormState(formid); - } - }; - - var html_generator = function(classname, idtype, heading, extra) { - if (typeof extra === 'undefined') { - extra = ''; - } - return '
' + - '
' + - '
' + heading + '
' + - '' + - '
' + - '
'; - }; - - var firstsection = Y.one('fieldset#id_coursesettings .fcontainer .grouped_settings.section_level'); - if (!firstsection) { - // This is not a relevant page. - return; - } - if (!firstsection.one('input[type="checkbox"]')) { - // No checkboxes. - return; - } - - formid = firstsection.ancestor('form').getAttribute('id'); - - var withuserdata = false; - Y.all('input[type="checkbox"]').each(function(checkbox) { - var name = checkbox.get('name'); - if (name.substring(name.length - 9) === '_userdata') { - withuserdata = '_userdata'; - } else if (name.substring(name.length - 9) === '_userinfo') { - withuserdata = '_userinfo'; - } - }); - - // Add global select all/none options. - var html = html_generator('include_setting section_level', 'included', M.util.get_string('select', 'moodle'), - ' (' + M.util.get_string('showtypes', 'backup') + ')'); - if (withuserdata) { - html += html_generator('normal_setting', 'userdata', M.util.get_string('select', 'moodle')); - } - var links = Y.Node.create('
' + html + '
'); - firstsection.insert(links, 'before'); - - // Add select all/none for each module type. - var initlinks = function(links, mod) { - Y.one('#backup-all-mod_' + mod).on('click', function(e) { - helper(e, true, '_included', mod); - }); - Y.one('#backup-none-mod_' + mod).on('click', function(e) { - helper(e, false, '_included', mod); - }); - if (withuserdata) { - Y.one('#backup-all-userdata-mod_' + mod).on('click', function(e) { - helper(e, true, withuserdata, mod); - }); - Y.one('#backup-none-userdata-mod_' + mod).on('click', function(e) { - helper(e, false, withuserdata, mod); - }); - } - }; - - // For each module type on the course, add hidden select all/none options. - var modlist = Y.Node.create('