91334a46b5
Co-authored-by: Cursor <cursoragent@cursor.com>
154 lines
6.1 KiB
PHP
154 lines
6.1 KiB
PHP
<?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/>.
|
||
|
||
/**
|
||
* Reset-to-default controls for access settings (role mapping + feature matrix).
|
||
*
|
||
* @package mod_meetletacbfree
|
||
* @copyright 2026 MeetLet <info@meetlet.net>
|
||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||
*/
|
||
|
||
namespace mod_meetletacbfree\admin;
|
||
|
||
use mod_meetletacbfree\local\icons;
|
||
use moodle_url;
|
||
|
||
defined('MOODLE_INTERNAL') || die();
|
||
|
||
/**
|
||
* Shared reset button, modal, and client strings for the access settings tab.
|
||
*/
|
||
class access_reset_ui {
|
||
/** @var bool */
|
||
protected static $assetsrendered = false;
|
||
|
||
/**
|
||
* Toolbar with a section-specific reset button.
|
||
*/
|
||
public static function toolbar(string $section): string {
|
||
if ($section === 'rolemapping') {
|
||
$label = get_string('reset_rolemapping', 'meetletacbfree');
|
||
} else if ($section === 'featureaccess') {
|
||
$label = get_string('reset_featureaccess', 'meetletacbfree');
|
||
} else {
|
||
return '';
|
||
}
|
||
|
||
return \html_writer::div(
|
||
\html_writer::tag('button',
|
||
icons::svg('refresh') .
|
||
\html_writer::span($label, 'meetlet-btn-with-icon__label'),
|
||
[
|
||
'type' => 'button',
|
||
'class' => 'meetlet-settings-btn meetlet-btn-with-icon meetlet-access-reset-btn',
|
||
'data-meetlet-reset-section' => $section,
|
||
]
|
||
),
|
||
'meetlet-access-reset-toolbar'
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Modal + config root (render once on the access settings tab).
|
||
*/
|
||
public static function page_assets(moodle_url $ajaxurl): string {
|
||
if (self::$assetsrendered) {
|
||
return '';
|
||
}
|
||
self::$assetsrendered = true;
|
||
|
||
$strings = self::client_strings();
|
||
$html = \html_writer::div('', '', [
|
||
'id' => 'meetlet-access-reset-root',
|
||
'hidden' => 'hidden',
|
||
'data-endpoint' => $ajaxurl->out(false),
|
||
'data-sesskey' => sesskey(),
|
||
'data-strings' => json_encode($strings, JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
$html .= self::modal_html();
|
||
return $html;
|
||
}
|
||
|
||
/**
|
||
* @return array<string,string>
|
||
*/
|
||
public static function client_strings(): array {
|
||
return [
|
||
'modal_cancel' => get_string('accessreset_modal_cancel', 'meetletacbfree'),
|
||
'modal_close' => get_string('accessreset_modal_close', 'meetletacbfree'),
|
||
'modal_ok' => get_string('accessreset_modal_ok', 'meetletacbfree'),
|
||
'confirm_reset' => get_string('accessreset_confirm_reset', 'meetletacbfree'),
|
||
'confirm_rolemapping_title' => get_string('reset_rolemapping_confirm_title', 'meetletacbfree'),
|
||
'confirm_rolemapping' => get_string('reset_rolemapping_confirm', 'meetletacbfree'),
|
||
'confirm_featureaccess_title' => get_string('reset_featureaccess_confirm_title', 'meetletacbfree'),
|
||
'confirm_featureaccess' => get_string('reset_featureaccess_confirm', 'meetletacbfree'),
|
||
'success_rolemapping' => get_string('reset_success_rolemapping', 'meetletacbfree'),
|
||
'success_featureaccess' => get_string('reset_success_featureaccess', 'meetletacbfree'),
|
||
'error' => get_string('reset_error', 'meetletacbfree'),
|
||
'busy' => get_string('accessreset_busy', 'meetletacbfree'),
|
||
];
|
||
}
|
||
|
||
protected static function modal_html(): string {
|
||
return \html_writer::div(
|
||
\html_writer::div('', 'meetlet-modal__backdrop', ['data-meetlet-modal-dismiss' => '1']) .
|
||
\html_writer::div(
|
||
\html_writer::div(
|
||
\html_writer::tag('h3', '', [
|
||
'class' => 'meetlet-modal__title',
|
||
'id' => 'meetlet-access-reset-modal-title',
|
||
]) .
|
||
\html_writer::tag('button', '×', [
|
||
'type' => 'button',
|
||
'class' => 'meetlet-modal__close',
|
||
'data-meetlet-modal-dismiss' => '1',
|
||
'aria-label' => get_string('accessreset_modal_close', 'meetletacbfree'),
|
||
]),
|
||
'meetlet-modal__head'
|
||
) .
|
||
\html_writer::div('', 'meetlet-modal__body', [
|
||
'id' => 'meetlet-access-reset-modal-body',
|
||
]) .
|
||
\html_writer::div(
|
||
\html_writer::tag('button', get_string('accessreset_modal_cancel', 'meetletacbfree'), [
|
||
'type' => 'button',
|
||
'class' => 'btn btn-outline-secondary',
|
||
'data-meetlet-modal-dismiss' => '1',
|
||
]) .
|
||
\html_writer::tag('button', get_string('accessreset_confirm_reset', 'meetletacbfree'), [
|
||
'type' => 'button',
|
||
'class' => 'btn btn-outline-danger',
|
||
'id' => 'meetlet-access-reset-modal-confirm',
|
||
]),
|
||
'meetlet-modal__foot'
|
||
),
|
||
'meetlet-modal__dialog',
|
||
[
|
||
'role' => 'dialog',
|
||
'aria-modal' => 'true',
|
||
'aria-labelledby' => 'meetlet-access-reset-modal-title',
|
||
]
|
||
),
|
||
'meetlet-modal meetlet-modal--confirm',
|
||
[
|
||
'id' => 'meetlet-access-reset-modal',
|
||
'hidden' => 'hidden',
|
||
]
|
||
);
|
||
}
|
||
}
|