From a5cd815635c64ebd4b0bc46e88b26a76e4cad745 Mon Sep 17 00:00:00 2001 From: Bas Brands Date: Mon, 31 Aug 2020 09:06:08 +0000 Subject: [PATCH] MDL-69454 core_search: consistent admin search --- admin/admin_settings_search_form.php | 48 ------------- admin/search.php | 13 +++- admin/tests/behat/behat_admin.php | 2 +- lib/amd/build/search-input.min.js | 2 - lib/amd/build/search-input.min.js.map | 1 - lib/amd/src/search-input.js | 122 ---------------------------------- lib/templates/search_input.mustache | 66 ++++++++++++++++++ 7 files changed, 77 insertions(+), 177 deletions(-) delete mode 100644 admin/admin_settings_search_form.php delete mode 100644 lib/amd/build/search-input.min.js delete mode 100644 lib/amd/build/search-input.min.js.map delete mode 100644 lib/amd/src/search-input.js create mode 100644 lib/templates/search_input.mustache diff --git a/admin/admin_settings_search_form.php b/admin/admin_settings_search_form.php deleted file mode 100644 index ad42300b853..00000000000 --- a/admin/admin_settings_search_form.php +++ /dev/null @@ -1,48 +0,0 @@ -. - -/** - * Admin settings search form - * - * @package admin - * @copyright 2016 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -require_once $CFG->libdir.'/formslib.php'; - -/** - * Admin settings search form - * - * @package admin - * @copyright 2016 Damyon Wiese - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class admin_settings_search_form extends moodleform { - function definition () { - $mform = $this->_form; - - //$mform->addElement('header', 'settingsheader', get_string('search', 'admin')); - $elements = []; - $elements[] = $mform->createElement('text', 'query', get_string('query', 'admin')); - $elements[] = $mform->createElement('submit', 'search', get_string('search')); - $mform->addGroup($elements); - $mform->setType('query', PARAM_RAW); - $mform->setDefault('query', optional_param('query', '', PARAM_RAW)); - } -} diff --git a/admin/search.php b/admin/search.php index 55395171b53..98ec900ed44 100644 --- a/admin/search.php +++ b/admin/search.php @@ -68,9 +68,16 @@ if ($errormsg !== '') { $showsettingslinks = true; if ($hassiteconfig) { - require_once("admin_settings_search_form.php"); - $form = new admin_settings_search_form(); - $form->display(); + $data = [ + 'action' => new moodle_url('/admin/search.php'), + 'btnclass' => 'btn-primary', + 'inputname' => 'query', + 'searchstring' => get_string('search'), + 'query' => $query, + 'extraclasses' => 'd-flex justify-content-center' + ]; + echo $OUTPUT->render_from_template('core/search_input', $data); + echo '
'; if ($query) { echo admin_search_settings_html($query); diff --git a/admin/tests/behat/behat_admin.php b/admin/tests/behat/behat_admin.php index af027dec4c8..98f5d91de10 100644 --- a/admin/tests/behat/behat_admin.php +++ b/admin/tests/behat/behat_admin.php @@ -56,7 +56,7 @@ class behat_admin extends behat_base { $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', [get_string('administrationsite')]); // Search by label. - $this->execute('behat_forms::i_set_the_field_to', [get_string('query', 'admin'), $label]); + $this->execute('behat_forms::i_set_the_field_to', [get_string('search'), $label]); $this->execute("behat_forms::press_button", get_string('search', 'admin')); // Admin settings does not use the same DOM structure than other moodle forms diff --git a/lib/amd/build/search-input.min.js b/lib/amd/build/search-input.min.js deleted file mode 100644 index 5e2f8db12b9..00000000000 --- a/lib/amd/build/search-input.min.js +++ /dev/null @@ -1,2 +0,0 @@ -define ("core/search-input",["jquery"],function(a){var b=null,c=function(a){if(b.hasClass("expanded")){e()}else{d(a)}},d=function(c){var d=a(document).width();if("keydown"===c.type&&13!==c.keyCode&&32!==c.keyCode){return}if(767>=d&&("click"===c.type||"keydown"===c.type)){f();return}else if(767>=d){return}if("keydown"===c.type){c.preventDefault()}b.addClass("expanded");b.find("form").addClass("expanded");b.find("input").focus()},e=function(){b.removeClass("expanded");b.find("form").removeClass("expanded")},f=function(){b.find("form").submit()};return{init:function init(d){b=a("#"+d);b.on("click mouseover keydown","div",c)}}}); -//# sourceMappingURL=search-input.min.js.map diff --git a/lib/amd/build/search-input.min.js.map b/lib/amd/build/search-input.min.js.map deleted file mode 100644 index f6a55ed1d8e..00000000000 --- a/lib/amd/build/search-input.min.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/search-input.js"],"names":["define","$","wrapper","toggleForm","ev","hasClass","hideForm","showForm","windowWidth","document","width","type","keyCode","submitForm","preventDefault","addClass","find","focus","removeClass","submit","init","id","on"],"mappings":"AAyBAA,OAAM,qBAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,IAOvBC,CAAAA,CAAO,CAAG,IAPa,CAgBvBC,CAAU,CAAG,SAASC,CAAT,CAAa,CAE1B,GAAIF,CAAO,CAACG,QAAR,CAAiB,UAAjB,CAAJ,CAAkC,CAC9BC,CAAQ,EACX,CAFD,IAEO,CACHC,CAAQ,CAACH,CAAD,CACX,CACJ,CAvB0B,CAgCvBG,CAAQ,CAAG,SAASH,CAAT,CAAa,CAExB,GAAII,CAAAA,CAAW,CAAGP,CAAC,CAACQ,QAAD,CAAD,CAAYC,KAAZ,EAAlB,CAGA,GAAgB,SAAZ,GAAAN,CAAE,CAACO,IAAH,EAAwC,EAAf,GAAAP,CAAE,CAACQ,OAA5B,EAA6D,EAAf,GAAAR,CAAE,CAACQ,OAArD,CAAqE,CACjE,MACH,CAED,GAAmB,GAAf,EAAAJ,CAAW,GAAwB,OAAZ,GAAAJ,CAAE,CAACO,IAAH,EAAmC,SAAZ,GAAAP,CAAE,CAACO,IAAtC,CAAf,CAA0E,CAEtEE,CAAU,GACV,MACH,CAJD,IAIO,IAAmB,GAAf,EAAAL,CAAJ,CAAwB,CAE3B,MACH,CAED,GAAgB,SAAZ,GAAAJ,CAAE,CAACO,IAAP,CAA2B,CAEvBP,CAAE,CAACU,cAAH,EACH,CAEDZ,CAAO,CAACa,QAAR,CAAiB,UAAjB,EACAb,CAAO,CAACc,IAAR,CAAa,MAAb,EAAqBD,QAArB,CAA8B,UAA9B,EACAb,CAAO,CAACc,IAAR,CAAa,OAAb,EAAsBC,KAAtB,EACH,CA1D0B,CAkEvBX,CAAQ,CAAG,UAAW,CACtBJ,CAAO,CAACgB,WAAR,CAAoB,UAApB,EACAhB,CAAO,CAACc,IAAR,CAAa,MAAb,EAAqBE,WAArB,CAAiC,UAAjC,CACH,CArE0B,CA8EvBL,CAAU,CAAG,UAAW,CACxBX,CAAO,CAACc,IAAR,CAAa,MAAb,EAAqBG,MAArB,EACH,CAhF0B,CAkF3B,MAA8C,CAS1CC,IAAI,CAAE,cAASC,CAAT,CAAa,CACfnB,CAAO,CAAGD,CAAC,CAAC,IAAMoB,CAAP,CAAX,CACAnB,CAAO,CAACoB,EAAR,CAAW,yBAAX,CAAsC,KAAtC,CAA6CnB,CAA7C,CACH,CAZyC,CAcjD,CAhGK,CAAN","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 * Search box.\n *\n * @module core/search-input\n * @class search-input\n * @package core\n * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since Moodle 3.1\n */\ndefine(['jquery'], function($) {\n\n /**\n * This search box div node.\n *\n * @private\n */\n var wrapper = null;\n\n /**\n * Toggles the form visibility.\n *\n * @param {Event} ev\n * @method toggleForm\n * @private\n */\n var toggleForm = function(ev) {\n\n if (wrapper.hasClass('expanded')) {\n hideForm();\n } else {\n showForm(ev);\n }\n };\n\n /**\n * Shows the form or submits it depending on the window size.\n *\n * @param {Event} ev\n * @method showForm\n * @private\n */\n var showForm = function(ev) {\n\n var windowWidth = $(document).width();\n\n // We are only interested in enter and space keys (accessibility).\n if (ev.type === 'keydown' && ev.keyCode !== 13 && ev.keyCode !== 32) {\n return;\n }\n\n if (windowWidth <= 767 && (ev.type === 'click' || ev.type === 'keydown')) {\n // Move to the search page when using small window sizes as the input requires too much space.\n submitForm();\n return;\n } else if (windowWidth <= 767) {\n // Ignore mousedown events in while using small window sizes.\n return;\n }\n\n if (ev.type === 'keydown') {\n // We don't want to submit the form unless the user hits enter.\n ev.preventDefault();\n }\n\n wrapper.addClass('expanded');\n wrapper.find('form').addClass('expanded');\n wrapper.find('input').focus();\n };\n\n /**\n * Hides the form.\n *\n * @method hideForm\n * @private\n */\n var hideForm = function() {\n wrapper.removeClass('expanded');\n wrapper.find('form').removeClass('expanded');\n };\n\n /**\n * Submits the form.\n *\n * @param {Event} ev\n * @method submitForm\n * @private\n */\n var submitForm = function() {\n wrapper.find('form').submit();\n };\n\n return /** @alias module:core/search-input */ {\n // Public variables and functions.\n\n /**\n * Assigns listeners to the requested select box.\n *\n * @method init\n * @param {Number} id The search wrapper div id\n */\n init: function(id) {\n wrapper = $('#' + id);\n wrapper.on('click mouseover keydown', 'div', toggleForm);\n }\n };\n});\n"],"file":"search-input.min.js"} \ No newline at end of file diff --git a/lib/amd/src/search-input.js b/lib/amd/src/search-input.js deleted file mode 100644 index 85f9bb14946..00000000000 --- a/lib/amd/src/search-input.js +++ /dev/null @@ -1,122 +0,0 @@ -// 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 . - -/** - * Search box. - * - * @module core/search-input - * @class search-input - * @package core - * @copyright 2016 David Monllao {@link http://www.davidmonllao.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @since Moodle 3.1 - */ -define(['jquery'], function($) { - - /** - * This search box div node. - * - * @private - */ - var wrapper = null; - - /** - * Toggles the form visibility. - * - * @param {Event} ev - * @method toggleForm - * @private - */ - var toggleForm = function(ev) { - - if (wrapper.hasClass('expanded')) { - hideForm(); - } else { - showForm(ev); - } - }; - - /** - * Shows the form or submits it depending on the window size. - * - * @param {Event} ev - * @method showForm - * @private - */ - var showForm = function(ev) { - - var windowWidth = $(document).width(); - - // We are only interested in enter and space keys (accessibility). - if (ev.type === 'keydown' && ev.keyCode !== 13 && ev.keyCode !== 32) { - return; - } - - if (windowWidth <= 767 && (ev.type === 'click' || ev.type === 'keydown')) { - // Move to the search page when using small window sizes as the input requires too much space. - submitForm(); - return; - } else if (windowWidth <= 767) { - // Ignore mousedown events in while using small window sizes. - return; - } - - if (ev.type === 'keydown') { - // We don't want to submit the form unless the user hits enter. - ev.preventDefault(); - } - - wrapper.addClass('expanded'); - wrapper.find('form').addClass('expanded'); - wrapper.find('input').focus(); - }; - - /** - * Hides the form. - * - * @method hideForm - * @private - */ - var hideForm = function() { - wrapper.removeClass('expanded'); - wrapper.find('form').removeClass('expanded'); - }; - - /** - * Submits the form. - * - * @param {Event} ev - * @method submitForm - * @private - */ - var submitForm = function() { - wrapper.find('form').submit(); - }; - - return /** @alias module:core/search-input */ { - // Public variables and functions. - - /** - * Assigns listeners to the requested select box. - * - * @method init - * @param {Number} id The search wrapper div id - */ - init: function(id) { - wrapper = $('#' + id); - wrapper.on('click mouseover keydown', 'div', toggleForm); - } - }; -}); diff --git a/lib/templates/search_input.mustache b/lib/templates/search_input.mustache new file mode 100644 index 00000000000..48c20f7b65d --- /dev/null +++ b/lib/templates/search_input.mustache @@ -0,0 +1,66 @@ +{{! + 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/search_input + + Simple search input. + + Example context (json): + { + "action": "https://moodle.local/admin/search.php", + "extraclasses": "my-2", + "inputname": "search", + "searchstring": "Search settings", + "value": "policy", + "btnclass": "primary", + "query": "themedesigner", + "hiddenfields": [ + { + "name": "context", + "value": "11" + } + ] + } +}} +
+
+ {{#hiddenfields}} + + {{/hiddenfields}} +
+ + +
+ +
+
+
+
\ No newline at end of file -- 2.11.4.GIT