From e274f1b29e07299a165a8e09e6f49d32d2297af7 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 21 Dec 2017 14:23:01 +1300 Subject: [PATCH] MDL-65933 mod_data: Use new core/checkbox_toggleall --- mod/data/lib.php | 8 +++++++- mod/data/module.js | 15 --------------- mod/data/view.php | 41 +++++++++++++++++++++-------------------- 3 files changed, 28 insertions(+), 36 deletions(-) delete mode 100644 mod/data/module.js diff --git a/mod/data/lib.php b/mod/data/lib.php index 9b3d93d8ff7..4da9e62aa4f 100644 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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 index 12c981c38a6..00000000000 --- a/mod/data/module.js +++ /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 diff --git a/mod/data/view.php b/mod/data/view.php index 96574453e1e..0812fb80233 100644 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -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' - )); + // 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); - $module = array('name' => 'mod_data', 'fullpath' => '/mod/data/module.js'); - $PAGE->requires->js_init_call('M.mod_data.init_view', null, false, $module); + $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');