MDL-70871 user: Move 'Show all X' functionality to dynamic_table
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -109,23 +109,19 @@ export const init = ({
|
||||
});
|
||||
|
||||
root.addEventListener('click', e => {
|
||||
// Handle clicking of the "Show [all|count]" and "Select all" actions.
|
||||
const showCountLink = root.querySelector(Selectors.showCountToggle);
|
||||
// Handle clicking of the "Select all" actions.
|
||||
const checkCountButton = root.querySelector(Selectors.checkCountButton);
|
||||
|
||||
const showCountLinkClicked = showCountLink && showCountLink.contains(e.target);
|
||||
const checkCountButtonClicked = checkCountButton && checkCountButton.contains(e.target);
|
||||
|
||||
if (showCountLinkClicked || checkCountButtonClicked) {
|
||||
if (checkCountButtonClicked) {
|
||||
e.preventDefault();
|
||||
|
||||
const tableRoot = getTableFromUniqueId(uniqueid);
|
||||
|
||||
DynamicTable.setPageSize(tableRoot, showCountLink.dataset.targetPageSize)
|
||||
DynamicTable.setPageSize(tableRoot, checkCountButton.dataset.targetPageSize)
|
||||
.then(tableRoot => {
|
||||
// Always update the toggle state.
|
||||
// This ensures that the bulk actions are disabled after changing the page size.
|
||||
CheckboxToggleAll.setGroupState(root, 'participants-table', checkCountButtonClicked);
|
||||
// Update the toggle state.
|
||||
CheckboxToggleAll.setGroupState(root, 'participants-table', true);
|
||||
|
||||
return tableRoot;
|
||||
})
|
||||
@@ -135,12 +131,11 @@ export const init = ({
|
||||
|
||||
// When the content is refreshed, update the row counts in various places.
|
||||
root.addEventListener(DynamicTable.Events.tableContentRefreshed, e => {
|
||||
const showCountLink = root.querySelector(Selectors.showCountToggle);
|
||||
const checkCountButton = root.querySelector(Selectors.checkCountButton);
|
||||
|
||||
const tableRoot = e.target;
|
||||
|
||||
const defaultPageSize = parseInt(root.dataset.tableDefaultPerPage, 10);
|
||||
const defaultPageSize = parseInt(tableRoot.dataset.tableDefaultPerPage, 10);
|
||||
const currentPageSize = parseInt(tableRoot.dataset.tablePageSize, 10);
|
||||
const totalRowCount = parseInt(tableRoot.dataset.tableTotalRows, 10);
|
||||
|
||||
@@ -154,67 +149,39 @@ export const init = ({
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
if (totalRowCount <= defaultPageSize) {
|
||||
// There are fewer than the default page count numbers of rows.
|
||||
showCountLink.classList.add('hidden');
|
||||
|
||||
if (checkCountButton) {
|
||||
checkCountButton.classList.add('hidden');
|
||||
}
|
||||
} else if (totalRowCount <= currentPageSize) {
|
||||
// The are fewer than the current page size.
|
||||
pageCountStrings.push({
|
||||
key: 'showperpage',
|
||||
component: 'core',
|
||||
param: defaultPageSize,
|
||||
});
|
||||
|
||||
pageCountStrings.push({
|
||||
key: 'selectalluserswithcount',
|
||||
component: 'core',
|
||||
param: defaultPageSize,
|
||||
});
|
||||
|
||||
// Show the 'Show [x]' link.
|
||||
showCountLink.classList.remove('hidden');
|
||||
showCountLink.dataset.targetPageSize = defaultPageSize;
|
||||
|
||||
if (checkCountButton) {
|
||||
// The 'Check all [x]' button is only visible when there are values to set.
|
||||
checkCountButton.classList.add('hidden');
|
||||
}
|
||||
} else {
|
||||
pageCountStrings.push({
|
||||
key: 'showall',
|
||||
component: 'core',
|
||||
param: totalRowCount,
|
||||
});
|
||||
|
||||
pageCountStrings.push({
|
||||
key: 'selectalluserswithcount',
|
||||
component: 'core',
|
||||
param: totalRowCount,
|
||||
});
|
||||
|
||||
// Show both the 'Show [x]' link, and the 'Check all [x]' button.
|
||||
showCountLink.classList.remove('hidden');
|
||||
showCountLink.dataset.targetPageSize = totalRowCount;
|
||||
|
||||
if (checkCountButton) {
|
||||
checkCountButton.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
Str.get_strings(pageCountStrings)
|
||||
.then(([showingParticipantCountString, showCountString, selectCountString]) => {
|
||||
.then(([showingParticipantCountString, selectCountString]) => {
|
||||
const showingParticipantCount = root.querySelector(Selectors.showCountText);
|
||||
showingParticipantCount.innerHTML = showingParticipantCountString;
|
||||
|
||||
if (showCountString) {
|
||||
showCountLink.innerHTML = showCountString;
|
||||
}
|
||||
|
||||
if (selectCountString && checkCountButton) {
|
||||
checkCountButton.value = selectCountString;
|
||||
}
|
||||
|
||||
@@ -195,6 +195,8 @@ class participants extends \table_sql implements dynamic_table {
|
||||
$this->no_sorting('groups');
|
||||
}
|
||||
|
||||
$this->set_default_per_page(20);
|
||||
|
||||
$this->set_attribute('id', 'participants');
|
||||
|
||||
$this->countries = get_string_manager()->get_list_of_countries(true);
|
||||
|
||||
+1
-37
@@ -35,7 +35,6 @@ use core_table\local\filter\integer_filter;
|
||||
use core_table\local\filter\string_filter;
|
||||
|
||||
define('DEFAULT_PAGE_SIZE', 20);
|
||||
define('SHOW_ALL_PAGE_SIZE', 5000);
|
||||
|
||||
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
|
||||
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
|
||||
@@ -189,7 +188,6 @@ echo html_writer::start_tag('form', [
|
||||
'id' => 'participantsform',
|
||||
'data-course-id' => $course->id,
|
||||
'data-table-unique-id' => $participanttable->uniqueid,
|
||||
'data-table-default-per-page' => ($perpage < DEFAULT_PAGE_SIZE) ? $perpage : DEFAULT_PAGE_SIZE,
|
||||
]);
|
||||
echo '<div>';
|
||||
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
|
||||
@@ -205,40 +203,6 @@ echo html_writer::tag(
|
||||
|
||||
echo $participanttablehtml;
|
||||
|
||||
$perpageurl = new moodle_url('/user/index.php', [
|
||||
'contextid' => $context->id,
|
||||
'id' => $course->id,
|
||||
]);
|
||||
$perpagesize = DEFAULT_PAGE_SIZE;
|
||||
$perpagevisible = false;
|
||||
$perpagestring = '';
|
||||
|
||||
if ($perpage == SHOW_ALL_PAGE_SIZE && $participanttable->totalrows > DEFAULT_PAGE_SIZE) {
|
||||
$perpageurl->param('perpage', $participanttable->totalrows);
|
||||
$perpagesize = SHOW_ALL_PAGE_SIZE;
|
||||
$perpagevisible = true;
|
||||
$perpagestring = get_string('showperpage', '', DEFAULT_PAGE_SIZE);
|
||||
} else if ($participanttable->get_page_size() < $participanttable->totalrows) {
|
||||
$perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
|
||||
$perpagesize = SHOW_ALL_PAGE_SIZE;
|
||||
$perpagevisible = true;
|
||||
$perpagestring = get_string('showall', '', $participanttable->totalrows);
|
||||
}
|
||||
|
||||
$perpageclasses = '';
|
||||
if (!$perpagevisible) {
|
||||
$perpageclasses = 'hidden';
|
||||
}
|
||||
echo $OUTPUT->container(html_writer::link(
|
||||
$perpageurl,
|
||||
$perpagestring,
|
||||
[
|
||||
'data-action' => 'showcount',
|
||||
'data-target-page-size' => $perpagesize,
|
||||
'class' => $perpageclasses,
|
||||
]
|
||||
), [], 'showall');
|
||||
|
||||
$bulkoptions = (object) [
|
||||
'uniqueid' => $participanttable->uniqueid,
|
||||
];
|
||||
@@ -256,7 +220,7 @@ if ($bulkoperations) {
|
||||
'id' => 'checkall',
|
||||
'class' => 'btn btn-secondary',
|
||||
'value' => $label,
|
||||
'data-target-page-size' => $participanttable->totalrows,
|
||||
'data-target-page-size' => TABLE_SHOW_ALL_PAGE_SIZE,
|
||||
]);
|
||||
}
|
||||
echo html_writer::end_tag('div');
|
||||
|
||||
Reference in New Issue
Block a user