Skip to content

Commit

Permalink
Merge branch 'MDL-75337-master' of https://github.com/laurentdavid/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 24, 2023
2 parents ebbcfa9 + 9686196 commit ae53d04
Show file tree
Hide file tree
Showing 70 changed files with 675 additions and 153 deletions.
2 changes: 1 addition & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\
$output .= $this->container_end();
}

$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', true);
$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';
$output .= $this->render($button);
$output .= $this->footer();
Expand Down
2 changes: 1 addition & 1 deletion admin/searchareas.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
$cancelurl = new moodle_url('/admin/searchareas.php');
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirm_' . $action, 'search', $a),
new single_button($actionurl, get_string('continue'), 'post', true),
new single_button($actionurl, get_string('continue'), 'post', single_button::BUTTON_PRIMARY),
new single_button($cancelurl, get_string('cancel'), 'get'));
echo $OUTPUT->footer();
exit;
Expand Down
2 changes: 1 addition & 1 deletion admin/searchreindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// Display confirmation prompt.
echo $OUTPUT->confirm(get_string('gradualreindex_confirm', 'search', html_writer::tag('strong', $areaname)),
new single_button(new moodle_url('/admin/searchreindex.php', ['areaid' => $areaid,
'sesskey' => sesskey()]), get_string('continue'), 'post', true),
'sesskey' => sesskey()]), get_string('continue'), 'post', single_button::BUTTON_PRIMARY),
new single_button(new moodle_url('/admin/searchareas.php'), get_string('cancel'), 'get'));
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/brickfield/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function analysisbutton(int $courseid) : string {
$link,
get_string('schedule:requestanalysis', manager::PLUGINNAME),
'post',
true,
\single_button::BUTTON_PRIMARY,
['class' => $classname]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ Outline buttons are used for buttons that controll part of the user interface, l

### Using the single_select renderer

The ```single_select()``` renderer allows you to quickly add a button with an action to a page without having to write a template for the page. Single select buttons are added as miniature forms that can pass custom form data.
The ```single_button()``` renderer allows you to quickly add a button with an action to a page without having to write a template for the page. Single select buttons are added as miniature forms that can pass custom form data.

{{< php >}}
$url = new moodle_url("$CFG->wwwroot/my/index.php", $params);
$button = $OUTPUT->single_button($url, $editstring);
$PAGE->set_button($resetbutton . $button);
{{< / php >}}

<iframe src="../../../../examples/singlebuttons.php" style="overflow:hidden;height:50px;width:100%;border:0" title="Single button examples"></iframe>

### Button links

Links can be style to look like buttons, the action for this button is to simply navigate to some other page
Expand Down
26 changes: 18 additions & 8 deletions admin/tool/componentlibrary/content/moodle/javascript/confirm.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ to the element that will trigger the confirmation modal.

## Source files

* `lib/amd/src/confirm.js` ({{< jsdoc module="core/confirm" >}})
* `lib/amd/src/utility.js` ({{< jsdoc module="core/utility" >}})
* `lib/templates/modal.mustache`

## Usage
Expand Down Expand Up @@ -82,23 +82,33 @@ echo $OUTPUT->single_button('#', get_string('delete'), 'get', [

### Basic confirmation modal

#### Simple Modal

{{< example >}}
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["delete", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["delete", "core"]'>Show confirmation modal</button>
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["ok", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["ok", "core"]'>Show confirmation modal</button>
{{< /example >}}

#### Delete Modal

{{< example >}}
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-type="delete" data-confirmation-title-str='["delete", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["delete", "core"]'>Show delete modal</button>
{{< /example >}}


### Confirmation modal with a toast

{{< example >}}
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["delete", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["delete", "core"]' data-confirmation-toast="true"
data-confirmation-toast-confirmation-str='["deleteblockinprogress", "block", "Online users"]'>Show confirmation modal</button>
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["save", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["save", "core"]' data-confirmation-toast="true"
data-confirmation-toast-confirmation-str='["saved", "core_question", "My question"]'>Show confirmation modal</button>
{{< /example >}}

### Confirmation modal with redirect

{{< example >}}
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["delete", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["delete", "core"]'
<button type="button" class="btn btn-primary" data-confirmation="modal" data-confirmation-title-str='["save", "core"]'
data-confirmation-question-str='["areyousure"]' data-confirmation-yes-button-str='["save", "core"]'
data-confirmation-destination="http://moodle.com">Show confirmation modal</button>
{{< /example >}}
59 changes: 59 additions & 0 deletions admin/tool/componentlibrary/examples/singlebuttons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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/>.

/**
* Moodle Component Library
*
* A sample of different singlebuttons
*
* @package tool_componentlibrary
* @copyright 2022 Laurent David <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../../../config.php');
require_once($CFG->dirroot . '/lib/formslib.php');

require_login();
require_capability('moodle/site:configview', context_system::instance());

$repeatcount = optional_param('test_repeat', 1, PARAM_INT);

$PAGE->set_pagelayout('embedded');

$url = new moodle_url('/admin/tool/componentlibrary/examples/singlebuttons.php');
$PAGE->set_url($url);
$PAGE->set_context(context_system::instance());

$PAGE->set_heading('Moodle single buttons');
$PAGE->set_title('Moodle single buttons');

$buttondefinitions = [
['label' => 'Standard'],
['label' => 'Primary', 'type' => single_button::BUTTON_PRIMARY],
['label' => 'Danger', 'type' => single_button::BUTTON_DANGER],
['label' => 'Warning', 'type' => single_button::BUTTON_WARNING],
['label' => 'Success', 'type' => single_button::BUTTON_SUCCESS],
['label' => 'Info', 'type' => single_button::BUTTON_INFO],

];
echo $OUTPUT->header();
foreach ($buttondefinitions as $def) {
$button = new single_button($url, $def['label'], 'post', $def['type'] ??
single_button::BUTTON_SECONDARY, $def['attributes'] ?? []);
echo $OUTPUT->render($button);
}
echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion admin/webservice/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
echo $OUTPUT->heading(get_string('managetokens', 'core_webservice'));

echo html_writer::div($OUTPUT->render(new single_button(new moodle_url($PAGE->url, ['action' => 'create']),
get_string('createtoken', 'core_webservice'), 'get', true)), 'my-3');
get_string('createtoken', 'core_webservice'), 'get', single_button::BUTTON_PRIMARY)), 'my-3');

$filter->display();

Expand Down
5 changes: 4 additions & 1 deletion analytics/classes/bulk_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct($actionname, \moodle_url $actionurl, \pix_icon $icon
$this->url = new \moodle_url('/report/insights/action.php', $params);

$label = $OUTPUT->render($icon) . $this->text;
$this->actionlink = new \single_button($this->url, $label, 'get', $primary, $attributes);
$this->actionlink = new \single_button($this->url, $label,
'get',
$primary ? \single_button::BUTTON_PRIMARY : \single_button::BUTTON_SECONDARY,
$attributes);
}
}
2 changes: 1 addition & 1 deletion backup/util/ui/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function continue_button($url, $method = 'post') {
if ($method != 'post') {
$method = 'get';
}
$button = new single_button($url, get_string('continue'), $method, true);
$button = new single_button($url, get_string('continue'), $method, single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';
return $this->render($button);
}
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/recipients_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function export_for_template(renderer_base $output): array {
if ($this->badge->has_manual_award_criteria()
&& has_capability('moodle/badges:awardbadge', $this->page->context) && $this->badge->is_active()) {
$url = new moodle_url('/badges/award.php', ['id' => $this->badge->id]);
$button = new single_button($url, get_string('award', 'badges'), 'post', true);
$button = new single_button($url, get_string('award', 'badges'), 'post', single_button::BUTTON_PRIMARY);
$elements['awardbutton'] = $button->export_for_template($output);
}
$thirdpartynav = $this->get_third_party_nav_action($output);
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/standard_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function export_for_template(renderer_base $output): array {

if ($this->showaddbadge && has_capability('moodle/badges:createbadge', $this->page->context)) {
$buttons[] = new single_button(new moodle_url('/badges/newbadge.php', $params),
get_string('newbadge', 'core_badges'), 'post', true);
get_string('newbadge', 'core_badges'), 'post', single_button::BUTTON_PRIMARY);
}

foreach ($buttons as $key => $button) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/accessreview/block_accessreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function get_content() {

$button = new single_button(
new moodle_url(accessibility::get_plugin_url(), ['action' => 'requestanalysis', 'courseid' => $COURSE->id]),
get_string('schedule:requestanalysis', manager::PLUGINNAME), 'post', true,
get_string('schedule:requestanalysis', manager::PLUGINNAME), 'post', single_button::BUTTON_PRIMARY,
['class' => 'block_accessreview_analysisbutton']);
$this->content->text .= html_writer::tag('div', $OUTPUT->render($button),
['class' => 'block_accessreview_analysisbutton']);
Expand Down
6 changes: 3 additions & 3 deletions blocks/myoverview/classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/request.php', ['category' => $category->id]),
get_string('requestcourse'),
'post',
true
\single_button::BUTTON_PRIMARY
);
return $this->generate_zero_state_data($nocoursesimg, [$button], 'request');
}
Expand All @@ -523,7 +523,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/edit.php', ['category' => $category->id]),
get_string('createcourse', 'block_myoverview'),
'post',
true
\single_button::BUTTON_PRIMARY
);
$buttons[] = $createbutton->export_for_template($output);
return $this->generate_zero_state_data($nocoursesimg, $buttons, 'nocourses');
Expand All @@ -534,7 +534,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/edit.php', ['category' => $categorytocreate->id]),
get_string('createcourse', 'block_myoverview'),
'post',
true
\single_button::BUTTON_PRIMARY
);
$buttons = [$createbutton->export_for_template($output)];
if ($categorytomanage = \core_course_category::get_nearest_editable_subcategory($coursecat, ['manage'])) {
Expand Down
4 changes: 2 additions & 2 deletions calendar/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ public function course_filter_selector(moodle_url $returnurl, $label = null, $co
*/
public function render_subscriptions_header(): string {
$importcalendarbutton = new single_button(new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()),
get_string('importcalendar', 'calendar'), 'get', true);
get_string('importcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY);
$importcalendarbutton->class .= ' float-sm-right float-right';
$exportcalendarbutton = new single_button(new moodle_url('/calendar/export.php', calendar_get_export_import_link_params()),
get_string('exportcalendar', 'calendar'), 'get', true);
get_string('exportcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY);
$exportcalendarbutton->class .= ' float-sm-right float-right';
$output = $this->output->heading(get_string('managesubscriptions', 'calendar'));
$output .= html_writer::start_div('header d-flex flex-wrap mt-5');
Expand Down
2 changes: 1 addition & 1 deletion enrol/manual/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {

$button = new enrol_user_button($link, get_string('enrolusers', 'enrol_manual'), 'get');
$button->class .= ' enrol_manual_plugin';
$button->primary = true;
$button->type = single_button::BUTTON_PRIMARY;

$context = context_course::instance($instance->courseid);
$arguments = array('contextid' => $context->id);
Expand Down
2 changes: 1 addition & 1 deletion enrol/otherusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
// Check we have a search button to render.
$searchbuttonrender = null;
if ($searchbutton = $table->get_user_search_button()) {
$searchbutton->primary = true;
$searchbutton->type = single_button::BUTTON_PRIMARY;
$searchbuttonrender = $OUTPUT->render($searchbutton);
}

Expand Down
15 changes: 9 additions & 6 deletions enrol/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class core_enrol_renderer extends plugin_renderer_base {
* @return string XHTML
*/
protected function render_enrol_user_button(enrol_user_button $button) {
$attributes = array('type' => 'submit',
'value' => $button->label,
'disabled' => $button->disabled ? 'disabled' : null,
'title' => $button->tooltip,
'class' => 'btn ' . ($button->primary ? 'btn-primary' : 'btn-secondary'));

$buttoninfo = $button->export_for_template($this->output);

$attributes = [
'type' => 'submit',
'value' => $buttoninfo->label,
'disabled' => $buttoninfo->disabled ? 'disabled' : null,
'title' => $buttoninfo->tooltip,
'class' => 'btn ' . "btn-{$buttoninfo->type}",
];
if ($button->actions) {
$id = html_writer::random_id('single_button');
$attributes['id'] = $id;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/course_outcomes_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'manage outcomes' page.
$manageoutcomeslink = new moodle_url('/grade/edit/outcome/index.php', ['id' => $courseid]);
$manageoutcomesbutton = new \single_button($manageoutcomeslink, get_string('manageoutcomes', 'grades'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['manageoutcomesbutton'] = $manageoutcomesbutton->export_for_template($output);
}

Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/export_key_manager_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add user key' page.
$adduserkeylink = new moodle_url('/grade/export/key.php', ['courseid' => $courseid]);
$adduserkeybutton = new \single_button($adduserkeylink, get_string('adduserkey', 'userkey'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['adduserkeybutton'] = $adduserkeybutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/grade_letters_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function export_for_template(\renderer_base $output): array {
}
// Add a button to the action bar with a link to the 'edit grade letters' page.
$editbuttonlink = new moodle_url('/grade/edit/letter/index.php', ['id' => $this->context->id, 'edit' => 1]);
$editbutton = new \single_button($editbuttonlink, get_string('edit'), 'get', true);
$editbutton = new \single_button($editbuttonlink, get_string('edit'), 'get', \single_button::BUTTON_PRIMARY);
$data['editbutton'] = $editbutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/import_key_manager_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add user key' page.
$adduserkeylink = new moodle_url('/grade/import/key.php', ['courseid' => $courseid]);
$adduserkeybutton = new \single_button($adduserkeylink, get_string('adduserkey', 'userkey'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['adduserkeybutton'] = $adduserkeybutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/manage_outcomes_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add new outcome' page.
$addoutcomelink = new moodle_url('/grade/edit/outcome/edit.php', ['courseid' => $courseid]);
$addoutcomebutton = new \single_button($addoutcomelink, get_string('outcomecreate', 'grades'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['addoutcomebutton'] = $addoutcomebutton->export_for_template($output);

if ($this->hasoutcomes) {
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/scales_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add new scale' page.
$addnewscalelink = new moodle_url('/grade/edit/scale/edit.php', ['courseid' => $courseid]);
$addnewscalebutton = new \single_button($addnewscalelink, get_string('scalescustomcreate'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['addnewscalebutton'] = $addnewscalebutton->export_for_template($output);

return $data;
Expand Down
Loading

0 comments on commit ae53d04

Please sign in to comment.