MDL-69454 core_search: consistent admin search

This commit is contained in:
Bas Brands 2020-08-31 09:06:08 +00:00
parent 1a2a52d121
commit ebfee99d90
7 changed files with 77 additions and 177 deletions

View File

@ -1,48 +0,0 @@
<?php
// 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 <http://www.gnu.org/licenses/>.
/**
* 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));
}
}

View File

@ -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 '<hr>';
if ($query) {
echo admin_search_settings_html($query);

View File

@ -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

View File

@ -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

File diff suppressed because one or more lines are too long

View File

@ -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 <http://www.gnu.org/licenses/>.
/**
* 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);
}
};
});

View File

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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"
}
]
}
}}
<div class="simplesearchform {{{ extraclasses }}}">
<form autocomplete="off" action="{{{ action }}}" method="get" accept-charset="utf-8" class="mform form-inline simplesearchform">
{{#hiddenfields}}
<input type="hidden" name="{{ name }}" value="{{ value }}">
{{/hiddenfields}}
<div class="input-group">
<label for="searchinput-{{uniqid}}">
<span class="sr-only">{{{ searchstring }}}</span>
</label>
<input type="text"
id="searchinput-{{uniqid}}"
class="form-control"
placeholder="{{{ searchstring }}}"
aria-label="{{{ searchstring }}}"
name="{{{ inputname }}}"
data-region="input"
autocomplete="off"
value="{{{ query }}}"
>
<div class="input-group-append">
<button type="submit" class="btn {{^btnclass}}btn-submit{{/btnclass}} {{{ btnclass }}} search-icon">
{{#pix}} a/search, core {{/pix}}
<span class="sr-only">{{{ searchstring }}}</span>
</button>
</div>
</div>
</form>
</div>