diff --git a/renderable.php b/renderable.php index dfd6d31..38c3bb7 100644 --- a/renderable.php +++ b/renderable.php @@ -348,7 +348,30 @@ public function action_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = $confirmaction = new confirm_action(get_string($confirmkey, 'scheduler')); } $act = new action_link($url, $title, $confirmaction, $attributes, $pix); - $act->primary = false; + return $act; + } + + /** + * Creates an action menu link with an optional confirmation dialogue attached. + * + * @param moodle_url $url URL of the action + * @param string $titlekey key of the link title + * @param string $iconkey key of the icon to display + * @param string|null $confirmkey key for the confirmation text + * @param string|null $id id attribute of the new link + * @return action_menu_link the new action link + */ + public function action_menu_link(moodle_url $url, $titlekey, $iconkey, $confirmkey = null, $id = null) { + $title = get_string($titlekey, 'scheduler'); + $pix = new pix_icon($iconkey, $title, 'moodle', array('class' => 'iconsmall', 'title' => '')); + $attributes = array(); + if ($id) { + $attributes['id'] = $id; + } + $act = new action_menu_link($url, $pix, $title, false, $attributes); + if ($confirmkey) { + $act->add_action(new confirm_action(get_string($confirmkey, 'scheduler'))); + } return $act; } diff --git a/renderer.php b/renderer.php index 2b2838c..e5e53f3 100644 --- a/renderer.php +++ b/renderer.php @@ -678,6 +678,29 @@ public function render_scheduler_slot_booker(scheduler_slot_booker $booker) { return html_writer::table($table); } + /** + * Renders an action menu component. Enhanced to allow confirmation dialogues in action menu items. + * + * @param action_menu $menu + * @return string HTML + */ + public function render_action_menu(action_menu $menu) { + + // We don't want the class icon there! + foreach ($menu->get_secondary_actions() as $action) { + if ($action instanceof \action_menu_link && $action->has_class('icon')) { + $action->attributes['class'] = preg_replace('/(^|\s+)icon(\s+|$)/i', '', $action->attributes['class']); + } + } + + if ($menu->is_empty()) { + return ''; + } + $context = $menu->export_for_template($this); + + return $this->render_from_template('mod_scheduler/action_menu', $context); + } + /** * Render a command bar. * diff --git a/teacherview.php b/teacherview.php index 5d5f064..a5dc709 100644 --- a/teacherview.php +++ b/teacherview.php @@ -459,8 +459,8 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $commandbar->title = get_string('actions', 'scheduler'); $addbuttons = array(); -$addbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'addsession')), 'addsession', 't/add'); -$addbuttons[] = $commandbar->action_link(new moodle_url($actionurl, array('what' => 'addslot')), 'addsingleslot', 't/add'); +$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, array('what' => 'addsession')), 'addsession', 't/add'); +$addbuttons[] = $commandbar->action_menu_link(new moodle_url($actionurl, array('what' => 'addslot')), 'addsingleslot', 't/add'); $commandbar->add_group(get_string('addcommands', 'scheduler'), $addbuttons); // If slots already exist, also show delete buttons. @@ -469,23 +469,23 @@ function scheduler_print_schedulebox(scheduler $scheduler, $studentid, $groupid $delselectedurl = new moodle_url($actionurl, array('what' => 'deleteslots')); $PAGE->requires->js_call_amd('mod_scheduler/delselected', 'init', [$delselectedurl->out(false)]); - $delselected = $commandbar->action_link($delselectedurl, 'deleteselection', 't/delete', - 'confirmdelete-selected', 'delselected'); + $delselected = $commandbar->action_menu_link($delselectedurl, 'deleteselection', 't/delete', + 'confirmdelete-selected', 'delselected'); $delselected->formid = 'delselected'; $delbuttons[] = $delselected; if ($permissions->can_edit_all_slots() && $subpage == 'allappointments') { - $delbuttons[] = $commandbar->action_link( + $delbuttons[] = $commandbar->action_menu_link( new moodle_url($actionurl, array('what' => 'deleteall')), 'deleteallslots', 't/delete', 'confirmdelete-all'); - $delbuttons[] = $commandbar->action_link( + $delbuttons[] = $commandbar->action_menu_link( new moodle_url($actionurl, array('what' => 'deleteallunused')), 'deleteallunusedslots', 't/delete', 'confirmdelete-unused'); } - $delbuttons[] = $commandbar->action_link( + $delbuttons[] = $commandbar->action_menu_link( new moodle_url($actionurl, array('what' => 'deleteunused')), 'deleteunusedslots', 't/delete', 'confirmdelete-myunused'); - $delbuttons[] = $commandbar->action_link( + $delbuttons[] = $commandbar->action_menu_link( new moodle_url($actionurl, array('what' => 'deleteonlymine')), 'deletemyslots', 't/delete', 'confirmdelete-mine'); diff --git a/templates/action_menu.mustache b/templates/action_menu.mustache new file mode 100644 index 0000000..b8eafd9 --- /dev/null +++ b/templates/action_menu.mustache @@ -0,0 +1,63 @@ +{{! + 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 . +}} +{{! + @template mod_scheduler/action_menu + + Action menu. Enhanced to allow confirmation dialogues in action menu items. + + Example context (json): + { + "classes": "", + "instance": "1", + "primary": { + "items": [{"rawhtml": "

Item in primary menu

"}] + }, + "secondary": { + "attributes": [ + {"name": "id", "value": "action-menu-1-menu"} + ], + "items": [ + { + "rawhtml": "

Item in secondary menu

" + } + ] + } + } +}} +
+ {{#primary}} + +
+ + {{#prioritise}}{{> mod_scheduler/action_menu_trigger }}{{/prioritise}} + + {{#items}} +
+ {{> mod_scheduler/action_menu_item }} +
+ {{/items}} + + {{^prioritise}} +
+ {{> mod_scheduler/action_menu_trigger }} +
+ {{/prioritise}} + +
+ + {{/primary}} +
diff --git a/templates/action_menu_item.mustache b/templates/action_menu_item.mustache new file mode 100644 index 0000000..8f60e47 --- /dev/null +++ b/templates/action_menu_item.mustache @@ -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 . +}} +{{! + @template mod_scheduler/action_menu_item + + Action menu item. Enhanced to allow confirmation dialogues in action menu items. + + Example context (json): + { + "rawhtml": "

[rawhtml]

" + } +}} +{{#actionmenulink}}{{> mod_scheduler/action_menu_link }}{{/actionmenulink}} +{{#actionmenufiller}} {{/actionmenufiller}} +{{#actionlink}}{{> core/action_link }}{{/actionlink}} +{{#pixicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/pixicon}} +{{#rawhtml}}{{{.}}}{{/rawhtml}} diff --git a/templates/action_menu_link.mustache b/templates/action_menu_link.mustache new file mode 100644 index 0000000..28039a0 --- /dev/null +++ b/templates/action_menu_link.mustache @@ -0,0 +1,44 @@ +{{! + 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 . +}} +{{! + @template mod_scheduler/action_menu_link + + Action menu link. Enhanced to allow confirmation dialogues in action menu items. + + Example context (json): + { + "text": "Example link text", + "showtext": true, + "url": "http://example.com/link" + } +}} +{{^disabled}} + + {{#icon}} + {{#pix}}{{key}}, {{component}}, {{title}}{{/pix}} + {{/icon}} + {{#showtext}} + {{{text}}} + {{/showtext}} + + {{#hasactions}} + {{> core/actions }} + {{/hasactions}} +{{/disabled}} +{{#disabled}} + {{#icon}}{{#pix}}{{key}},{{component}},{{title}}{{/pix}}{{/icon}}{{{text}}} +{{/disabled}} diff --git a/templates/action_menu_trigger.mustache b/templates/action_menu_trigger.mustache new file mode 100644 index 0000000..5d467d8 --- /dev/null +++ b/templates/action_menu_trigger.mustache @@ -0,0 +1,133 @@ +{{! + 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 . +}} +{{! + @template core/action_menu_trigger + + Action menu trigger. + + Example context (json): + { + "actiontext": "Example link text", + "title": "Example link title", + "triggerrole": "button", + "triggerattributes": [ + {"name": "data-boundary", "value": "window" } + ], + "url": "http://example.com/link", + "classes": "icon menu-action", + "instance": "1", + "triggerextraclasses": "", + "attributes": [ + {"name": "role", "value": "menuitem" }, + {"name": "data-title", "value": "mymoodle,admin" } + ], + "secondary": { + "classes": "menu align-tr-br", + "dropdownalignment": "dropdown-menu-right", + "attributes": [ + {"name": "id", "value": "action-menu-0-menu"}, + {"name": "data-rel", "value": "menu-content"}, + {"name": "role", "value": "menu"}, + {"name": "data-align", "value": "tr-br"} + ], + "items": [ + {"actionmenulink": + { + "id": "action_link59ecf8394a68078", + "disabled": false, + "text": "Dashboard", + "url": "http://example.com/link", + "icon": { + "key": "i/dashboard", + "component": null, + "title": "Dashboard" + }, + "classes": "menu-action", + "attributes": [ + {"name": "role", "value": "menuitem"}, + {"name": "data-title", "value": "mymoodle,admin"} + ], + "instance": 1, + "showtext": true + } + }, + {"actionmenufiller": + { + "id": "action_link59ecf8394a68079", + "disabled": false, + "text": "", + "url": "", + "icon": null, + "classes": "", + "attributes": [ + {"name": "role", "value": "menuitem"} + ] + } + } + ] + } + } +}} +