MDL-68463 user: Show count link should always exist in DOM
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 19 May 2020 04:18:15 +0000 (12:18 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 19 May 2020 04:18:15 +0000 (12:18 +0800)
user/amd/build/participants.min.js
user/amd/build/participants.min.js.map
user/amd/src/participants.js
user/index.php

index 1d61489..b963d28 100644 (file)
Binary files a/user/amd/build/participants.min.js and b/user/amd/build/participants.min.js differ
index 97fd5a5..7a9ea4a 100644 (file)
Binary files a/user/amd/build/participants.min.js.map and b/user/amd/build/participants.min.js.map differ
index a5e2704..f9b62a6 100644 (file)
@@ -153,7 +153,10 @@ export const init = ({
             if (totalRowCount <= defaultPageSize) {
                 // There are fewer than the default page count numbers of rows.
                 showCountLink.classList.add('hidden');
-                checkCountButton.classList.add('hidden');
+
+                if (checkCountButton) {
+                    checkCountButton.classList.add('hidden');
+                }
             } else if (totalRowCount <= currentPageSize) {
                 // The are fewer than the current page size.
                 pageCountStrings.push({
@@ -172,8 +175,10 @@ export const init = ({
                 showCountLink.classList.remove('hidden');
                 showCountLink.dataset.targetPageSize = defaultPageSize;
 
-                // The 'Check all [x]' button is only visible when there are values to set.
-                checkCountButton.classList.add('hidden');
+                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',
@@ -190,7 +195,10 @@ export const init = ({
                 // Show both the 'Show [x]' link, and the 'Check all [x]' button.
                 showCountLink.classList.remove('hidden');
                 showCountLink.dataset.targetPageSize = totalRowCount;
-                checkCountButton.classList.remove('hidden');
+
+                if (checkCountButton) {
+                    checkCountButton.classList.remove('hidden');
+                }
             }
 
             Str.get_strings(pageCountStrings)
@@ -202,7 +210,7 @@ export const init = ({
                     showCountLink.innerHTML = showCountString;
                 }
 
-                if (selectCountString) {
+                if (selectCountString && checkCountButton) {
                     checkCountButton.value = selectCountString;
                 }
 
index 579a04c..2e9290f 100644 (file)
@@ -310,29 +310,31 @@ echo $participanttablehtml;
 
 $perpageurl = clone($baseurl);
 $perpageurl->remove_params('perpage');
+$perpagesize = DEFAULT_PAGE_SIZE;
+$perpagevisible = false;
+
 if ($perpage == SHOW_ALL_PAGE_SIZE && $participanttable->totalrows > DEFAULT_PAGE_SIZE) {
     $perpageurl->param('perpage', DEFAULT_PAGE_SIZE);
-    echo $OUTPUT->container(html_writer::link(
-        $perpageurl,
-        get_string('showperpage', '', DEFAULT_PAGE_SIZE),
-        [
-            'data-action' => 'showcount',
-            'data-target-page-size' => DEFAULT_PAGE_SIZE,
-        ]
-    ), [], 'showall');
-
+    $perpagevisible = true;
 } else if ($participanttable->get_page_size() < $participanttable->totalrows) {
     $perpageurl->param('perpage', SHOW_ALL_PAGE_SIZE);
-    echo $OUTPUT->container(html_writer::link(
-        $perpageurl,
-        get_string('showall', '', $participanttable->totalrows),
-        [
-            'data-action' => 'showcount',
-            'data-target-page-size' => SHOW_ALL_PAGE_SIZE,
-        ]
-    ),
-    [], 'showall');
+    $pagesize = SHOW_ALL_PAGE_SIZE;
+    $perpagevisible = true;
+}
+
+$perpageclasses = '';
+if (!$perpagevisible) {
+    $perpageclasses = 'hidden';
 }
+echo $OUTPUT->container(html_writer::link(
+    $perpageurl,
+    get_string('showperpage', '', DEFAULT_PAGE_SIZE),
+    [
+        'data-action' => 'showcount',
+        'data-target-page-size' => $perpagesize,
+        'class' => $perpageclasses,
+    ]
+), [], 'showall');
 
 if ($bulkoperations) {
     echo '<br /><div class="buttons"><div class="form-inline">';