MDL-65946 mod_scorm: Use new core/checkbox-toggleall
This commit is contained in:
@@ -54,4 +54,60 @@ class report {
|
||||
public function canview($contextmodule) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a checkbox that can be added to header tables to select/deselect all quiz attempts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_master_checkbox(): string {
|
||||
global $OUTPUT;
|
||||
|
||||
// Build the select/deselect all control.
|
||||
$selectalltext = get_string('selectall', 'scorm');
|
||||
$deselectalltext = get_string('selectnone', 'scorm');
|
||||
$mastercheckbox = new \core\output\checkbox_toggleall('scorm-attempts', true, [
|
||||
'name' => 'scorm-selectall-attempts',
|
||||
'value' => 1,
|
||||
'label' => $selectalltext,
|
||||
'labelclasses' => 'accesshide',
|
||||
'selectall' => $selectalltext,
|
||||
'deselectall' => $deselectalltext,
|
||||
]);
|
||||
|
||||
return $OUTPUT->render($mastercheckbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a checkbox for a row in the attempts table.
|
||||
*
|
||||
* @param string $name The checkbox's name attribute.
|
||||
* @param string $value The checkbox's value.
|
||||
* @return string
|
||||
*/
|
||||
protected function generate_row_checkbox(string $name, string $value): string {
|
||||
global $OUTPUT;
|
||||
|
||||
$checkbox = new \core\output\checkbox_toggleall('scorm-attempts', false, [
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
]);
|
||||
return $OUTPUT->render($checkbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an action button that deletes the selected attempts.
|
||||
*/
|
||||
protected function generate_delete_selected_button(): string {
|
||||
$deleteselectedparams = array(
|
||||
'type' => 'submit',
|
||||
'value' => get_string('deleteselected', 'scorm'),
|
||||
'class' => 'btn btn-secondary',
|
||||
'data-action' => 'toggle',
|
||||
'data-togglegroup' => 'scorm-attempts',
|
||||
'data-toggle' => 'action',
|
||||
'disabled' => true
|
||||
);
|
||||
return \html_writer::empty_tag('input', $deleteselectedparams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ class report extends \mod_scorm\report {
|
||||
$headers = array();
|
||||
if (!$download && $candelete) {
|
||||
$columns[] = 'checkbox';
|
||||
$headers[] = null;
|
||||
$headers[] = $this->generate_master_checkbox();
|
||||
}
|
||||
if (!$download && $CFG->grade_report_showuserimage) {
|
||||
$columns[] = 'picture';
|
||||
@@ -380,7 +380,7 @@ class report extends \mod_scorm\report {
|
||||
}
|
||||
if (in_array('checkbox', $columns)) {
|
||||
if ($candelete && !empty($timetracks->start)) {
|
||||
$row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false);
|
||||
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
|
||||
} else if ($candelete) {
|
||||
$row[] = '';
|
||||
}
|
||||
@@ -490,24 +490,7 @@ class report extends \mod_scorm\report {
|
||||
if ($candelete) {
|
||||
echo \html_writer::start_tag('table', array('id' => 'commands'));
|
||||
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
|
||||
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
|
||||
echo ' / ';
|
||||
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
|
||||
$PAGE->requires->js_amd_inline("
|
||||
require(['jquery'], function($) {
|
||||
$('#checkattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', true);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('#uncheckattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', false);
|
||||
e.preventDefault();
|
||||
});
|
||||
});");
|
||||
echo ' ';
|
||||
echo \html_writer::empty_tag('input', array('type' => 'submit',
|
||||
'value' => get_string('deleteselected', 'scorm'),
|
||||
'class' => 'btn btn-secondary'));
|
||||
echo $this->generate_delete_selected_button();
|
||||
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
|
||||
// Close form.
|
||||
echo \html_writer::end_tag('div');
|
||||
|
||||
@@ -133,7 +133,7 @@ class report extends \mod_scorm\report {
|
||||
$headers = array();
|
||||
if (!$download && $candelete) {
|
||||
$columns[] = 'checkbox';
|
||||
$headers[] = null;
|
||||
$headers[] = $this->generate_master_checkbox();
|
||||
}
|
||||
if (!$download && $CFG->grade_report_showuserimage) {
|
||||
$columns[] = 'picture';
|
||||
@@ -426,7 +426,7 @@ class report extends \mod_scorm\report {
|
||||
}
|
||||
if (in_array('checkbox', $columns)) {
|
||||
if ($candelete && !empty($timetracks->start)) {
|
||||
$row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false);
|
||||
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
|
||||
} else if ($candelete) {
|
||||
$row[] = '';
|
||||
}
|
||||
@@ -581,24 +581,7 @@ class report extends \mod_scorm\report {
|
||||
if ($candelete) {
|
||||
echo \html_writer::start_tag('table', array('id' => 'commands'));
|
||||
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
|
||||
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
|
||||
echo ' / ';
|
||||
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
|
||||
$PAGE->requires->js_amd_inline("
|
||||
require(['jquery'], function($) {
|
||||
$('#checkattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', true);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('#uncheckattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', false);
|
||||
e.preventDefault();
|
||||
});
|
||||
});");
|
||||
echo ' ';
|
||||
echo \html_writer::empty_tag('input', array('type' => 'submit',
|
||||
'value' => get_string('deleteselected', 'scorm'),
|
||||
'class' => 'btn btn-secondary'));
|
||||
echo $this->generate_delete_selected_button();
|
||||
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
|
||||
// Close form.
|
||||
echo \html_writer::end_tag('div');
|
||||
|
||||
@@ -127,7 +127,7 @@ class report extends \mod_scorm\report {
|
||||
$headers = array();
|
||||
if (!$download && $candelete) {
|
||||
$columns[] = 'checkbox';
|
||||
$headers[] = null;
|
||||
$headers[] = $this->generate_master_checkbox();
|
||||
}
|
||||
if (!$download && $CFG->grade_report_showuserimage) {
|
||||
$columns[] = 'picture';
|
||||
@@ -416,7 +416,7 @@ class report extends \mod_scorm\report {
|
||||
}
|
||||
if (in_array('checkbox', $columns)) {
|
||||
if ($candelete && !empty($timetracks->start)) {
|
||||
$row[] = \html_writer::checkbox('attemptid[]', $scouser->userid . ':' . $scouser->attempt, false);
|
||||
$row[] = $this->generate_row_checkbox('attemptid[]', "{$scouser->userid}:{$scouser->attempt}");
|
||||
} else if ($candelete) {
|
||||
$row[] = '';
|
||||
}
|
||||
@@ -580,24 +580,7 @@ class report extends \mod_scorm\report {
|
||||
if ($candelete) {
|
||||
echo \html_writer::start_tag('table', array('id' => 'commands'));
|
||||
echo \html_writer::start_tag('tr').\html_writer::start_tag('td');
|
||||
echo \html_writer::link('#', get_string('selectall', 'scorm'), array('id' => 'checkattempts'));
|
||||
echo ' / ';
|
||||
echo \html_writer::link('#', get_string('selectnone', 'scorm'), array('id' => 'uncheckattempts'));
|
||||
$PAGE->requires->js_amd_inline("
|
||||
require(['jquery'], function($) {
|
||||
$('#checkattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', true);
|
||||
e.preventDefault();
|
||||
});
|
||||
$('#uncheckattempts').click(function(e) {
|
||||
$('#attemptsform').find('input:checkbox').prop('checked', false);
|
||||
e.preventDefault();
|
||||
});
|
||||
});");
|
||||
echo ' ';
|
||||
echo \html_writer::empty_tag('input', array('type' => 'submit',
|
||||
'value' => get_string('deleteselected', 'scorm'),
|
||||
'class' => 'btn btn-secondary'));
|
||||
echo $this->generate_delete_selected_button();
|
||||
echo \html_writer::end_tag('td').\html_writer::end_tag('tr').\html_writer::end_tag('table');
|
||||
// Close form.
|
||||
echo \html_writer::end_tag('div');
|
||||
|
||||
Reference in New Issue
Block a user