1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Moodle Component Library
|
|
|
19 |
*
|
|
|
20 |
* A sample page with dropdowns.
|
|
|
21 |
*
|
|
|
22 |
* @package tool_componentlibrary
|
|
|
23 |
* @copyright 2023 Ferran Recio <ferran@moodle.com>
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
declare(strict_types=1);
|
|
|
28 |
|
|
|
29 |
require_once(__DIR__ . '/../../../../config.php');
|
|
|
30 |
|
|
|
31 |
require_login();
|
|
|
32 |
require_capability('moodle/site:configview', context_system::instance());
|
|
|
33 |
|
|
|
34 |
global $PAGE, $OUTPUT;
|
|
|
35 |
$PAGE->set_url(new moodle_url('/admin/tool/componentlibrary/examples/dropdowns.php'));
|
|
|
36 |
$PAGE->set_context(context_system::instance());
|
|
|
37 |
$PAGE->set_pagelayout('embedded');
|
|
|
38 |
|
|
|
39 |
$PAGE->set_heading('Moodle dropdowns');
|
|
|
40 |
$PAGE->set_title('Moodle dropdowns');
|
|
|
41 |
|
|
|
42 |
/** @var core_renderer $output*/
|
|
|
43 |
$output = $PAGE->get_renderer('core');
|
|
|
44 |
|
|
|
45 |
echo $output->header();
|
|
|
46 |
|
|
|
47 |
echo $output->paragraph(
|
|
|
48 |
'<strong>Important note:</strong> dropdowns are not prepared
|
|
|
49 |
to be displayed inside iframes. You may need to scroll to see the
|
|
|
50 |
the dropdown content.'
|
|
|
51 |
);
|
|
|
52 |
|
|
|
53 |
echo $output->heading("Dropdown dialog example", 3);
|
|
|
54 |
echo '<div class="p-3">';
|
|
|
55 |
|
|
|
56 |
$dialog = new core\output\local\dropdown\dialog(
|
|
|
57 |
'Open dialog',
|
|
|
58 |
'<p>Some rich content <b>element</b>.</p>
|
|
|
59 |
<ul>
|
|
|
60 |
<li>Item 1 <a href="#">Link 1</a></li>
|
|
|
61 |
<li>Item 2 <a href="#">Link 2</a></li>
|
|
|
62 |
</ul>'
|
|
|
63 |
);
|
|
|
64 |
echo $OUTPUT->render($dialog);
|
|
|
65 |
echo "</div>";
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
echo $output->heading("Dropdown status example", 3);
|
|
|
69 |
echo '<div class="p-3">';
|
|
|
70 |
|
|
|
71 |
$choice = new core\output\choicelist('Choice description text');
|
|
|
72 |
|
|
|
73 |
// Option one is a link.
|
|
|
74 |
$choice->add_option('option1', 'Option 1', [
|
|
|
75 |
'icon' => new pix_icon('t/show', 'Eye icon 1'),
|
|
|
76 |
'url' => new moodle_url('/admin/tool/componentlibrary/examples/dropdowns.php'),
|
|
|
77 |
]);
|
|
|
78 |
// Option two has an icon and description.
|
|
|
79 |
$choice->add_option('option2', 'Option 2', [
|
|
|
80 |
'description' => 'Option 2 description',
|
|
|
81 |
'icon' => new pix_icon('t/hide', 'Eye icon 2'),
|
|
|
82 |
]);
|
|
|
83 |
// Option three is disabled.
|
|
|
84 |
$choice->add_option('option3', 'Option 3', [
|
|
|
85 |
'description' => 'Option 3 description',
|
|
|
86 |
'icon' => new pix_icon('t/stealth', 'Eye icon 3'),
|
|
|
87 |
'disabled' => true,
|
|
|
88 |
]);
|
|
|
89 |
|
|
|
90 |
$choice->set_selected_value('option2');
|
|
|
91 |
|
|
|
92 |
$dialog = new core\output\local\dropdown\status('Open dialog button', $choice);
|
|
|
93 |
echo $OUTPUT->render($dialog);
|
|
|
94 |
echo "</div>";
|
|
|
95 |
|
|
|
96 |
echo $output->heading("Dropdown status in update mode example", 3);
|
|
|
97 |
echo '<div class="p-3">';
|
|
|
98 |
|
|
|
99 |
$choice = new core\output\choicelist('Choice description text');
|
|
|
100 |
|
|
|
101 |
$choice->add_option('option1', 'Option 1', [
|
|
|
102 |
'description' => 'Option 1 description',
|
|
|
103 |
'icon' => new pix_icon('t/show', 'Eye icon 1'),
|
|
|
104 |
]);
|
|
|
105 |
$choice->add_option('option2', 'Option 2', [
|
|
|
106 |
'description' => 'Option 2 description',
|
|
|
107 |
'icon' => new pix_icon('t/hide', 'Eye icon 2'),
|
|
|
108 |
]);
|
|
|
109 |
|
|
|
110 |
$choice->set_selected_value('option2');
|
|
|
111 |
|
|
|
112 |
$dialog = new core\output\local\dropdown\status(
|
|
|
113 |
'Open dialog button',
|
|
|
114 |
$choice,
|
|
|
115 |
[
|
|
|
116 |
'buttonsync' => true,
|
|
|
117 |
'updatestatus' => true,
|
|
|
118 |
'dialogwidth' => core\output\local\dropdown\status::WIDTH['big']
|
|
|
119 |
]
|
|
|
120 |
);
|
|
|
121 |
echo $OUTPUT->render($dialog);
|
|
|
122 |
echo "</div>";
|
|
|
123 |
|
|
|
124 |
echo $output->footer();
|