Skip to content

Commit

Permalink
MDL-55564 core_admin: Convert admin settings to use templates
Browse files Browse the repository at this point in the history
Part of MDL-55071
  • Loading branch information
Frederic Massart authored and danpoltawski committed Sep 23, 2016
1 parent 58357d4 commit df76022
Show file tree
Hide file tree
Showing 26 changed files with 1,170 additions and 482 deletions.
65 changes: 34 additions & 31 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@

// ---------------------------------------------------------------------------------------------------------------

echo '<form action="' . $PAGE->url . '" method="post" id="adminsettings">';
echo '<div class="settingsform clearfix">';
echo html_writer::input_hidden_params($PAGE->url);
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="return" value="'.$return.'" />';
// HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
echo prevent_form_autofill_password();

echo $settingspage->output_html();

echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';

echo '</div>';
echo '</form>';
$pageparams = $PAGE->url->params();
$context = [
'actionurl' => $PAGE->url->out(false),
'params' => array_map(function($param) use ($pageparams) {
return [
'name' => $param,
'value' => $pageparams[$param]
];
}, array_keys($pageparams)),
'sesskey' => sesskey(),
'return' => $return,
'title' => null,
'settings' => $settingspage->output_html(),
'showsave' => true
];

echo $OUTPUT->render_from_template('core_admin/settings', $context);

} else {
if ($PAGE->user_allowed_editing()) {
Expand Down Expand Up @@ -121,23 +124,23 @@

// ---------------------------------------------------------------------------------------------------------------

echo '<form action="' . $PAGE->url . '" method="post" id="adminsettings">';
echo '<div class="settingsform clearfix">';
echo html_writer::input_hidden_params($PAGE->url);
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
echo '<input type="hidden" name="return" value="'.$return.'" />';
// HACK to prevent browsers from automatically inserting the user's password into the wrong fields.
echo prevent_form_autofill_password();
echo $OUTPUT->heading($settingspage->visiblename);

echo $settingspage->output_html();

if ($settingspage->show_save()) {
echo '<div class="form-buttons"><input class="form-submit" type="submit" value="'.get_string('savechanges','admin').'" /></div>';
}

echo '</div>';
echo '</form>';
$pageparams = $PAGE->url->params();
$context = [
'actionurl' => $PAGE->url->out(false),
'params' => array_map(function($param) use ($pageparams) {
return [
'name' => $param,
'value' => $pageparams[$param]
];
}, array_keys($pageparams)),
'sesskey' => sesskey(),
'return' => $return,
'title' => $settingspage->visiblename,
'settings' => $settingspage->output_html(),
'showsave' => $settingspage->show_save()
];

echo $OUTPUT->render_from_template('core_admin/settings', $context);
}

$PAGE->requires->yui_module('moodle-core-formchangechecker',
Expand Down
43 changes: 43 additions & 0 deletions admin/templates/setting.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{!
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/>.
}}
{{!
Setting.
}}
<div class="form-item clearfix" id="{{id}}">
<div class="form-label">
<label {{#labelfor}}for="{{labelfor}}"{{/labelfor}}>
{{{title}}}
{{#override}}
<div class="form-overridden">{{override}}</div>
{{/override}}
{{#warning}}
<div class="form-warning">{{warning}}</div>
{{/warning}}
</label>
<span class="form-shortname">{{{name}}}</span>
</div>
<div class="form-setting">
{{#error}}
<div><span class="error">{{error}}</span></div>
{{/error}}
{{{element}}}
{{#default}}
<div class="form-defaultinfo">{{{default}}}</div>
{{/default}}
</div>
<div class="form-description">{{{description}}}</div>
</div>
23 changes: 23 additions & 0 deletions admin/templates/setting_configcheckbox.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{!
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/>.
}}
{{!
Setting configdirectory.
}}
<div class="form-checkbox defaultsnext">
<input type="hidden" name="{{name}}" value="{{no}}">
<input type="checkbox" name="{{name}}" value="{{value}}" id="{{id}}" {{#checked}}checked{{/checked}}>
</div>
30 changes: 30 additions & 0 deletions admin/templates/setting_configcolourpicker.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{!
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/>.
}}
{{!
Setting configcolourpicker.
}}
<div class="form-colourpicker defaultsnext">
<div class="admin_colourpicker clearfix">
{{#icon}}
{{>core/pix_icon}}
{{/icon}}
</div>
<input type="text" name="{{name}}" id="{{id}}" value="{{value}}" size="12">
{{#haspreviewconfig}}
<input type="button" id="{{id}}_preview" value={{#quote}}{{#str}}preview{{/str}}{{/quote}} class="admin_colourpicker_preview">
{{/haspreviewconfig}}
</div>
20 changes: 20 additions & 0 deletions admin/templates/setting_configdirectory.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{!
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/>.
}}
{{!
Setting configdirectory.
}}
{{>core_admin/setting_configfile}}
29 changes: 29 additions & 0 deletions admin/templates/setting_configduration.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{!
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/>.
}}
{{!
Setting configduration.
}}
<div class="form-duration defaultsnext">
<input type="text" size="5" id="{{id}}v" name="{{name}}[v]" value="{{value}}">
<label class="accesshide" for="{{id}}u">{{#str}}durationunits, admin{{/str}}</label>
<select id="{{id}}u" name="{{name}}[u]">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</select>
</div>

22 changes: 22 additions & 0 deletions admin/templates/setting_configempty.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{!
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/>.
}}
{{!
Setting configempty.
}}
<div class="form-empty">
<input type="hidden" name="{{name}}" id="{{id}}" value="">
</div>
20 changes: 20 additions & 0 deletions admin/templates/setting_configexecutable.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{!
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/>.
}}
{{!
Setting configexecutable.
}}
{{>core_admin/setting_configfile}}
31 changes: 31 additions & 0 deletions admin/templates/setting_configfile.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{!
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/>.
}}
{{!
Setting configfile.
}}
<div class="form-file defaultsnext">
<input type="text" name="{{name}}" id="{{id}}" size="{{size}}" value="{{value}}" {{#readonly}}readonly{{/readonly}}>
{{#showvalidity}}
{{#valid}}
<span class="pathok">&#x2714;</span>
{{/valid}}
{{^valid}}
<span class="patherror">&#x2718;</span>
{{/valid}}
{{/showvalidity}}
</div>

20 changes: 20 additions & 0 deletions admin/templates/setting_confightmleditor.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{!
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/>.
}}
{{!
Setting confightmleditor.
}}
{{>core_admin/setting_configtextarea}}
32 changes: 32 additions & 0 deletions admin/templates/setting_configmulticheckbox.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{!
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/>.
}}
{{!
Setting configmulticheckbox.
}}
<div class="form-multicheckbox">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
{{#hasoptions}}
<ul>
{{#options}}
<li>
<input type="checkbox" name="{{name}}[{{key}}]" value="1" id="{{id}}_{{key}}" {{#checked}}checked{{/checked}}>
<label for="{{id}}_{{key}}">{{{label}}}</label>
</li>
{{/options}}
</ul>
{{/hasoptions}}
</div>
28 changes: 28 additions & 0 deletions admin/templates/setting_configmultiselect.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{!
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/>.
}}
{{!
Setting configmultiselect.
}}
<div class="form-select">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
<select id="{{id}}" name="{{name}}[]" size="{{size}}" multiple>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</select>
</div>

Loading

0 comments on commit df76022

Please sign in to comment.