| 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 | 
            * Test page for action menu subpanel output component.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @copyright 2023 Ferran Recio <ferran@moodle.com>
  | 
        
        
            | 
            | 
           21 | 
            * @package   core
  | 
        
        
            | 
            | 
           22 | 
            * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            */
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           require_once(__DIR__ . '/../../../../config.php');
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           defined('BEHAT_SITE_RUNNING') || die();
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           $foo = optional_param('foo', 'none', PARAM_TEXT);
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           global $CFG, $PAGE, $OUTPUT;
  | 
        
        
            | 
            | 
           32 | 
           $PAGE->set_url('/lib/tests/behat/fixtures/action_menu_subpanel_output_testpage.php');
  | 
        
        
            | 
            | 
           33 | 
           $PAGE->add_body_class('limitedwidth');
  | 
        
        
            | 
            | 
           34 | 
           require_login();
  | 
        
        
            | 
            | 
           35 | 
           $PAGE->set_context(core\context\system::instance());
  | 
        
        
            | 
            | 
           36 | 
           $PAGE->set_title('Action menu subpanel test page');
  | 
        
        
            | 
            | 
           37 | 
              | 
        
        
            | 
            | 
           38 | 
           echo $OUTPUT->header();
  | 
        
        
            | 
            | 
           39 | 
              | 
        
        
            | 
            | 
           40 | 
           $choice1 = new core\output\choicelist('Choice example');
  | 
        
        
            | 
            | 
           41 | 
           $choice1->add_option("statusa", "Status A", [
  | 
        
        
            | 
            | 
           42 | 
               'url' => new moodle_url($PAGE->url, ['foo' => 'Aardvark']),
  | 
        
        
            | 
            | 
           43 | 
               'description' => 'Status A description',
  | 
        
        
            | 
            | 
           44 | 
               'icon' => new pix_icon('t/user', '', ''),
  | 
        
        
            | 
            | 
           45 | 
           ]);
  | 
        
        
            | 
            | 
           46 | 
           $choice1->add_option("statusb", "Status B", [
  | 
        
        
            | 
            | 
           47 | 
               'url' => new moodle_url($PAGE->url, ['foo' => 'Beetle']),
  | 
        
        
            | 
            | 
           48 | 
               'description' => 'Status B description',
  | 
        
        
            | 
            | 
           49 | 
               'icon' => new pix_icon('t/groupv', '', ''),
  | 
        
        
            | 
            | 
           50 | 
           ]);
  | 
        
        
            | 
            | 
           51 | 
           $choice1->set_selected_value('statusb');
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
           $choice2 = new core\output\choicelist('Choice example');
  | 
        
        
            | 
            | 
           54 | 
           $choice2->add_option("statusc", "Status C", [
  | 
        
        
            | 
            | 
           55 | 
               'url' => new moodle_url($PAGE->url, ['foo' => 'Caterpillar']),
  | 
        
        
            | 
            | 
           56 | 
               'description' => 'Status C description',
  | 
        
        
            | 
            | 
           57 | 
               'icon' => new pix_icon('t/groups', '', ''),
  | 
        
        
            | 
            | 
           58 | 
           ]);
  | 
        
        
            | 
            | 
           59 | 
           $choice2->add_option("statusd", "Status D", [
  | 
        
        
            | 
            | 
           60 | 
               'url' => new moodle_url($PAGE->url, ['foo' => 'Donkey']),
  | 
        
        
            | 
            | 
           61 | 
               'description' => 'Status D description',
  | 
        
        
            | 
            | 
           62 | 
               'icon' => new pix_icon('t/hide', '', ''),
  | 
        
        
            | 
            | 
           63 | 
           ]);
  | 
        
        
            | 
            | 
           64 | 
           $choice2->set_selected_value('statusc');
  | 
        
        
            | 
            | 
           65 | 
              | 
        
        
            | 
            | 
           66 | 
           $normalactionlink = new action_menu_link(
  | 
        
        
            | 
            | 
           67 | 
               new moodle_url($PAGE->url, ['foo' => 'bar']),
  | 
        
        
            | 
            | 
           68 | 
               new pix_icon('t/emptystar', ''),
  | 
        
        
            | 
            | 
           69 | 
               'Action link example',
  | 
        
        
            | 
            | 
           70 | 
               false
  | 
        
        
            | 
            | 
           71 | 
           );
  | 
        
        
            | 
            | 
           72 | 
              | 
        
        
            | 
            | 
           73 | 
           echo "<h2>Action menu subpanel test page</h2>";
  | 
        
        
            | 
            | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
           echo '<div id="paramcheck" class="mb-4">';
  | 
        
        
            | 
            | 
           76 | 
           echo "<p>Foo param value: $foo</p>";
  | 
        
        
            | 
            | 
           77 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           78 | 
              | 
        
        
            | 
            | 
           79 | 
           echo '<div id="regularscenario" class="mb-4">';
  | 
        
        
            | 
            | 
           80 | 
           echo "<h3>Basic example</h3>";
  | 
        
        
            | 
            | 
           81 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           82 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           83 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           84 | 
           $menu->add(
  | 
        
        
            | 
            | 
           85 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           86 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           87 | 
                   $choice1
  | 
        
        
            | 
            | 
           88 | 
               )
  | 
        
        
            | 
            | 
           89 | 
           );
  | 
        
        
            | 
            | 
           90 | 
           $menu->add(
  | 
        
        
            | 
            | 
           91 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           92 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           93 | 
                   $choice2
  | 
        
        
            | 
            | 
           94 | 
               )
  | 
        
        
            | 
            | 
           95 | 
           );
  | 
        
        
            | 
            | 
           96 | 
           echo '<div class="border p-2 d-flex flex-row">';
  | 
        
        
            | 
            | 
           97 | 
           echo '<div class="flex-fill">Menu right example</div><div>';
  | 
        
        
            | 
            | 
           98 | 
           echo $OUTPUT->render($menu);
  | 
        
        
            | 
            | 
           99 | 
           echo '</div></div>';
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           102 | 
              | 
        
        
            | 
            | 
           103 | 
           echo '<div id="menuleft" class="mb-4">';
  | 
        
        
            | 
            | 
           104 | 
           echo "<h3>Menu left</h3>";
  | 
        
        
            | 
            | 
           105 | 
              | 
        
        
            | 
            | 
           106 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           107 | 
           $menu->set_menu_left();
  | 
        
        
            | 
            | 
           108 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           109 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           110 | 
           $menu->add(
  | 
        
        
            | 
            | 
           111 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           112 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           113 | 
                   $choice1,
  | 
        
        
            | 
            | 
           114 | 
                   null,
  | 
        
        
            | 
            | 
           115 | 
                   null
  | 
        
        
            | 
            | 
           116 | 
               )
  | 
        
        
            | 
            | 
           117 | 
           );
  | 
        
        
            | 
            | 
           118 | 
           $menu->add(
  | 
        
        
            | 
            | 
           119 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           120 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           121 | 
                   $choice2,
  | 
        
        
            | 
            | 
           122 | 
                   null,
  | 
        
        
            | 
            | 
           123 | 
                   null
  | 
        
        
            | 
            | 
           124 | 
               )
  | 
        
        
            | 
            | 
           125 | 
           );
  | 
        
        
            | 
            | 
           126 | 
           echo '<div class="border p-2 d-flex flex-row"><div>';
  | 
        
        
            | 
            | 
           127 | 
           echo $OUTPUT->render($menu);
  | 
        
        
           | 1441 | 
           ariadna | 
           128 | 
           echo '</div><div class="flex-fill ms-2">Menu left example</div></div>';
  | 
        
        
           | 1 | 
           efrain | 
           129 | 
              | 
        
        
            | 
            | 
           130 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           131 | 
              | 
        
        
            | 
            | 
           132 | 
           echo '<div id="itemicon" class="mb-4">';
  | 
        
        
            | 
            | 
           133 | 
           echo "<h3>Menu item with icon</h3>";
  | 
        
        
            | 
            | 
           134 | 
              | 
        
        
            | 
            | 
           135 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           136 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           137 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           138 | 
           $menu->add(
  | 
        
        
            | 
            | 
           139 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           140 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           141 | 
                   $choice1,
  | 
        
        
            | 
            | 
           142 | 
                   null,
  | 
        
        
            | 
            | 
           143 | 
                   new pix_icon('t/locked', 'Locked icon')
  | 
        
        
            | 
            | 
           144 | 
               )
  | 
        
        
            | 
            | 
           145 | 
           );
  | 
        
        
            | 
            | 
           146 | 
           $menu->add(
  | 
        
        
            | 
            | 
           147 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           148 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           149 | 
                   $choice2,
  | 
        
        
            | 
            | 
           150 | 
                   null,
  | 
        
        
            | 
            | 
           151 | 
                   new pix_icon('t/message', 'Message icon')
  | 
        
        
            | 
            | 
           152 | 
               )
  | 
        
        
            | 
            | 
           153 | 
           );
  | 
        
        
            | 
            | 
           154 | 
           echo '<div class="border p-2 d-flex flex-row">';
  | 
        
        
            | 
            | 
           155 | 
           echo '<div class="flex-fill">Menu right example</div><div>';
  | 
        
        
            | 
            | 
           156 | 
           echo $OUTPUT->render($menu);
  | 
        
        
            | 
            | 
           157 | 
           echo '</div></div>';
  | 
        
        
            | 
            | 
           158 | 
              | 
        
        
            | 
            | 
           159 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           160 | 
              | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
           echo '<div id="itemiconleft" class="mb-4">';
  | 
        
        
            | 
            | 
           163 | 
           echo "<h3>Left menu with item icon</h3>";
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           166 | 
           $menu->set_menu_left();
  | 
        
        
            | 
            | 
           167 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           168 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           169 | 
           $menu->add(
  | 
        
        
            | 
            | 
           170 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           171 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           172 | 
                   $choice1,
  | 
        
        
            | 
            | 
           173 | 
                   null,
  | 
        
        
            | 
            | 
           174 | 
                   new pix_icon('t/locked', 'Locked icon')
  | 
        
        
            | 
            | 
           175 | 
               )
  | 
        
        
            | 
            | 
           176 | 
           );
  | 
        
        
            | 
            | 
           177 | 
           $menu->add(
  | 
        
        
            | 
            | 
           178 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           179 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           180 | 
                   $choice2,
  | 
        
        
            | 
            | 
           181 | 
                   null,
  | 
        
        
            | 
            | 
           182 | 
                   new pix_icon('t/message', 'Message icon')
  | 
        
        
            | 
            | 
           183 | 
               )
  | 
        
        
            | 
            | 
           184 | 
           );
  | 
        
        
            | 
            | 
           185 | 
           echo '<div class="border p-2 d-flex flex-row"><div>';
  | 
        
        
            | 
            | 
           186 | 
           echo $OUTPUT->render($menu);
  | 
        
        
           | 1441 | 
           ariadna | 
           187 | 
           echo '</div><div class="flex-fill ms-2">Menu left example</div></div>';
  | 
        
        
           | 1 | 
           efrain | 
           188 | 
              | 
        
        
            | 
            | 
           189 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
           echo '<div id="dataattributes" class="mb-4">';
  | 
        
        
            | 
            | 
           192 | 
           echo "<h3>Adding data attributes to menu item</h3>";
  | 
        
        
            | 
            | 
           193 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           194 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           195 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           196 | 
           $menu->add(
  | 
        
        
            | 
            | 
           197 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           198 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           199 | 
                   $choice1,
  | 
        
        
            | 
            | 
           200 | 
                   ['data-extra' => 'some extra value']
  | 
        
        
            | 
            | 
           201 | 
               )
  | 
        
        
            | 
            | 
           202 | 
           );
  | 
        
        
            | 
            | 
           203 | 
           $menu->add(
  | 
        
        
            | 
            | 
           204 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           205 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           206 | 
                   $choice2,
  | 
        
        
            | 
            | 
           207 | 
                   ['data-extra' => 'some other value']
  | 
        
        
            | 
            | 
           208 | 
               )
  | 
        
        
            | 
            | 
           209 | 
           );
  | 
        
        
            | 
            | 
           210 | 
           echo '<div class="border p-2 d-flex flex-row">';
  | 
        
        
            | 
            | 
           211 | 
           echo '<div class="flex-fill">Menu right example</div><div>';
  | 
        
        
            | 
            | 
           212 | 
           echo $OUTPUT->render($menu);
  | 
        
        
            | 
            | 
           213 | 
           echo '</div></div>';
  | 
        
        
            | 
            | 
           214 | 
           echo '<div class="mt-1 p-2 border" id="datachecks">Nothing here.</div>';
  | 
        
        
            | 
            | 
           215 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           216 | 
              | 
        
        
            | 
            | 
           217 | 
           $inlinejs = <<<EOF
  | 
        
        
            | 
            | 
           218 | 
               const datachecks = document.getElementById('datachecks');
  | 
        
        
            | 
            | 
           219 | 
               const dataitems = document.querySelectorAll('[data-extra]');
  | 
        
        
            | 
            | 
           220 | 
               let dataitemshtml = '';
  | 
        
        
            | 
            | 
           221 | 
               for (let i = 0; i < dataitems.length; i++) {
  | 
        
        
            | 
            | 
           222 | 
                   dataitemshtml += '<p>Extra data attribute detected: ' + dataitems[i].getAttribute('data-extra') + '</p>';
  | 
        
        
            | 
            | 
           223 | 
               }
  | 
        
        
            | 
            | 
           224 | 
               datachecks.innerHTML = dataitemshtml;
  | 
        
        
            | 
            | 
           225 | 
           EOF;
  | 
        
        
            | 
            | 
           226 | 
              | 
        
        
            | 
            | 
           227 | 
           $PAGE->requires->js_amd_inline($inlinejs);
  | 
        
        
            | 
            | 
           228 | 
              | 
        
        
            | 
            | 
           229 | 
           echo '<div id="drawersimulation" class="mb-4">';
  | 
        
        
            | 
            | 
           230 | 
           echo "<h3>Drawer like example</h3>";
  | 
        
        
            | 
            | 
           231 | 
           $menu = new action_menu();
  | 
        
        
            | 
            | 
           232 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           233 | 
           $menu->add($normalactionlink);
  | 
        
        
            | 
            | 
           234 | 
           $menu->add(
  | 
        
        
            | 
            | 
           235 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           236 | 
                   'Subpanel example',
  | 
        
        
            | 
            | 
           237 | 
                   $choice1
  | 
        
        
            | 
            | 
           238 | 
               )
  | 
        
        
            | 
            | 
           239 | 
           );
  | 
        
        
            | 
            | 
           240 | 
           $menu->add(
  | 
        
        
            | 
            | 
           241 | 
               new core\output\local\action_menu\subpanel(
  | 
        
        
            | 
            | 
           242 | 
                   'Another subpanel',
  | 
        
        
            | 
            | 
           243 | 
                   $choice2
  | 
        
        
            | 
            | 
           244 | 
               )
  | 
        
        
            | 
            | 
           245 | 
           );
  | 
        
        
            | 
            | 
           246 | 
           echo '<div class="border p-2 d-flex flex-row" data-region="fixed-drawer" data-behat-fake-drawer="true" style="width: 350px;">';
  | 
        
        
            | 
            | 
           247 | 
           echo '<div class="flex-fill">Drawer example</div><div>';
  | 
        
        
            | 
            | 
           248 | 
           echo $OUTPUT->render($menu);
  | 
        
        
            | 
            | 
           249 | 
           echo '</div></div>';
  | 
        
        
            | 
            | 
           250 | 
              | 
        
        
            | 
            | 
           251 | 
           echo '</div>';
  | 
        
        
            | 
            | 
           252 | 
              | 
        
        
            | 
            | 
           253 | 
           echo $OUTPUT->footer();
  |