mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-55805 admin: Convert admin search results to use a template
Part of MDL-55071
This commit is contained in:
parent
d5732f7f40
commit
4121391d34
admin
lib
theme/noname/templates/core_admin
@ -43,24 +43,6 @@ if ($errormsg !== '') {
|
||||
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
|
||||
}
|
||||
|
||||
$resultshtml = admin_search_settings_html($query); // case insensitive search only
|
||||
|
||||
echo '<form action="' . $PAGE->url->out(true) . '" method="post" id="adminsettings">';
|
||||
echo '<div>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
// HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
|
||||
echo prevent_form_autofill_password();
|
||||
echo '</div>';
|
||||
echo '<fieldset>';
|
||||
echo '<div class="clearer"><!-- --></div>';
|
||||
if ($resultshtml != '') {
|
||||
echo $resultshtml;
|
||||
} else {
|
||||
echo get_string('noresults','admin');
|
||||
}
|
||||
echo '</fieldset>';
|
||||
echo '</form>';
|
||||
echo admin_search_settings_html($query);
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
|
||||
|
47
admin/templates/settings_search_results.mustache
Normal file
47
admin/templates/settings_search_results.mustache
Normal file
@ -0,0 +1,47 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
Settings.
|
||||
}}
|
||||
<form action="{{actionurl}}" method="post" id="adminsettings">
|
||||
<div>
|
||||
<input type="hidden" name="sesskey" value="{{sesskey}}">
|
||||
{{>core/prevent_form_autofill_password}}
|
||||
</div>
|
||||
<fieldset>
|
||||
<div class="clearer"></div>
|
||||
{{#hasresults}}
|
||||
{{#results}}
|
||||
<h2 class="main">{{#str}}searchresults, admin{{/str}} - <a href="{{url}}">{{{title}}}</a></h2>
|
||||
<fieldset class="adminsettings">
|
||||
{{#settings}}
|
||||
<div class="clearer"></div>
|
||||
{{{.}}}
|
||||
{{/settings}}
|
||||
</fieldset>
|
||||
{{/results}}
|
||||
{{#showsave}}
|
||||
<div class="form-buttons">
|
||||
<input type="submit" class="form-submit" value={{#quote}}{{#str}}savechanges, admin{{/str}}{{/quote}}>
|
||||
</div>
|
||||
{{/showsave}}
|
||||
{{/hasresults}}
|
||||
{{^hasresults}}
|
||||
{{#str}}noresults, admin{{/str}}
|
||||
{{/hasresults}}
|
||||
</fieldset>
|
||||
</form>
|
@ -7498,7 +7498,7 @@ function admin_find_write_settings($node, $data) {
|
||||
* @return string empty or XHTML
|
||||
*/
|
||||
function admin_search_settings_html($query) {
|
||||
global $CFG, $OUTPUT;
|
||||
global $CFG, $OUTPUT, $PAGE;
|
||||
|
||||
if (core_text::strlen($query) < 2) {
|
||||
return '';
|
||||
@ -7507,9 +7507,14 @@ function admin_search_settings_html($query) {
|
||||
|
||||
$adminroot = admin_get_root();
|
||||
$findings = $adminroot->search($query);
|
||||
$return = '';
|
||||
$savebutton = false;
|
||||
|
||||
$tpldata = (object) [
|
||||
'actionurl' => $PAGE->url->out(false),
|
||||
'results' => [],
|
||||
'sesskey' => sesskey(),
|
||||
];
|
||||
|
||||
foreach ($findings as $found) {
|
||||
$page = $found->page;
|
||||
$settings = $found->settings;
|
||||
@ -7517,20 +7522,23 @@ function admin_search_settings_html($query) {
|
||||
// hidden pages are not displayed in search results
|
||||
continue;
|
||||
}
|
||||
|
||||
$heading = highlight($query, $page->visiblename);
|
||||
$headingurl = null;
|
||||
if ($page instanceof admin_externalpage) {
|
||||
$return .= $OUTPUT->heading(get_string('searchresults','admin').' - <a href="'.$page->url.'">'.highlight($query, $page->visiblename).'</a>', 2, 'main');
|
||||
$headingurl = new moodle_url($page->url);
|
||||
} else if ($page instanceof admin_settingpage) {
|
||||
$return .= $OUTPUT->heading(get_string('searchresults','admin').' - <a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section='.$page->name.'">'.highlight($query, $page->visiblename).'</a>', 2, 'main');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
$headingurl = new moodle_url('/admin/settings.php', ['section' => $page->name]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sectionsettings = [];
|
||||
if (!empty($settings)) {
|
||||
$return .= '<fieldset class="adminsettings">'."\n";
|
||||
foreach ($settings as $setting) {
|
||||
if (empty($setting->nosave)) {
|
||||
$savebutton = true;
|
||||
}
|
||||
$return .= '<div class="clearer"><!-- --></div>'."\n";
|
||||
$fullname = $setting->get_full_name();
|
||||
if (array_key_exists($fullname, $adminroot->errors)) {
|
||||
$data = $adminroot->errors[$fullname]->data;
|
||||
@ -7538,17 +7546,21 @@ function admin_search_settings_html($query) {
|
||||
$data = $setting->get_setting();
|
||||
// do not use defaults if settings not available - upgradesettings handles the defaults!
|
||||
}
|
||||
$return .= $setting->output_html($data, $query);
|
||||
$sectionsettings[] = $setting->output_html($data, $query);
|
||||
}
|
||||
$return .= '</fieldset>';
|
||||
}
|
||||
|
||||
$tpldata->results[] = (object) [
|
||||
'title' => $heading,
|
||||
'url' => $headingurl->out(false),
|
||||
'settings' => $sectionsettings
|
||||
];
|
||||
}
|
||||
|
||||
if ($savebutton) {
|
||||
$return .= '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
|
||||
}
|
||||
$tpldata->showsave = $savebutton;
|
||||
$tpldata->hasresults = !empty($tpldata->results);
|
||||
|
||||
return $return;
|
||||
return $OUTPUT->render_from_template('core_admin/settings_search_results', $tpldata);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,49 @@
|
||||
{{!
|
||||
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/>.
|
||||
}}
|
||||
{{!
|
||||
Settings.
|
||||
}}
|
||||
<form action="{{actionurl}}" method="post" id="adminsettings">
|
||||
<div>
|
||||
<input type="hidden" name="sesskey" value="{{sesskey}}">
|
||||
{{>core/prevent_form_autofill_password}}
|
||||
</div>
|
||||
<fieldset>
|
||||
<div class="clearer"></div>
|
||||
{{#hasresults}}
|
||||
{{#results}}
|
||||
<h2 class="main">{{#str}}searchresults, admin{{/str}} - <a href="{{url}}">{{{title}}}</a></h2>
|
||||
<fieldset class="adminsettings">
|
||||
{{#settings}}
|
||||
<div class="clearer"></div>
|
||||
{{{.}}}
|
||||
{{/settings}}
|
||||
</fieldset>
|
||||
{{/results}}
|
||||
{{#showsave}}
|
||||
<div class="row">
|
||||
<div class="offset-sm-3 col-sm-3">
|
||||
<button type="submit" class="btn btn-primary">{{#str}}savechanges, admin{{/str}}</button>
|
||||
</div>
|
||||
</div>
|
||||
{{/showsave}}
|
||||
{{/hasresults}}
|
||||
{{^hasresults}}
|
||||
{{#str}}noresults, admin{{/str}}
|
||||
{{/hasresults}}
|
||||
</fieldset>
|
||||
</form>
|
Loading…
x
Reference in New Issue
Block a user