MDL-65933 mod_data: Use new core/checkbox_toggleall
authorJun Pataleta <jun@moodle.com>
Thu, 21 Dec 2017 01:23:01 +0000 (14:23 +1300)
committerJun Pataleta <jun@moodle.com>
Fri, 2 Aug 2019 08:30:39 +0000 (16:30 +0800)
mod/data/lib.php
mod/data/module.js [deleted file]
mod/data/view.php

index 9b3d93d..4da9e62 100644 (file)
@@ -1448,7 +1448,13 @@ function data_print_template($template, $records, $data, $search='', $page=0, $r
 
         $patterns[]='##delcheck##';
         if ($canmanageentries) {
-            $replacement[] = html_writer::checkbox('delcheck[]', $record->id, false, '', array('class' => 'recordcheckbox'));
+            $checkbox = new \core\output\checkbox_toggleall('listview-entries', false, [
+                'id' => "entry_{$record->id}",
+                'name' => 'delcheck[]',
+                'class' => 'recordcheckbox',
+                'value' => $record->id,
+            ]);
+            $replacement[] = $OUTPUT->render($checkbox);
         } else {
             $replacement[] = '';
         }
diff --git a/mod/data/module.js b/mod/data/module.js
deleted file mode 100644 (file)
index 12c981c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-M.mod_data = {};
-
-M.mod_data.init_view = function(Y) {
-    Y.on('click', function(e) {
-        Y.all('input.recordcheckbox').each(function() {
-            this.set('checked', 'checked');
-        });
-    }, '#checkall');
-
-    Y.on('click', function(e) {
-        Y.all('input.recordcheckbox').each(function() {
-            this.set('checked', '');
-        });
-    }, '#checknone');
-};
\ No newline at end of file
index 9657445..0812fb8 100644 (file)
@@ -508,27 +508,28 @@ if ($showactivity) {
             }
 
             if ($mode != 'single' && $canmanageentries) {
-                echo html_writer::empty_tag('input', array(
-                        'type' => 'button',
-                        'id' => 'checkall',
-                        'value' => get_string('selectall'),
-                        'class' => 'btn btn-secondary mr-1'
-                    ));
-                echo html_writer::empty_tag('input', array(
-                        'type' => 'button',
-                        'id' => 'checknone',
-                        'value' => get_string('deselectall'),
-                        'class' => 'btn btn-secondary mr-1'
-                    ));
-                echo html_writer::empty_tag('input', array(
-                        'class' => 'form-submit',
-                        'type' => 'submit',
-                        'value' => get_string('deleteselected'),
-                        'class' => 'btn btn-secondary mr-1'
-                    ));
-
-                $module = array('name' => 'mod_data', 'fullpath' => '/mod/data/module.js');
-                $PAGE->requires->js_init_call('M.mod_data.init_view', null, false, $module);
+                // Build the select/deselect all control.
+                $selectallid = 'selectall-listview-entries';
+                $togglegroup = 'listview-entries';
+                $mastercheckbox = new \core\output\checkbox_toggleall($togglegroup, true, [
+                    'id' => $selectallid,
+                    'name' => $selectallid,
+                    'value' => 1,
+                    'label' => get_string('selectall'),
+                    'classes' => 'mr-1',
+                ], true);
+                echo $OUTPUT->render($mastercheckbox);
+
+                $deleteselected = html_writer::empty_tag('input', array(
+                    'class' => 'btn btn-secondary',
+                    'type' => 'submit',
+                    'value' => get_string('deleteselected'),
+                    'disabled' => true,
+                    'data-action' => 'toggle',
+                    'data-togglegroup' => $togglegroup,
+                    'data-toggle' => 'action',
+                ));
+                echo $deleteselected;
             }
 
             echo html_writer::end_tag('form');