From 4f9e9319932c17bf93f69a33952ea70327bb830b Mon Sep 17 00:00:00 2001 From: Kevin Percy Date: Tue, 22 Aug 2023 11:46:27 +0800 Subject: [PATCH] MDL-77640 gradebook: Moved add items to new tertiary nav dropdown --- .../output/gradebook_setup_action_bar.php | 48 ++++++------- .../gradebook_setup_action_bar.mustache | 70 +++++-------------- 2 files changed, 42 insertions(+), 76 deletions(-) diff --git a/grade/classes/output/gradebook_setup_action_bar.php b/grade/classes/output/gradebook_setup_action_bar.php index 2de80d68081..7a1ce3c2bc1 100644 --- a/grade/classes/output/gradebook_setup_action_bar.php +++ b/grade/classes/output/gradebook_setup_action_bar.php @@ -54,57 +54,55 @@ class gradebook_setup_action_bar extends action_bar { $generalnavselector = new general_action_bar($this->context, new moodle_url('/grade/edit/tree/index.php', ['id' => $courseid]), 'settings', 'setup'); $data = $generalnavselector->export_for_template($output); + $actions = []; + $additemurl = new moodle_url('#'); - // Add a button to the action bar with a link to the 'add grade item' page. - $addgradeitemlink = new moodle_url('#'); - $addgradeitembutton = new \single_button( - $addgradeitemlink, + // Add a button to the action bar dropdown with a link to the 'add grade item' modal. + $actions[] = new \action_menu_link_secondary( + $additemurl, + null, get_string('additem', 'grades'), - 'get', - \single_button::BUTTON_SECONDARY, [ 'data-courseid' => $courseid, 'data-itemid' => -1, 'data-trigger' => 'add-item-form', - 'data-gprplugin' => 'tree' + 'data-gprplugin' => 'tree', ] ); - $data['addgradeitembutton'] = $addgradeitembutton->export_for_template($output); - // If outcomes are enabled, add a button to the action bar with a link to the 'add outcome item' page. + // If outcomes are enabled, add a button to the action bar dropdown with a link to the 'add outcome item' modal. if (!empty($CFG->enableoutcomes) && count(\grade_outcome::fetch_all_available($courseid)) > 0) { - // Add a button to the action bar with a link to the 'add outcome item' page. - $addoutcomeitem = new moodle_url('#'); - $addoutcomeitembutton = new \single_button( - $addoutcomeitem, + // Add a button to the action bar dropdown with a link to the 'add outcome item' modal. + $actions[] = new \action_menu_link_secondary( + $additemurl, + null, get_string('addoutcomeitem', 'grades'), - 'get', - \single_button::BUTTON_SECONDARY, [ - 'class' => 'btn btn-secondary', 'data-courseid' => $courseid, 'data-itemid' => -1, 'data-trigger' => 'add-outcome-form', - 'data-gprplugin' => 'tree' + 'data-gprplugin' => 'tree', ] ); - $data['addoutcomeitembutton'] = $addoutcomeitembutton->export_for_template($output); } - // Add a button to the action bar with a link to the 'add category' page. - $addgradecategorybutton = new \single_button( - $addgradeitemlink, + // Add a button to the action bar dropdown with a link to the 'add category' modal. + $actions[] = new \action_menu_link_secondary( + $additemurl, + null, get_string('addcategory', 'grades'), - 'get', - \single_button::BUTTON_SECONDARY, [ 'data-courseid' => $courseid, 'data-category' => -1, 'data-trigger' => 'add-category-form', - 'data-gprplugin' => 'tree' + 'data-gprplugin' => 'tree', ] ); - $data['addcategorybutton'] = $addgradecategorybutton->export_for_template($output); + + $addmenu = new \action_menu($actions); + $addmenu->set_menu_trigger(get_string('add'), 'btn font-weight-bold'); + $data['addmenu'] = $addmenu->export_for_template($output); + return $data; } } diff --git a/grade/templates/gradebook_setup_action_bar.mustache b/grade/templates/gradebook_setup_action_bar.mustache index ed0a14e0ed7..cf006792a8b 100644 --- a/grade/templates/gradebook_setup_action_bar.mustache +++ b/grade/templates/gradebook_setup_action_bar.mustache @@ -18,9 +18,7 @@ Context variables required for this template: * generalnavselector - The data object containing the required properties to render the general navigation selector. - * addgradeitembutton - The data object containing the required properties to render the 'add grade item' button. - * addoutcomeitembutton - The data object containing the required properties to render the 'add outcome item' button. - * addcategorybutton - The data object containing the required properties to render the 'add category' button. + * addmenu - The data object containing the required properties to render the 'Add' action menu. Example context (json): { @@ -62,39 +60,17 @@ } ] }, - "addgradeitembutton": { - "id": "single_button12345", - "method" : "get", - "classes": "singlebutton", - "formid": null, - "url" : "#", - "primary" : false, - "tooltip" : null, - "label" : "Add grade item", - "attributes": [] - }, - "addoutcomeitembutton": { - "id": "single_button13245", - "method" : "get", - "classes": "singlebutton", - "formid": null, - "url" : "#", - "primary" : false, - "tooltip" : null, - "label" : "Add outcome item", - "attributes": [] - }, - "addcategorybutton": { - "id": "single_button14325", - "method" : "get", - "classes": "singlebutton", - "formid": null, - "url" : "#", - "primary" : false, - "tooltip" : null, - "label" : "Add category", - "attributes": [] - } + "addmenu": [ + { + "classes": "", + "primary": { + "items": [{"rawhtml": "

Item in primary menu

"}] + }, + "secondary": { + "items": [{"rawhtml": "

Item in secondary menu

"}] + } + } + ] } }}
@@ -105,20 +81,12 @@
{{/generalnavselector}} - {{#addgradeitembutton}} - - {{/addgradeitembutton}} - {{#addoutcomeitembutton}} - - {{/addoutcomeitembutton}} - {{#addcategorybutton}} - - {{/addcategorybutton}} + + +