From b91fc7c027bb111ee7ef7d15c0c2304a18ec5792 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Tue, 8 Mar 2016 16:46:10 +0000 Subject: [PATCH 1/3] CONTRIB-6184 mod_checklist: Allow multiple items to be shown/hidden --- lang/en/checklist.php | 1 + locallib.php | 73 ++++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/lang/en/checklist.php b/lang/en/checklist.php index a7e2f7d1..a6cd967c 100644 --- a/lang/en/checklist.php +++ b/lang/en/checklist.php @@ -164,6 +164,7 @@ $string['showcompletemymoodle'] = 'Show completed Checklists on \'My Moodle\' page'; $string['showfulldetails'] = 'Show full details'; +$string['showhidechecked'] = 'Show/hide selected items'; $string['showupdateablemymoodle'] = 'Show only updatable Checklists on \'My Moodle\' page'; $string['showmymoodle'] = 'Show Checklists on \'My Moodle\' page'; $string['showprogressbars'] = 'Show progress bars'; diff --git a/locallib.php b/locallib.php index 22f01826..f3453f94 100644 --- a/locallib.php +++ b/locallib.php @@ -1421,6 +1421,9 @@ protected function view_edit_items() { if ($this->editdates) { $thispage->param('editdates', 'on'); } + if ($itemid = optional_param('itemid', null, PARAM_INT)) { + $thispage->param('itemid', $itemid); + } if ($this->checklist->autoupdate && $this->checklist->autopopulate) { if ($this->checklist->teacheredit == CHECKLIST_MARKING_STUDENT) { @@ -1436,6 +1439,17 @@ protected function view_edit_items() { if ($this->items) { $lastitem = count($this->items); $lastindent = 0; + + echo html_writer::start_tag('form', array('action' => $thispage->out_omit_querystring(), 'method' => 'post')); + echo html_writer::input_hidden_params($thispage); + + if ($this->checklist->autopopulate) { + echo html_writer::empty_tag('input', array( + 'type' => 'submit', 'name' => 'showhideitems', + 'value' => get_string('showhidechecked', 'checklist') + )); + } + foreach ($this->items as $item) { while ($item->indent > $currindent) { @@ -1481,6 +1495,13 @@ protected function view_edit_items() { $hasauto = $hasauto || ($item->moduleid != 0); echo '
  • '; + + echo html_writer::start_span('', array('style' => 'display: inline-block; width: 16px;')); + if ($autoitem && $item->hidden != CHECKLIST_HIDDEN_BYMODULE) { + echo html_writer::checkbox('items[' . $item->id . ']', $item->id, false); + } + echo html_writer::end_span(); + if ($item->itemoptional == CHECKLIST_OPTIONAL_YES) { $title = '"'.get_string('optionalitem', 'checklist').'"'; echo ''; @@ -1515,23 +1536,16 @@ protected function view_edit_items() { } if (isset($item->editme)) { - echo '
    '; echo ''; - echo ''; - echo html_writer::input_hidden_params($thispage); if ($this->editdates) { $this->print_edit_date($item->duetime); } echo ''; - echo '
    '; $focusitem = 'updateitembox'; - echo '
    '; - echo html_writer::input_hidden_params($thispage, array('sesskey', 'itemid')); echo ''; - echo '
    '; $addatend = false; @@ -1611,9 +1625,6 @@ protected function view_edit_items() { if ($this->additemafter == $item->id) { $addatend = false; echo '
  • '; - echo '
    '; - echo html_writer::input_hidden_params($thispage); - echo ''; echo ''; echo ''; echo ' '; @@ -1622,12 +1633,7 @@ protected function view_edit_items() { $this->print_edit_date(); } echo ''; - echo '
    '; - - echo '
    '; - echo html_writer::input_hidden_params($thispage, array('sesskey', 'additemafter')); echo ''; - echo '
    '; echo '
  • '; if (!$focusitem) { @@ -1639,6 +1645,8 @@ protected function view_edit_items() { echo ''; } + + echo html_writer::end_tag('form'); } $thispage->remove_params(array('itemid')); @@ -2189,9 +2197,7 @@ protected function process_view_actions() { return; } - if (!confirm_sesskey()) { - error('Invalid sesskey'); - } + require_sesskey(); $itemid = optional_param('itemid', 0, PARAM_INT); @@ -2237,7 +2243,7 @@ protected function process_view_actions() { break; default: - error('Invalid action - "'.s($action).'"'); + throw new moodle_exception('invalidaction', 'mod_checklist', '', $action); } if ($action != 'updatechecks') { @@ -2254,22 +2260,29 @@ protected function process_edit_actions() { if ($removeauto) { // Remove any automatically generated items from the list // (if no longer using automatic items). - if (!confirm_sesskey()) { - error('Invalid sesskey'); - } + require_sesskey(); $this->removeauto(); return; } $action = optional_param('action', false, PARAM_TEXT); + if (!$action) { + if (optional_param('additem', false, PARAM_BOOL)) { + $action = 'additem'; + } else if (optional_param('updateitem', false, PARAM_BOOL)) { + $action = 'updateitem'; + } else if (optional_param('showhideitems', false, PARAM_BOOL)) { + $action = 'showhideitems'; + } else if (optional_param('canceledititem', false, PARAM_BOOL)) { + $additemafter = false; + } + } if (!$action) { $this->additemafter = $additemafter; return; } - if (!confirm_sesskey()) { - error('Invalid sesskey'); - } + require_sesskey(); $itemid = optional_param('itemid', 0, PARAM_INT); @@ -2344,8 +2357,16 @@ protected function process_edit_actions() { case 'nextcolour': $this->nextcolour($itemid); break; + + case 'showhideitems': + $itemids = optional_param_array('items', array(), PARAM_INT); + foreach ($itemids as $itemid) { + $this->toggledisableitem($itemid); + } + break; + default: - error('Invalid action - "'.s($action).'"'); + throw new moodle_exception('invalidaction', 'mod_checklist', '', $action); } if ($additemafter) { From d05679d6bc51be002c026580436e49403a84493d Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Mon, 14 Mar 2016 14:11:32 +0000 Subject: [PATCH 2/3] CONTRIB-6184 mod_checklist: Behat test for bulk auto-pop display toggle --- locallib.php | 3 +- tests/behat/show_hide_multiple_items.feature | 56 ++++++++++++++++++++ tests/generator/lib.php | 2 + 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/behat/show_hide_multiple_items.feature diff --git a/locallib.php b/locallib.php index f3453f94..4d0790d4 100644 --- a/locallib.php +++ b/locallib.php @@ -1498,7 +1498,8 @@ protected function view_edit_items() { echo html_writer::start_span('', array('style' => 'display: inline-block; width: 16px;')); if ($autoitem && $item->hidden != CHECKLIST_HIDDEN_BYMODULE) { - echo html_writer::checkbox('items[' . $item->id . ']', $item->id, false); + echo html_writer::checkbox('items[' . $item->id . ']', $item->id, false, '', + array('title' => $item->displaytext)); } echo html_writer::end_span(); diff --git a/tests/behat/show_hide_multiple_items.feature b/tests/behat/show_hide_multiple_items.feature new file mode 100644 index 00000000..0aa0519e --- /dev/null +++ b/tests/behat/show_hide_multiple_items.feature @@ -0,0 +1,56 @@ +@mod @mod_checklist @checklist +Feature: Multiple autopopulate items can be shown/hidden at once + + Background: + Given the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | course | section | idnumber | name | intro | + | assign | C1 | 1 | assign1 | Test assignment | This is an assignment | + | data | C1 | 1 | data1 | Test database | This is a database | + | checklist | C1 | 1 | checklist1 | Test checklist | This is a checklist | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Checklist" to section "1" and I fill the form with: + | Checklist | Test auto-pop checklist | + | Introduction | This is an auto-populated checklist | + | Show course modules in checklist | Whole course | + And I log out + + Scenario: When viewing an auto-populated checklist, a student should see items corresponding to the course modules + When I log in as "student1" + And I follow "Course 1" + And I follow "Test auto-pop checklist" + Then I should see "Test auto-pop checklist" + And I should see "This is an auto-populated checklist" + And I should see "Test assignment" + And I should see "Test database" + + Scenario: When I select multiple items and click the 'Show/hide' button, the items' visibility should toggle + Given I log in as "teacher1" + And I follow "Course 1" + And I follow "Test auto-pop checklist" + And I follow "Edit checklist" + And I set the field with xpath "//input[@type='checkbox' and @title='Test assignment']" to "1" + And I set the field with xpath "//input[@type='checkbox' and @title='Test database']" to "1" + And I press "Show/hide selected items" + And I set the field with xpath "//input[@type='checkbox' and @title='Test database']" to "1" + And I set the field with xpath "//input[@type='checkbox' and @title='Test checklist']" to "1" + And I press "Show/hide selected items" + And I log out + When I log in as "student1" + And I follow "Course 1" + And I follow "Test auto-pop checklist" + Then I should not see "Test assignment" in the "#region-main" "css_element" + And I should see "Test database" in the "#region-main" "css_element" + And I should not see "Test checklist" in the "#region-main" "css_element" diff --git a/tests/generator/lib.php b/tests/generator/lib.php index e8b7f350..55af544a 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -23,6 +23,8 @@ */ defined('MOODLE_INTERNAL') || die(); +global $CFG; +require_once($CFG->dirroot.'/mod/checklist/lib.php'); class mod_checklist_generator extends testing_module_generator { public function create_instance($record = null, array $options = null) { From b7d8e81f52562e836c547415992a366b470bd292 Mon Sep 17 00:00:00 2001 From: Davo Smith Date: Mon, 14 Mar 2016 22:29:57 +0000 Subject: [PATCH 3/3] Bump version number --- version.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/version.php b/version.php index 3651f589..7e354c56 100644 --- a/version.php +++ b/version.php @@ -30,10 +30,10 @@ $plugin = new stdClass(); } // Used by M2.6 and above. -$plugin->version = 2015122300; // The current module version (Date: YYYYMMDDXX) +$plugin->version = 2016031400; // The current module version (Date: YYYYMMDDXX) $plugin->cron = 60; // Period for cron to check this module (secs). $plugin->maturity = MATURITY_STABLE; -$plugin->release = '2.x (Build: 2015122300)'; +$plugin->release = '2.x (Build: 2016031400)'; $plugin->requires = 2010112400; $plugin->component = 'mod_checklist'; @@ -45,4 +45,4 @@ $module->release = $plugin->release; $module->requires = $plugin->requires; $module->component = $plugin->component; -} \ No newline at end of file +}