Skip to content

Commit

Permalink
Replace markup in manage.php with template file
Browse files Browse the repository at this point in the history
- Add `templates/manage_form.mustache`
- Render template with selector HTML and other context from `manage.php`
  • Loading branch information
daniil-berg committed Sep 19, 2024
1 parent 499dfcb commit 4f8a228
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 48 deletions.
57 changes: 9 additions & 48 deletions manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,52 +87,13 @@
}

echo $OUTPUT->heading(get_string('user_exceptions', 'availability_shibboleth2fa'));

?>
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>">
<div>
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
<table class="roleassigntable generaltable generalbox boxaligncenter">
<tr>
<td id="existingcell">
<p>
<label for="removeselect">
<?php print_string('users_with_exception', 'availability_shibboleth2fa'); ?>
</label>
</p>
<?php $currentuserselector->display() ?>
</td>
<td id="buttonscell">
<div id="addcontrols">
<input name="add"
id="add"
type="submit"
value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>"
title="<?php print_string('add'); ?>"
/>
<br />
</div>
<div id="removecontrols">
<input name="remove"
id="remove"
type="submit"
value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>"
title="<?php print_string('remove'); ?>"
/>
</div>
</td>
<td id="potentialcell">
<p>
<label for="addselect">
<?php print_string('users_without_exception', 'availability_shibboleth2fa'); ?>
</label>
</p>
<?php $potentialuserselector->display() ?>
</td>
</tr>
</table>
</div>
</form>
<?php

$templatecontext = [
'actionurl' => $PAGE->url->out(),
'sesskey' => sesskey(),
'currentuserselector' => $currentuserselector->display(return: true),
'potentialuserselector' => $potentialuserselector->display(return: true),
'larrow' => $OUTPUT->larrow(),
'rarrow' => $OUTPUT->rarrow(),
];
echo $OUTPUT->render_from_template('availability_shibboleth2fa/manage_form', $templatecontext);
echo $OUTPUT->footer();
90 changes: 90 additions & 0 deletions templates/manage_form.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{{!
This file is part of Moodle - https://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 availability_shibboleth2fa/manage_form
Form for managing exceptions from the 2FA condition for users in a course.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* actionurl URL to assign to the `action` attribute of the HTML form
* sesskey Value to assign to the hidden `sesskey` form field
* currentuserselector Fully rendered selector field HTML markup for users that already have an exception
* potentialuserselector Fully rendered selector field HTML markup for users that an exception can be made for
* larrow Left arrow-like character
* larrow Right arrow-like character
Example context (json):
{
"actionurl": "/availability/condition/shibboleth2fa/manage.php?id=123",
"sesskey": "abc123",
"currentuserselector": "<div><select><option>...</option></select></div>"
"potentialuserselector": "<div><select><option>...</option></select></div>"
"larrow": "&#x25C4;",
"rarrow": "&#x25BA;"
}
}}

<form id="assignform" method="post" action="{{actionurl}}">
<div>
<input type="hidden" name="sesskey" value="{{sesskey}}" />
<table class="roleassigntable generaltable generalbox boxaligncenter">
<tr>
<td id="existingcell">
<p>
<label for="removeselect">
{{#str}} users_with_exception, availability_shibboleth2fa {{/str}}
</label>
</p>
{{{currentuserselector}}}
</td>
<td id="buttonscell">
<div id="addcontrols">
<input name="add"
id="add"
type="submit"
value="{{{larrow}}}&nbsp;{{#str}} add {{/str}}"
title="{{#str}} add {{/str}}"
/>
<br />
</div>
<div id="removecontrols">
<input name="remove"
id="remove"
type="submit"
value="{{#str}} remove {{/str}}&nbsp;{{{rarrow}}}"
title="{{#str}} remove {{/str}}"
/>
</div>
</td>
<td id="potentialcell">
<p>
<label for="addselect">
{{#str}} users_without_exception, availability_shibboleth2fa {{/str}}
</label>
</p>
{{{potentialuserselector}}}
</td>
</tr>
</table>
</div>
</form>

0 comments on commit 4f8a228

Please sign in to comment.