From 47c0e48c9cc7cadbcb729823227367664d31b023 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 7 Feb 2023 17:38:57 +0000 Subject: [PATCH] MDL-77172 tool_capability: replace YUI search with ESM version. --- admin/tool/capability/amd/build/search.min.js | 10 + .../capability/amd/build/search.min.js.map | 1 + admin/tool/capability/amd/src/search.js | 102 ++++++++++ .../tool/capability/classes/settings_form.php | 10 +- admin/tool/capability/index.php | 7 +- admin/tool/capability/styles.css | 4 + .../tests/behat/show_capabilies.feature | 9 +- .../moodle-tool_capability-search-debug.js | 182 ------------------ .../moodle-tool_capability-search-min.js | 1 - .../moodle-tool_capability-search.js | 182 ------------------ .../tool/capability/yui/src/search/build.json | 10 - .../capability/yui/src/search/js/search.js | 177 ----------------- .../yui/src/search/meta/search.json | 8 - theme/boost/scss/moodle/admin.scss | 4 - theme/boost/style/moodle.css | 3 - theme/classic/style/moodle.css | 3 - 16 files changed, 129 insertions(+), 584 deletions(-) create mode 100644 admin/tool/capability/amd/build/search.min.js create mode 100644 admin/tool/capability/amd/build/search.min.js.map create mode 100644 admin/tool/capability/amd/src/search.js delete mode 100644 admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-debug.js delete mode 100644 admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-min.js delete mode 100644 admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search.js delete mode 100644 admin/tool/capability/yui/src/search/build.json delete mode 100644 admin/tool/capability/yui/src/search/js/search.js delete mode 100644 admin/tool/capability/yui/src/search/meta/search.json diff --git a/admin/tool/capability/amd/build/search.min.js b/admin/tool/capability/amd/build/search.min.js new file mode 100644 index 0000000000000..3ebe01ab0e872 --- /dev/null +++ b/admin/tool/capability/amd/build/search.min.js @@ -0,0 +1,10 @@ +define("tool_capability/search",["exports","core/pending","core/utils"],(function(_exports,_pending,_utils){var obj; +/** + * Add search filtering of capabilities + * + * @module tool_capability/search + * @copyright 2023 Paul Holden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_pending=(obj=_pending)&&obj.__esModule?obj:{default:obj};const Selectors_capabilityOverviewForm="#capability-overview-form",Selectors_capabilitySelect='[data-search="capability"]',Selectors_capabilitySearch='[data-action="search"]';_exports.init=()=>{const capabilityOverviewForm=document.querySelector(Selectors_capabilityOverviewForm);if(!capabilityOverviewForm)return;const capabilitySelect=capabilityOverviewForm.querySelector(Selectors_capabilitySelect),capabilitySearch=capabilityOverviewForm.querySelector(Selectors_capabilitySearch),capabilitySelectFilter=searchTerm=>{const pendingPromise=new _pending.default("tool_capability/search:filter");let capabilitySelected=[];capabilitySelect.querySelectorAll("option").forEach((option=>{option.selected&&capabilitySelected.push(option.value),option.remove()}));const availableCapabilities=JSON.parse(capabilitySelect.dataset.availableCapabilities),filteredCapabilities=Object.keys(availableCapabilities).reduce(((matches,capability)=>(availableCapabilities[capability].toLowerCase().includes(searchTerm)&&(matches[capability]=availableCapabilities[capability]),matches)),[]);Object.entries(filteredCapabilities).forEach((_ref=>{let[capability,capabilityText]=_ref;const option=document.createElement("option");option.value=capability,option.innerText=capabilityText,option.selected=capabilitySelected.indexOf(capability)>-1,capabilitySelect.append(option)})),pendingPromise.resolve()},availableCapabilities={};capabilitySelect.querySelectorAll("option").forEach((option=>{availableCapabilities[option.value]=option.text})),capabilitySelect.dataset.availableCapabilities=JSON.stringify(availableCapabilities);const capabilitySearchDebounce=(0,_utils.debounce)(capabilitySelectFilter,250);capabilitySearch.addEventListener("keyup",(event=>{const pendingPromise=new _pending.default("tool_capability/search:keyup");capabilitySearchDebounce(event.target.value.toLowerCase()),setTimeout((()=>{pendingPromise.resolve()}),250)})),""!==capabilitySearch.value&&capabilitySelectFilter(capabilitySearch.value.toLowerCase())}})); + +//# sourceMappingURL=search.min.js.map \ No newline at end of file diff --git a/admin/tool/capability/amd/build/search.min.js.map b/admin/tool/capability/amd/build/search.min.js.map new file mode 100644 index 0000000000000..7e148fde8c146 --- /dev/null +++ b/admin/tool/capability/amd/build/search.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"search.min.js","sources":["../src/search.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 * Add search filtering of capabilities\n *\n * @module tool_capability/search\n * @copyright 2023 Paul Holden \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Pending from 'core/pending';\nimport {debounce} from 'core/utils';\n\nconst Selectors = {\n capabilityOverviewForm: '#capability-overview-form',\n capabilitySelect: '[data-search=\"capability\"]',\n capabilitySearch: '[data-action=\"search\"]',\n};\n\nconst debounceTimer = 250;\n\n/**\n * Initialize module\n */\nexport const init = () => {\n const capabilityOverviewForm = document.querySelector(Selectors.capabilityOverviewForm);\n if (!capabilityOverviewForm) {\n return;\n }\n\n const capabilitySelect = capabilityOverviewForm.querySelector(Selectors.capabilitySelect);\n const capabilitySearch = capabilityOverviewForm.querySelector(Selectors.capabilitySearch);\n\n const capabilitySelectFilter = searchTerm => {\n const pendingPromise = new Pending('tool_capability/search:filter');\n\n // Remove existing options, remembering which were previously selected.\n let capabilitySelected = [];\n capabilitySelect.querySelectorAll('option').forEach(option => {\n if (option.selected) {\n capabilitySelected.push(option.value);\n }\n option.remove();\n });\n\n // Filter for matching capabilities.\n const availableCapabilities = JSON.parse(capabilitySelect.dataset.availableCapabilities);\n const filteredCapabilities = Object.keys(availableCapabilities).reduce((matches, capability) => {\n if (availableCapabilities[capability].toLowerCase().includes(searchTerm)) {\n matches[capability] = availableCapabilities[capability];\n }\n return matches;\n }, []);\n\n // Re-create filtered options.\n Object.entries(filteredCapabilities).forEach(([capability, capabilityText]) => {\n const option = document.createElement('option');\n option.value = capability;\n option.innerText = capabilityText;\n option.selected = capabilitySelected.indexOf(capability) > -1;\n capabilitySelect.append(option);\n });\n\n pendingPromise.resolve();\n };\n\n // Cache initial capability options.\n const availableCapabilities = {};\n capabilitySelect.querySelectorAll('option').forEach(option => {\n availableCapabilities[option.value] = option.text;\n });\n capabilitySelect.dataset.availableCapabilities = JSON.stringify(availableCapabilities);\n\n // Debounce the event listener on the search element to allow user to finish typing.\n const capabilitySearchDebounce = debounce(capabilitySelectFilter, debounceTimer);\n capabilitySearch.addEventListener('keyup', event => {\n const pendingPromise = new Pending('tool_capability/search:keyup');\n\n capabilitySearchDebounce(event.target.value.toLowerCase());\n setTimeout(() => {\n pendingPromise.resolve();\n }, debounceTimer);\n });\n\n // Ensure filter is applied on form load.\n if (capabilitySearch.value !== '') {\n capabilitySelectFilter(capabilitySearch.value.toLowerCase());\n }\n};\n"],"names":["obj","_pending","__esModule","default","Selectors","_exports","init","capabilityOverviewForm","document","querySelector","capabilitySelect","capabilitySearch","capabilitySelectFilter","searchTerm","pendingPromise","Pending","capabilitySelected","querySelectorAll","forEach","option","selected","push","value","remove","availableCapabilities","JSON","parse","dataset","filteredCapabilities","Object","keys","reduce","matches","capability","toLowerCase","includes","entries","_ref","capabilityText","createElement","innerText","indexOf","append","resolve","text","stringify","capabilitySearchDebounce","debounce","addEventListener","event","target","setTimeout"],"mappings":"4GAuBmC,IAAAA;;;;;;;kFAAnCC,UAAmCD,IAAnCC,WAAmCD,IAAAE,WAAAF,IAAAG,CAAAA,QAAAH,KAGnC,MAAMI,iCACsB,4BADtBA,2BAEgB,6BAFhBA,2BAGgB,yBAwEpBC,SAAAC,KAhEkBA,KAChB,MAAMC,uBAAyBC,SAASC,cAAcL,kCACtD,IAAKG,uBACD,OAGJ,MAAMG,iBAAmBH,uBAAuBE,cAAcL,4BACxDO,iBAAmBJ,uBAAuBE,cAAcL,4BAExDQ,uBAAyBC,aAC3B,MAAMC,eAAiB,IAAIC,SAAOZ,QAAC,iCAGnC,IAAIa,mBAAqB,GACzBN,iBAAiBO,iBAAiB,UAAUC,SAAQC,SAC5CA,OAAOC,UACPJ,mBAAmBK,KAAKF,OAAOG,OAEnCH,OAAOI,QAAQ,IAInB,MAAMC,sBAAwBC,KAAKC,MAAMhB,iBAAiBiB,QAAQH,uBAC5DI,qBAAuBC,OAAOC,KAAKN,uBAAuBO,QAAO,CAACC,QAASC,cACzET,sBAAsBS,YAAYC,cAAcC,SAAStB,cACzDmB,QAAQC,YAAcT,sBAAsBS,aAEzCD,UACR,IAGHH,OAAOO,QAAQR,sBAAsBV,SAAQmB,OAAkC,IAAhCJ,WAAYK,gBAAeD,KACtE,MAAMlB,OAASX,SAAS+B,cAAc,UACtCpB,OAAOG,MAAQW,WACfd,OAAOqB,UAAYF,eACnBnB,OAAOC,SAAWJ,mBAAmByB,QAAQR,aAAe,EAC5DvB,iBAAiBgC,OAAOvB,OAAO,IAGnCL,eAAe6B,SAAS,EAItBnB,sBAAwB,CAAA,EAC9Bd,iBAAiBO,iBAAiB,UAAUC,SAAQC,SAChDK,sBAAsBL,OAAOG,OAASH,OAAOyB,IAAI,IAErDlC,iBAAiBiB,QAAQH,sBAAwBC,KAAKoB,UAAUrB,uBAGhE,MAAMsB,0BAA2B,EAAAC,OAAAA,UAASnC,uBAvDxB,KAwDlBD,iBAAiBqC,iBAAiB,SAASC,QACvC,MAAMnC,eAAiB,IAAIC,SAAOZ,QAAC,gCAEnC2C,yBAAyBG,MAAMC,OAAO5B,MAAMY,eAC5CiB,YAAW,KACPrC,eAAe6B,SAAS,GA7Dd,IA8DG,IAIU,KAA3BhC,iBAAiBW,OACjBV,uBAAuBD,iBAAiBW,MAAMY,cAClD,CACF"} \ No newline at end of file diff --git a/admin/tool/capability/amd/src/search.js b/admin/tool/capability/amd/src/search.js new file mode 100644 index 0000000000000..fed89a27d6d65 --- /dev/null +++ b/admin/tool/capability/amd/src/search.js @@ -0,0 +1,102 @@ +// 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 . + +/** + * Add search filtering of capabilities + * + * @module tool_capability/search + * @copyright 2023 Paul Holden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +import Pending from 'core/pending'; +import {debounce} from 'core/utils'; + +const Selectors = { + capabilityOverviewForm: '#capability-overview-form', + capabilitySelect: '[data-search="capability"]', + capabilitySearch: '[data-action="search"]', +}; + +const debounceTimer = 250; + +/** + * Initialize module + */ +export const init = () => { + const capabilityOverviewForm = document.querySelector(Selectors.capabilityOverviewForm); + if (!capabilityOverviewForm) { + return; + } + + const capabilitySelect = capabilityOverviewForm.querySelector(Selectors.capabilitySelect); + const capabilitySearch = capabilityOverviewForm.querySelector(Selectors.capabilitySearch); + + const capabilitySelectFilter = searchTerm => { + const pendingPromise = new Pending('tool_capability/search:filter'); + + // Remove existing options, remembering which were previously selected. + let capabilitySelected = []; + capabilitySelect.querySelectorAll('option').forEach(option => { + if (option.selected) { + capabilitySelected.push(option.value); + } + option.remove(); + }); + + // Filter for matching capabilities. + const availableCapabilities = JSON.parse(capabilitySelect.dataset.availableCapabilities); + const filteredCapabilities = Object.keys(availableCapabilities).reduce((matches, capability) => { + if (availableCapabilities[capability].toLowerCase().includes(searchTerm)) { + matches[capability] = availableCapabilities[capability]; + } + return matches; + }, []); + + // Re-create filtered options. + Object.entries(filteredCapabilities).forEach(([capability, capabilityText]) => { + const option = document.createElement('option'); + option.value = capability; + option.innerText = capabilityText; + option.selected = capabilitySelected.indexOf(capability) > -1; + capabilitySelect.append(option); + }); + + pendingPromise.resolve(); + }; + + // Cache initial capability options. + const availableCapabilities = {}; + capabilitySelect.querySelectorAll('option').forEach(option => { + availableCapabilities[option.value] = option.text; + }); + capabilitySelect.dataset.availableCapabilities = JSON.stringify(availableCapabilities); + + // Debounce the event listener on the search element to allow user to finish typing. + const capabilitySearchDebounce = debounce(capabilitySelectFilter, debounceTimer); + capabilitySearch.addEventListener('keyup', event => { + const pendingPromise = new Pending('tool_capability/search:keyup'); + + capabilitySearchDebounce(event.target.value.toLowerCase()); + setTimeout(() => { + pendingPromise.resolve(); + }, debounceTimer); + }); + + // Ensure filter is applied on form load. + if (capabilitySearch.value !== '') { + capabilitySelectFilter(capabilitySearch.value.toLowerCase()); + } +}; diff --git a/admin/tool/capability/classes/settings_form.php b/admin/tool/capability/classes/settings_form.php index c0984d1e8a10f..e4c8bd3812b5d 100644 --- a/admin/tool/capability/classes/settings_form.php +++ b/admin/tool/capability/classes/settings_form.php @@ -43,19 +43,22 @@ public function definition() { $form = $this->_form; $capabilities = $this->_customdata['capabilities']; $roles = $this->_customdata['roles']; + // Set the form ID. $form->setAttributes(array('id' => 'capability-overview-form') + $form->getAttributes()); $form->addElement('header', 'reportsettings', get_string('reportsettings', 'tool_capability')); $form->addElement('html', html_writer::tag('p', get_string('intro', 'tool_capability'), array('id' => 'intro'))); - $form->addElement('hidden', 'search'); - $form->setType('search', PARAM_TEXT); - $attributes = array('multiple' => 'multiple', 'size' => 10, 'data-search' => 'capability'); $form->addElement('select', 'capability', get_string('capabilitylabel', 'tool_capability'), $capabilities, $attributes); $form->setType('capability', PARAM_CAPABILITY); + $strsearch = get_string('search'); + $form->addElement('text', 'search', $strsearch, ['data-action' => 'search', 'placeholder' => $strsearch]) + ->setHiddenLabel(true); + $form->setType('search', PARAM_TEXT); + $attributes = array('multiple' => 'multiple', 'size' => 10); $form->addElement('select', 'roles', get_string('roleslabel', 'tool_capability'), $roles, $attributes); $form->setType('roles', PARAM_TEXT); @@ -67,5 +70,4 @@ public function definition() { $form->addElement('submit', 'submitbutton', get_string('getreport', 'tool_capability')); } - } diff --git a/admin/tool/capability/index.php b/admin/tool/capability/index.php index 1f392fab5e41a..98238343e42f0 100644 --- a/admin/tool/capability/index.php +++ b/admin/tool/capability/index.php @@ -55,11 +55,8 @@ 'capabilities' => $capabilitychoices, 'roles' => $rolechoices )); -$PAGE->requires->yui_module( - 'moodle-tool_capability-search', - 'M.tool_capability.init_capability_search', - array(array('strsearch' => get_string('search'))) -); + +$PAGE->requires->js_call_amd('tool_capability/search', 'init'); // Log. $capabilities = array(); diff --git a/admin/tool/capability/styles.css b/admin/tool/capability/styles.css index fe2b5a7eeac9b..b25b9e0b217c2 100644 --- a/admin/tool/capability/styles.css +++ b/admin/tool/capability/styles.css @@ -1,3 +1,7 @@ +.path-admin-tool-capability [data-search="capability"] { + min-width: 675px; +} + .path-admin-tool-capability .comparisontable { margin-top: 150px; } diff --git a/admin/tool/capability/tests/behat/show_capabilies.feature b/admin/tool/capability/tests/behat/show_capabilies.feature index d0ec7c653fd34..04ad857682aa8 100644 --- a/admin/tool/capability/tests/behat/show_capabilies.feature +++ b/admin/tool/capability/tests/behat/show_capabilies.feature @@ -86,19 +86,18 @@ Feature: show capabilities for selected roles Scenario: filter capability list using javascript Given I should see "moodle/site:config" in the "Capability" "field" And I should see "moodle/course:change" in the "Capability" "field" - When I wait until the page is ready - And I set the field "capabilitysearch" to "moodle/course:change" + And I set the field "Search" in the "#capability-overview-form" "css_element" to "moodle/course:change" Then I should see "moodle/course:change" in the "Capability" "field" And I should not see "moodle/site:config" in the "Capability" "field" @javascript Scenario: selecting capabilities using filters Given I should see "moodle/course:change" in the "Capability" "field" - When I wait until the page is ready - And I set the field "capabilitysearch" to "moodle/course:change" + And I set the field "Search" in the "#capability-overview-form" "css_element" to "moodle/course:change" + And I wait "1" seconds When I set the following fields to these values: | Capability: | moodle/course:changecategory | | Roles: | Student | - And I set the field "capabilitysearch" to "" And I click on "Get the overview" "button" Then I should see "moodle/course:changecategory" in the "comparisontable" "table" + And the field "Capability:" matches value "moodle/course:changecategory" diff --git a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-debug.js b/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-debug.js deleted file mode 100644 index ed3d79cd36e6a..0000000000000 --- a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-debug.js +++ /dev/null @@ -1,182 +0,0 @@ -YUI.add('moodle-tool_capability-search', function (Y, NAME) { - -/** - * This file contains the capability overview search functionality. - * - * @module moodle-tool_capability-search - */ - -/** - * Constructs a new capability search manager. - * - * @namespace M.tool_capability - * @class Search - * @constructor - * @extends Base - */ -var SEARCH = function() { - SEARCH.superclass.constructor.apply(this, arguments); -}; -SEARCH.prototype = { - /** - * The search form. - * @property form - * @type Node - * @protected - */ - form: null, - /** - * The capability select node. - * @property select - * @type Node - * @protected - */ - select: null, - /** - * An associative array of search option. Populated from the select node above during initialisation. - * @property selectoptions - * @type Object - * @protected - */ - selectoptions: {}, - /** - * The search input field. - * @property input - * @type Node - * @protected - */ - input: null, - /** - * The submit button for the form. - * @property button - * @type Node - * @protected - */ - button: null, - /** - * The cancel button for the form. - * @property button - * @type Node - * @protected - */ - cancel: null, - /** - * The last search node if there is one. - * If there is a last search node then the last search term will be persisted between requests. - * @property lastsearch - * @type Node - * @protected - */ - lastsearch: null, - /** - * Constructs the search manager. - * @method initializer - */ - initializer: function() { - this.form = Y.one('#capability-overview-form'); - this.select = this.form.one('select[data-search=capability]'); - this.select.setStyle('minWidth', this.select.get('offsetWidth')); - this.select.get('options').each(function(option) { - var capability = option.get('value'); - this.selectoptions[capability] = option; - }, this); - this.button = this.form.all('input[type=submit]'); - this.lastsearch = this.form.one('input[name=search]'); - - var div = Y.Node.create('
'), - label = Y.Node.create(''); - this.cancel = Y.Node.create('' + - '' + - ''); - this.input = Y.Node.create(''); - - div.append(label).append(this.input).append(this.cancel); - - this.select.insert(div, 'before'); - - this.input.on('keyup', this.typed, this); - this.select.on('change', this.validate, this); - - this.cancel.on('click', function() { - this.input.set('value', ''); - this.typed(); - }, this); - - if (this.lastsearch) { - this.input.set('value', this.lastsearch.get('value')); - this.typed(); - if (this.select.one('option[selected]')) { - this.select.set('scrollTop', this.select.one('option[selected]').get('getX')); - } - } - - this.validate(); - }, - /** - * Disables the submit button if there are no capabilities selected. - * @method validate - */ - validate: function() { - this.button.set('disabled', (this.select.get('value') === '')); - }, - /** - * Called when ever the user types into the search field. - * This method hides any capabilities that don't match the search term. - * @method typed - */ - typed: function() { - var search = this.input.get('value'), - matching = 0, - last = null, - capability; - if (this.lastsearch) { - this.lastsearch.set('value', search); - } - this.select.all('option').remove(); - for (capability in this.selectoptions) { - if (capability.indexOf(search) >= 0) { - matching++; - last = this.selectoptions[capability]; - this.select.append(this.selectoptions[capability]); - } - } - if (matching === 0) { - this.input.addClass("error"); - } else { - this.input.removeClass("error"); - if (matching === 1) { - last.set('selected', true); - } - } - if (search !== '') { - this.cancel.removeClass("d-none"); - } else { - this.cancel.addClass("d-none"); - } - this.validate(); - } -}; -Y.extend(SEARCH, Y.Base, SEARCH.prototype, { - NAME: 'tool_capability-search', - ATTRS: { - strsearch: {} - } -}); - -M.tool_capability = M.tool_capability || {}; - -/** - * Initialises capability search functionality. - * @static - * @method M.tool_capability.init_capability_search - * @param {Object} options - */ -M.tool_capability.init_capability_search = function(options) { - new SEARCH(options); -}; - - -}, '@VERSION@', {"requires": ["base", "node"]}); diff --git a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-min.js b/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-min.js deleted file mode 100644 index b90e165c5b803..0000000000000 --- a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search-min.js +++ /dev/null @@ -1 +0,0 @@ -YUI.add("moodle-tool_capability-search",function(s,t){var e=function(){e.superclass.constructor.apply(this,arguments)};s.extend(e,s.Base,e.prototype={form:null,select:null,selectoptions:{},input:null,button:null,cancel:null,lastsearch:null,initializer:function(){this.form=s.one("#capability-overview-form"),this.select=this.form.one("select[data-search=capability]"),this.select.setStyle("minWidth",this.select.get("offsetWidth")),this.select.get("options").each(function(t){var e=t.get("value");this.selectoptions[e]=t},this),this.button=this.form.all("input[type=submit]"),this.lastsearch=this.form.one("input[name=search]");var t=s.Node.create('
'),e=s.Node.create('");this.cancel=s.Node.create(''),this.input=s.Node.create(''),t.append(e).append(this.input).append(this.cancel),this.select.insert(t,"before"),this.input.on("keyup",this.typed,this),this.select.on("change",this.validate,this),this.cancel.on("click",function(){this.input.set("value",""),this.typed()},this),this.lastsearch&&(this.input.set("value",this.lastsearch.get("value")),this.typed(),this.select.one("option[selected]"))&&this.select.set("scrollTop",this.select.one("option[selected]").get("getX")),this.validate()},validate:function(){this.button.set("disabled",""===this.select.get("value"))},typed:function(){var t,e=this.input.get("value"),s=0,i=null;for(t in this.lastsearch&&this.lastsearch.set("value",e),this.select.all("option").remove(),this.selectoptions)0<=t.indexOf(e)&&(s++,i=this.selectoptions[t],this.select.append(this.selectoptions[t]));0===s?this.input.addClass("error"):(this.input.removeClass("error"),1===s&&i.set("selected",!0)),""!==e?this.cancel.removeClass("d-none"):this.cancel.addClass("d-none"),this.validate()}},{NAME:"tool_capability-search",ATTRS:{strsearch:{}}}),M.tool_capability=M.tool_capability||{},M.tool_capability.init_capability_search=function(t){new e(t)}},"@VERSION@",{requires:["base","node"]}); \ No newline at end of file diff --git a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search.js b/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search.js deleted file mode 100644 index ed3d79cd36e6a..0000000000000 --- a/admin/tool/capability/yui/build/moodle-tool_capability-search/moodle-tool_capability-search.js +++ /dev/null @@ -1,182 +0,0 @@ -YUI.add('moodle-tool_capability-search', function (Y, NAME) { - -/** - * This file contains the capability overview search functionality. - * - * @module moodle-tool_capability-search - */ - -/** - * Constructs a new capability search manager. - * - * @namespace M.tool_capability - * @class Search - * @constructor - * @extends Base - */ -var SEARCH = function() { - SEARCH.superclass.constructor.apply(this, arguments); -}; -SEARCH.prototype = { - /** - * The search form. - * @property form - * @type Node - * @protected - */ - form: null, - /** - * The capability select node. - * @property select - * @type Node - * @protected - */ - select: null, - /** - * An associative array of search option. Populated from the select node above during initialisation. - * @property selectoptions - * @type Object - * @protected - */ - selectoptions: {}, - /** - * The search input field. - * @property input - * @type Node - * @protected - */ - input: null, - /** - * The submit button for the form. - * @property button - * @type Node - * @protected - */ - button: null, - /** - * The cancel button for the form. - * @property button - * @type Node - * @protected - */ - cancel: null, - /** - * The last search node if there is one. - * If there is a last search node then the last search term will be persisted between requests. - * @property lastsearch - * @type Node - * @protected - */ - lastsearch: null, - /** - * Constructs the search manager. - * @method initializer - */ - initializer: function() { - this.form = Y.one('#capability-overview-form'); - this.select = this.form.one('select[data-search=capability]'); - this.select.setStyle('minWidth', this.select.get('offsetWidth')); - this.select.get('options').each(function(option) { - var capability = option.get('value'); - this.selectoptions[capability] = option; - }, this); - this.button = this.form.all('input[type=submit]'); - this.lastsearch = this.form.one('input[name=search]'); - - var div = Y.Node.create('
'), - label = Y.Node.create(''); - this.cancel = Y.Node.create('' + - '' + - ''); - this.input = Y.Node.create(''); - - div.append(label).append(this.input).append(this.cancel); - - this.select.insert(div, 'before'); - - this.input.on('keyup', this.typed, this); - this.select.on('change', this.validate, this); - - this.cancel.on('click', function() { - this.input.set('value', ''); - this.typed(); - }, this); - - if (this.lastsearch) { - this.input.set('value', this.lastsearch.get('value')); - this.typed(); - if (this.select.one('option[selected]')) { - this.select.set('scrollTop', this.select.one('option[selected]').get('getX')); - } - } - - this.validate(); - }, - /** - * Disables the submit button if there are no capabilities selected. - * @method validate - */ - validate: function() { - this.button.set('disabled', (this.select.get('value') === '')); - }, - /** - * Called when ever the user types into the search field. - * This method hides any capabilities that don't match the search term. - * @method typed - */ - typed: function() { - var search = this.input.get('value'), - matching = 0, - last = null, - capability; - if (this.lastsearch) { - this.lastsearch.set('value', search); - } - this.select.all('option').remove(); - for (capability in this.selectoptions) { - if (capability.indexOf(search) >= 0) { - matching++; - last = this.selectoptions[capability]; - this.select.append(this.selectoptions[capability]); - } - } - if (matching === 0) { - this.input.addClass("error"); - } else { - this.input.removeClass("error"); - if (matching === 1) { - last.set('selected', true); - } - } - if (search !== '') { - this.cancel.removeClass("d-none"); - } else { - this.cancel.addClass("d-none"); - } - this.validate(); - } -}; -Y.extend(SEARCH, Y.Base, SEARCH.prototype, { - NAME: 'tool_capability-search', - ATTRS: { - strsearch: {} - } -}); - -M.tool_capability = M.tool_capability || {}; - -/** - * Initialises capability search functionality. - * @static - * @method M.tool_capability.init_capability_search - * @param {Object} options - */ -M.tool_capability.init_capability_search = function(options) { - new SEARCH(options); -}; - - -}, '@VERSION@', {"requires": ["base", "node"]}); diff --git a/admin/tool/capability/yui/src/search/build.json b/admin/tool/capability/yui/src/search/build.json deleted file mode 100644 index 215788915654e..0000000000000 --- a/admin/tool/capability/yui/src/search/build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "moodle-tool_capability-search", - "builds": { - "moodle-tool_capability-search": { - "jsfiles": [ - "search.js" - ] - } - } -} diff --git a/admin/tool/capability/yui/src/search/js/search.js b/admin/tool/capability/yui/src/search/js/search.js deleted file mode 100644 index 71bd15257665b..0000000000000 --- a/admin/tool/capability/yui/src/search/js/search.js +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This file contains the capability overview search functionality. - * - * @module moodle-tool_capability-search - */ - -/** - * Constructs a new capability search manager. - * - * @namespace M.tool_capability - * @class Search - * @constructor - * @extends Base - */ -var SEARCH = function() { - SEARCH.superclass.constructor.apply(this, arguments); -}; -SEARCH.prototype = { - /** - * The search form. - * @property form - * @type Node - * @protected - */ - form: null, - /** - * The capability select node. - * @property select - * @type Node - * @protected - */ - select: null, - /** - * An associative array of search option. Populated from the select node above during initialisation. - * @property selectoptions - * @type Object - * @protected - */ - selectoptions: {}, - /** - * The search input field. - * @property input - * @type Node - * @protected - */ - input: null, - /** - * The submit button for the form. - * @property button - * @type Node - * @protected - */ - button: null, - /** - * The cancel button for the form. - * @property button - * @type Node - * @protected - */ - cancel: null, - /** - * The last search node if there is one. - * If there is a last search node then the last search term will be persisted between requests. - * @property lastsearch - * @type Node - * @protected - */ - lastsearch: null, - /** - * Constructs the search manager. - * @method initializer - */ - initializer: function() { - this.form = Y.one('#capability-overview-form'); - this.select = this.form.one('select[data-search=capability]'); - this.select.setStyle('minWidth', this.select.get('offsetWidth')); - this.select.get('options').each(function(option) { - var capability = option.get('value'); - this.selectoptions[capability] = option; - }, this); - this.button = this.form.all('input[type=submit]'); - this.lastsearch = this.form.one('input[name=search]'); - - var div = Y.Node.create('
'), - label = Y.Node.create(''); - this.cancel = Y.Node.create('' + - '' + - ''); - this.input = Y.Node.create(''); - - div.append(label).append(this.input).append(this.cancel); - - this.select.insert(div, 'before'); - - this.input.on('keyup', this.typed, this); - this.select.on('change', this.validate, this); - - this.cancel.on('click', function() { - this.input.set('value', ''); - this.typed(); - }, this); - - if (this.lastsearch) { - this.input.set('value', this.lastsearch.get('value')); - this.typed(); - if (this.select.one('option[selected]')) { - this.select.set('scrollTop', this.select.one('option[selected]').get('getX')); - } - } - - this.validate(); - }, - /** - * Disables the submit button if there are no capabilities selected. - * @method validate - */ - validate: function() { - this.button.set('disabled', (this.select.get('value') === '')); - }, - /** - * Called when ever the user types into the search field. - * This method hides any capabilities that don't match the search term. - * @method typed - */ - typed: function() { - var search = this.input.get('value'), - matching = 0, - last = null, - capability; - if (this.lastsearch) { - this.lastsearch.set('value', search); - } - this.select.all('option').remove(); - for (capability in this.selectoptions) { - if (capability.indexOf(search) >= 0) { - matching++; - last = this.selectoptions[capability]; - this.select.append(this.selectoptions[capability]); - } - } - if (matching === 0) { - this.input.addClass("error"); - } else { - this.input.removeClass("error"); - if (matching === 1) { - last.set('selected', true); - } - } - if (search !== '') { - this.cancel.removeClass("d-none"); - } else { - this.cancel.addClass("d-none"); - } - this.validate(); - } -}; -Y.extend(SEARCH, Y.Base, SEARCH.prototype, { - NAME: 'tool_capability-search', - ATTRS: { - strsearch: {} - } -}); - -M.tool_capability = M.tool_capability || {}; - -/** - * Initialises capability search functionality. - * @static - * @method M.tool_capability.init_capability_search - * @param {Object} options - */ -M.tool_capability.init_capability_search = function(options) { - new SEARCH(options); -}; diff --git a/admin/tool/capability/yui/src/search/meta/search.json b/admin/tool/capability/yui/src/search/meta/search.json deleted file mode 100644 index 720e20bf310ec..0000000000000 --- a/admin/tool/capability/yui/src/search/meta/search.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "moodle-tool_capability-search": { - "requires": [ - "base", - "node" - ] - } -} diff --git a/theme/boost/scss/moodle/admin.scss b/theme/boost/scss/moodle/admin.scss index 30f2dc5d23d42..828d4527945b9 100644 --- a/theme/boost/scss/moodle/admin.scss +++ b/theme/boost/scss/moodle/admin.scss @@ -58,10 +58,6 @@ display: none; } -#page-admin-report-capability-index #capabilitysearch { - width: 30em; -} - #page-admin-qtypes #qtypes div, #page-admin-qtypes #qtypes form, #page-admin-qbehaviours #qbehaviours div, diff --git a/theme/boost/style/moodle.css b/theme/boost/style/moodle.css index 92355dbd84dea..4961729b7ce43 100644 --- a/theme/boost/style/moodle.css +++ b/theme/boost/style/moodle.css @@ -12635,9 +12635,6 @@ blockquote { .timewarninghidden { display: none; } -#page-admin-report-capability-index #capabilitysearch { - width: 30em; } - #page-admin-qtypes #qtypes div, #page-admin-qtypes #qtypes form, #page-admin-qbehaviours #qbehaviours div, diff --git a/theme/classic/style/moodle.css b/theme/classic/style/moodle.css index cd4873bcebd91..9b1d1a5258b53 100644 --- a/theme/classic/style/moodle.css +++ b/theme/classic/style/moodle.css @@ -12635,9 +12635,6 @@ blockquote { .timewarninghidden { display: none; } -#page-admin-report-capability-index #capabilitysearch { - width: 30em; } - #page-admin-qtypes #qtypes div, #page-admin-qtypes #qtypes form, #page-admin-qbehaviours #qbehaviours div,