Merge branch 'MDL-78288-master' of https://github.com/aanabit/moodle

This commit is contained in:
Sara Arjona
2023-07-13 16:49:56 +02:00
28 changed files with 394 additions and 76 deletions
@@ -44,7 +44,7 @@ Feature: Confirm that conditions on completion no longer cause a bug
And I click on "Activity completion" "button" in the "Add restriction..." "dialogue"
And I set the field with xpath "//div[contains(concat(' ', normalize-space(@class), ' '), ' availability-item ')][preceding-sibling::div]//select[@name='cm']" to "Page2"
And I press "Save and return to course"
And I click on "Show more" "button" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show more" "button" in the "TestGlossary" "core_availability > Activity availability"
Then I should see "Not available unless:" in the ".activity.glossary" "css_element"
And I should see "The activity Page1 is marked complete" in the ".activity.glossary" "css_element"
And I should see "The activity Page2 is marked complete" in the ".activity.glossary" "css_element"
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
/**
* Availability related behat steps and selectors definitions.
*
* @package core_availability
* @category test
* @copyright 2023 Amaia Anabitarte <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_availability extends \behat_base {
/**
* Return the list of partial named selectors.
*
* @return array
*/
public static function get_partial_named_selectors(): array {
return [
new \behat_component_named_selector(
'Activity availability', [<<<XPATH
.//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][descendant::*[contains(normalize-space(.), %locator%)]]
//div[@data-region='availabilityinfo']
XPATH
]
),
new \behat_component_named_selector(
'Section availability', [<<<XPATH
.//li[@id = %locator%]//div[@data-region='availabilityinfo']
XPATH
]
),
];
}
}
@@ -69,24 +69,24 @@ Feature: display_availability
And I press "Save and return to course"
# Page 1 should show in single-line format, showing the date
Then I should see "Available until" in the "#section-1 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-1 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-1 .availabilityinfo" "css_element"
And "li" "css_element" should not exist in the "#section-1 .availabilityinfo" "css_element"
And "Show more" "button" should not exist in the "#section-1 .availabilityinfo" "css_element"
Then I should see "Available until" in the "Page 1" "core_availability > Activity availability"
And I should see "2013" in the "Page 1" "core_availability > Activity availability"
And I should see "2013" in the "Page 1" "core_availability > Activity availability"
And "li" "css_element" should not exist in the "Page 1" "core_availability > Activity availability"
And "Show more" "button" should not exist in the "Page 1" "core_availability > Activity availability"
# Page 2 should show in list format.
And "li" "css_element" should exist in the "#section-2 .availabilityinfo" "css_element"
And I should see "Not available unless:" in the "#section-2 .availabilityinfo" "css_element"
And I should see "It is before" in the "#section-2 .availabilityinfo" "css_element"
And I should see "hidden otherwise" in the "#section-2 .availabilityinfo" "css_element"
And "li" "css_element" should exist in the "Page 2" "core_availability > Activity availability"
And I should see "Not available unless:" in the "Page 2" "core_availability > Activity availability"
And I should see "It is before" in the "Page 2" "core_availability > Activity availability"
And I should see "hidden otherwise" in the "Page 2" "core_availability > Activity availability"
And I click on "Show more" "button" in the "Page 2" "activity"
And I should see "Email address" in the "#section-2 .availabilityinfo" "css_element"
And I click on "Show less" "button" in the "#section-2 .availabilityinfo" "css_element"
And I should not see "Email address" in the "#section-2 .availabilityinfo" "css_element"
And I should see "Email address" in the "Page 2" "core_availability > Activity availability"
And I click on "Show less" "button" in the "Page 2" "core_availability > Activity availability"
And I should not see "Email address" in the "Page 2" "core_availability > Activity availability"
# Page 3 should not have available info.
And "#section-3 .availabilityinfo" "css_element" should not exist
And "Page 3" "core_availability > Activity availability" should not exist
# Change to student view.
Given I am on the "C1" "Course" page logged in as "student1"
@@ -139,9 +139,9 @@ Feature: display_availability
And I am on "Course 1" course homepage
# Check display
Then I should see "Not available unless" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Available until" in the "#section-2 .availabilityinfo" "css_element"
And I should see "hidden otherwise" in the "#section-2 .availabilityinfo" "css_element"
Then I should see "Not available unless" in the "section-1" "core_availability > Section availability"
And I should see "Available until" in the "section-2" "core_availability > Section availability"
And I should see "hidden otherwise" in the "section-2" "core_availability > Section availability"
# Change to student view.
Given I am on the "Course 1" "Course" page logged in as "student1"
@@ -153,11 +153,11 @@ Feature: display_availability
# Section 1 should be visible and show info.
And I should see "Topic 1" in the "region-main" "region"
And I should see "Not available unless" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show more" "button" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Email address" in the "#section-1 .availabilityinfo" "css_element"
And I click on "Show less" "button" in the "#section-1 .availabilityinfo" "css_element"
And I should not see "Email address" in the "#section-1 .availabilityinfo" "css_element"
And I should see "Not available unless" in the "section-1" "core_availability > Section availability"
And I click on "Show more" "button" in the "section-1" "core_availability > Section availability"
And I should see "Email address" in the "section-1" "core_availability > Section availability"
And I click on "Show less" "button" in the "section-1" "core_availability > Section availability"
And I should not see "Email address" in the "section-1" "core_availability > Section availability"
# Section 2 should not be available at all
And I should not see "Topic 2" in the "region-main" "region"
@@ -224,3 +224,43 @@ Feature: edit_availability
# And check it's still active if I delete the condition.
And I click on "Delete" "link" in the "Restrict access" "fieldset"
And the "Add group/grouping access restriction" "button" should be enabled
@javascript
Scenario: Edit section availability using course page link
# Setting a restriction up
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I edit the section "1"
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Date" "button" in the "Add restriction..." "dialogue"
And I press "Save changes"
# Testing edit settings link
And "Edit settings" "link" should exist in the "section-1" "core_availability > Section availability"
When I click on "Edit settings" "link" in the "section-1" "core_availability > Section availability"
Then I should see "Restrict access"
And I should not see "General"
And I should see "Collapse all"
And I should not see "Expand all"
And I click on "Cancel" "button"
And I am on "Course 1" course homepage with editing mode off
And I should not see "Edit settings"
@javascript
Scenario: Edit activity availability using course page link
# Setting a restriction up
Given I am on the "MyForum" "forum activity editing" page logged in as teacher1
And I expand all fieldsets
And I press "Add restriction..."
And I click on "Date" "button" in the "Add restriction..." "dialogue"
When I press "Save and return to course"
# Edit settings link not displayed when editing mode is off.
Then "Edit settings" "link" should not exist in the "MyForum" "core_availability > Activity availability"
# Testing edit settings link
But I am on "Course 1" course homepage with editing mode on
And "Edit settings" "link" should exist in the "MyForum" "core_availability > Activity availability"
And I click on "Edit settings" "link" in the "MyForum" "core_availability > Activity availability"
And I should see "Restrict access"
And I should not see "Content"
And I should see "Collapse all"
And I should not see "Expand all"
@@ -145,6 +145,10 @@ M.core_availability.form = {
}
this.updateRestrictByGroup();
}
// Everything is ready. Make sure the div is visible.
this.parent = Y.one('#fitem_id_availabilityconditionsjson');
this.parent.removeClass('d-none');
},
/**
File diff suppressed because one or more lines are too long
@@ -145,6 +145,10 @@ M.core_availability.form = {
}
this.updateRestrictByGroup();
}
// Everything is ready. Make sure the div is visible.
this.parent = Y.one('#fitem_id_availabilityconditionsjson');
this.parent.removeClass('d-none');
},
/**
+4
View File
@@ -143,6 +143,10 @@ M.core_availability.form = {
}
this.updateRestrictByGroup();
}
// Everything is ready. Make sure the div is visible.
this.parent = Y.one('#fitem_id_availabilityconditionsjson');
this.parent.removeClass('d-none');
},
/**
+14 -4
View File
@@ -30,8 +30,13 @@ require_once($CFG->libdir . '/formslib.php');
$id = required_param('id', PARAM_INT); // course_sections.id
$sectionreturn = optional_param('sr', 0, PARAM_INT);
$deletesection = optional_param('delete', 0, PARAM_BOOL);
$showonly = optional_param('showonly', 0, PARAM_TAGLIST);
$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));
$params = ['id' => $id, 'sr' => $sectionreturn];
if (!empty($showonly)) {
$params['showonly'] = $showonly;
}
$PAGE->set_url('/course/editsection.php', $params);
$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
@@ -96,11 +101,13 @@ $editoroptions = array(
$courseformat = course_get_format($course);
$defaultsectionname = $courseformat->get_default_section_name($section);
$customdata = array(
$customdata = [
'cs' => $sectioninfo,
'editoroptions' => $editoroptions,
'defaultsectionname' => $defaultsectionname
);
'defaultsectionname' => $defaultsectionname,
'showonly' => $showonly,
];
$mform = $courseformat->editsection_form($PAGE->url, $customdata);
// set current value, make an editable copy of section_info object
@@ -110,6 +117,9 @@ if (!empty($CFG->enableavailability)) {
$initialdata['availabilityconditionsjson'] = $sectioninfo->availability;
}
$mform->set_data($initialdata);
if (!empty($showonly)) {
$mform->filter_shown_headers(explode(',', $showonly));
}
if ($mform->is_cancelled()){
// Form cancelled, return to course.
+17 -12
View File
@@ -17,6 +17,7 @@ require_once($CFG->libdir.'/gradelib.php');
class editsection_form extends moodleform {
function definition() {
global $CFG;
$mform = $this->_form;
$course = $this->_customdata['course'];
@@ -47,26 +48,30 @@ class editsection_form extends moodleform {
$elements = $courseformat->create_edit_form_elements($mform, true);
}
$mform->_registerCancelButton('cancel');
}
public function definition_after_data() {
global $CFG, $DB;
$mform = $this->_form;
$course = $this->_customdata['course'];
$context = context_course::instance($course->id);
if (!empty($CFG->enableavailability)) {
$mform->addElement('header', 'availabilityconditions',
get_string('restrictaccess', 'availability'));
get_string('restrictaccess', 'availability'));
$mform->setExpanded('availabilityconditions', false);
// Availability field. This is just a textarea; the user interface
// interaction is all implemented in JavaScript. The field is named
// availabilityconditionsjson for consistency with moodleform_mod.
$mform->addElement('textarea', 'availabilityconditionsjson',
get_string('accessrestrictions', 'availability'));
get_string('accessrestrictions', 'availability'),
['class' => 'd-none']
);
}
$mform->_registerCancelButton('cancel');
}
public function definition_after_data() {
global $CFG;
$mform = $this->_form;
$course = $this->_customdata['course'];
if (!empty($CFG->enableavailability)) {
\core_availability\frontend::include_all_javascript($course, null,
$this->_customdata['cs']);
}
@@ -86,11 +86,16 @@ class availability extends section_avalability {
// Nothing to be displayed to the user.
return [];
}
if (!$this->mod->uservisible) {
return $this->user_availability_info($output);
return ['info' => $this->user_availability_info($output)];
}
return $this->conditional_availability_info($output);
$editurl = new \moodle_url(
'/course/modedit.php',
['update' => $this->mod->id, 'showonly' => 'availabilityconditionsheader']
);
return ['editurl' => $editurl->out(false), 'info' => $this->conditional_availability_info($output)];
}
/**
@@ -106,9 +106,7 @@ class availability implements named_templatable, renderable {
return;
}
$data = (object)[
'info' => $this->get_info($output),
];
$data = (object) $this->get_info($output);
$attributename = $this->hasavailabilityname;
$data->$attributename = !empty($data->info);
@@ -139,21 +137,25 @@ class availability implements named_templatable, renderable {
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context, $USER);
$info = [];
$editurl = new \moodle_url(
'/course/editsection.php',
['id' => $this->section->id, 'showonly' => 'availabilityconditions']
);
$info = ['editurl' => $editurl->out(false)];
if (!$section->visible) {
$info = [];
return [];
} else if (!$section->uservisible) {
if ($section->availableinfo) {
// Note: We only get to this function if availableinfo is non-empty,
// so there is definitely something to print.
$info[] = $this->get_availability_data($output, $section->availableinfo, 'isrestricted');
$info['info'] = $this->get_availability_data($output, $section->availableinfo, 'isrestricted');
}
} else if ($canviewhidden && !empty($CFG->enableavailability)) {
// Check if there is an availability restriction.
$ci = new info_section($section);
$fullinfo = $ci->get_full_information();
if ($fullinfo) {
$info[] = $this->get_availability_data($output, $fullinfo, 'isrestricted isfullinfo');
$info['info'] = $this->get_availability_data($output, $fullinfo, 'isrestricted isfullinfo');
}
}
@@ -22,7 +22,9 @@
Example context (json):
{
"text": "Not available unless: <ul><li>It is on or after <strong>8 June 2012</strong></li><li>You achieve higher than a certain score in <strong>Course total</strong></li></ul>",
"excerpt": "Not available unless: It is on or after <strong>8 June 2012</strong>"
"excerpt": "Not available unless: It is on or after <strong>8 June 2012</strong>",
"editing": true,
"editurl": "/course/editsection.php?id=81&showonly=availabilityconditions"
}
}}
{{^excerpt}}
@@ -41,3 +43,10 @@
{{$expandedextraclasses}}py-2{{/expandedextraclasses}}
{{/core/showmore }}
{{/excerpt}}
{{#editing}}
{{#editurl}}
<div class="editavailability border-top mt-2 py-2">
<a href="{{editurl}}" class="p-1">{{#pix}} i/edit, core {{/pix}}{{#str}}editsettings, availability{{/str}}</a>
</div>
{{/editurl}}
{{/editing}}
@@ -36,7 +36,7 @@
}}
{{#hasmodavailability}}
{{#info}}
<div class="activity-availability availabilityinfo small {{classes}}">
<div class="activity-availability availabilityinfo small {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-pill badge-warning">{{{text}}}</span>
{{/isrestricted}}
@@ -36,7 +36,7 @@
<div class="section_availability">
{{#hasavailability}}
{{#info}}
<div class="availabilityinfo {{classes}}">
<div class="availabilityinfo {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-pill badge-warning">{{{text}}}</span>
{{/isrestricted}}
+10
View File
@@ -37,12 +37,16 @@ $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.ph
$type = optional_param('type', '', PARAM_ALPHANUM); //TODO: hopefully will be removed in 2.0
$sectionreturn = optional_param('sr', null, PARAM_INT);
$beforemod = optional_param('beforemod', 0, PARAM_INT);
$showonly = optional_param('showonly', '', PARAM_TAGLIST); // Settings group to show expanded and hide the rest.
$url = new moodle_url('/course/modedit.php');
$url->param('sr', $sectionreturn);
if (!empty($return)) {
$url->param('return', $return);
}
if (!empty($showonly)) {
$url->param('showonly', $showonly);
}
if (!empty($add)) {
$section = required_param('section', PARAM_INT);
@@ -113,6 +117,9 @@ if (!empty($add)) {
$data->return = $return;
$data->sr = $sectionreturn;
$data->update = $update;
if (!empty($showonly)) {
$data->showonly = $showonly;
}
$sectionname = get_section_name($course, $cw);
$fullmodulename = get_string('modulename', $module->name);
@@ -153,6 +160,9 @@ if (file_exists($modmoodleform)) {
$mformclassname = 'mod_'.$module->name.'_mod_form';
$mform = new $mformclassname($data, $cw->section, $cm, $course);
$mform->set_data($data);
if (!empty($showonly)) {
$mform->filter_shown_headers(explode(',', $showonly));
}
if ($mform->is_cancelled()) {
if ($return && !empty($cm->id)) {
+7 -1
View File
@@ -712,7 +712,10 @@ abstract class moodleform_mod extends moodleform {
// conflicts with fields in existing modules (such as assign).
// So it uses a long name that will not conflict.
$mform->addElement('textarea', 'availabilityconditionsjson',
get_string('accessrestrictions', 'availability'));
get_string('accessrestrictions', 'availability'),
['class' => 'd-none']
);
// The _cm variable may not be a proper cm_info, so get one from modinfo.
if ($this->_cm) {
$modinfo = get_fast_modinfo($COURSE);
@@ -1064,6 +1067,9 @@ abstract class moodleform_mod extends moodleform {
$mform->addElement('hidden', 'beforemod', 0);
$mform->setType('beforemod', PARAM_INT);
$mform->addElement('hidden', 'showonly', '');
$mform->setType('showonly', PARAM_ALPHANUMEXT);
}
public function standard_grading_coursemodule_elements() {
@@ -65,8 +65,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should not see "Forum 4"
And I should see "Not available" in the "#section-5" "css_element"
And I should not see "Forum 5"
@@ -83,7 +83,7 @@ Feature: Collapse course sections
And I should not see "Assignment 2" in the "region-main" "region"
And I should not see "Book 2" in the "region-main" "region"
And I should not see "Book 3" in the "region-main" "region"
And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should not see "Available until" in the "section-4" "core_availability > Section availability"
And I click on "#collapssesection1" "css_element"
And I click on "#collapssesection2" "css_element"
And I click on "#collapssesection3" "css_element"
@@ -93,7 +93,7 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
@javascript
Scenario: Expand/collapse sections for Weeks format.
@@ -107,8 +107,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
@@ -125,7 +125,7 @@ Feature: Collapse course sections
And I should not see "Assignment 2" in the "region-main" "region"
And I should not see "Book 2" in the "region-main" "region"
And I should not see "Book 3" in the "region-main" "region"
And I should not see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should not see "Available until" in the "section-4" "core_availability > Section availability"
And I should not see "Not available" in the "#section-5" "css_element"
And I click on "#collapssesection1" "css_element"
And I click on "#collapssesection2" "css_element"
@@ -136,8 +136,8 @@ Feature: Collapse course sections
And I should see "Assignment 2" in the "region-main" "region"
And I should see "Book 2" in the "region-main" "region"
And I should see "Book 3" in the "region-main" "region"
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
@@ -157,8 +157,8 @@ Feature: Collapse course sections
Then "Topic 1" "section" should not exist
And "Topic 3" "section" should not exist
And I am on "Course 1" course homepage with editing mode on
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should see "Forum 4"
And I should see "Hidden from students" in the "#section-5" "css_element"
And I should see "Forum 5"
@@ -179,8 +179,8 @@ Feature: Collapse course sections
Then "1 May - 7 May" "section" should not exist
And "15 May - 21 May" "section" should not exist
And I am on the "Course 1" course page logged in as student1
And I should see "Available until" in the "#section-4 .availabilityinfo" "css_element"
And I should see "2013" in the "#section-4 .availabilityinfo" "css_element"
And I should see "Available until" in the "section-4" "core_availability > Section availability"
And I should see "2013" in the "section-4" "core_availability > Section availability"
And I should not see "Forum 4"
And I should see "Not available" in the "#section-5" "css_element"
And I should not see "Forum 5"
+1
View File
@@ -28,6 +28,7 @@ $string['and'] = 'and';
$string['condition_group'] = 'Restriction set';
$string['condition_group_info'] = 'Add a set of nested restrictions to apply complex logic.';
$string['disabled_verb'] = 'Cannot be changed as ruleset includes a rule containing private data.';
$string['editsettings'] = 'Edit settings';
$string['enableavailability'] = 'Enable restricted access';
$string['enableavailability_desc'] = 'If enabled, conditions (based on date, grade, completion etc.) may be set to control whether an activity or resource can be accessed.';
$string['error_list_nochildren'] = 'Restriction sets should contain at least one condition.';
+1 -1
View File
@@ -6,6 +6,6 @@ define("core_form/collapsesections",["exports","jquery","core/pending"],(functio
* @copyright 2021 Bas Brands
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 4.0
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_pending=_interopRequireDefault(_pending);const SELECTORS_FORMHEADER=".fheader",SELECTORS_FORMCONTAINER=".fcontainer",CLASSES_SHOW="show",CLASSES_COLLAPSED="collapsed";_exports.init=collapsesections=>{const pendingPromise=new _pending.default("core_form/collapsesections"),collapsemenu=document.querySelector(collapsesections),formParent=collapsemenu.closest("form");collapsemenu.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),collapsemenu.click())}));let expandedcount=0;const formcontainercount=(0,_jquery.default)(SELECTORS_FORMCONTAINER).length;(0,_jquery.default)(SELECTORS_FORMCONTAINER).each(((_,collapsecontainer)=>{collapsecontainer.classList.contains(CLASSES_SHOW)&&expandedcount++})),formcontainercount===expandedcount&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0)),collapsemenu.addEventListener("click",(()=>{let action="hide";collapsemenu.classList.contains(CLASSES_COLLAPSED)&&(action="show"),formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{(0,_jquery.default)(collapsecontainer).collapse(action)}))}));const collapseElementIds=[...(0,_jquery.default)(SELECTORS_FORMHEADER)].map(((element,index)=>(element.id=element.id||"collapseElement-".concat(index),element.id)));collapsemenu.setAttribute("aria-controls",collapseElementIds.join(" ")),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("hidden.bs.collapse",(()=>{let allCollapsed=!0;formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{collapsecontainer.classList.contains(CLASSES_SHOW)&&(allCollapsed=!1)})),allCollapsed&&(collapsemenu.classList.add(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!1))})),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("shown.bs.collapse",(()=>{let allExpanded=!0;formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{collapsecontainer.classList.contains(CLASSES_SHOW)||(allExpanded=!1)})),allExpanded&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0))})),pendingPromise.resolve()}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_pending=_interopRequireDefault(_pending);const SELECTORS_FORMHEADER=".fheader",SELECTORS_FORMCONTAINER=".fcontainer",CLASSES_SHOW="show",CLASSES_COLLAPSED="collapsed",CLASSES_HIDDEN="d-none";_exports.init=collapsesections=>{const pendingPromise=new _pending.default("core_form/collapsesections"),collapsemenu=document.querySelector(collapsesections),formParent=collapsemenu.closest("form");collapsemenu.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),collapsemenu.click())}));let formcontainercount=0;(0,_jquery.default)(SELECTORS_FORMCONTAINER).each(((_,container)=>{container.classList.contains(CLASSES_HIDDEN)||container.parentElement.classList.contains(CLASSES_HIDDEN)||formcontainercount++}));let expandedcount=0;(0,_jquery.default)(SELECTORS_FORMCONTAINER).each(((_,collapsecontainer)=>{collapsecontainer.classList.contains(CLASSES_SHOW)&&expandedcount++})),formcontainercount===expandedcount&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0)),collapsemenu.addEventListener("click",(()=>{let action="hide";collapsemenu.classList.contains(CLASSES_COLLAPSED)&&(action="show"),formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{(0,_jquery.default)(collapsecontainer).collapse(action)}))}));const collapseElementIds=[...(0,_jquery.default)(SELECTORS_FORMHEADER)].map(((element,index)=>(element.id=element.id||"collapseElement-".concat(index),element.id)));collapsemenu.setAttribute("aria-controls",collapseElementIds.join(" ")),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("hidden.bs.collapse",(()=>{let allCollapsed=!0;formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{collapsecontainer.classList.contains(CLASSES_SHOW)&&(allCollapsed=!1)})),allCollapsed&&(collapsemenu.classList.add(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!1))})),(0,_jquery.default)(SELECTORS_FORMCONTAINER).on("shown.bs.collapse",(()=>{let allExpanded=!0;formParent.querySelectorAll(SELECTORS_FORMCONTAINER).forEach((collapsecontainer=>{collapsecontainer.classList.contains(CLASSES_SHOW)||(allExpanded=!1)})),allExpanded&&(collapsemenu.classList.remove(CLASSES_COLLAPSED),collapsemenu.setAttribute("aria-expanded",!0))})),pendingPromise.resolve()}}));
//# sourceMappingURL=collapsesections.min.js.map
File diff suppressed because one or more lines are too long
+10 -3
View File
@@ -32,7 +32,8 @@ const SELECTORS = {
const CLASSES = {
SHOW: 'show',
COLLAPSED: 'collapsed'
COLLAPSED: 'collapsed',
HIDDEN: 'd-none'
};
/**
@@ -52,9 +53,15 @@ export const init = collapsesections => {
}
});
// Override default collapse class if all containers are expanded on page load
// Override default collapse class if all visible containers are expanded on page load
let formcontainercount = 0;
$(SELECTORS.FORMCONTAINER).each((_, container) => {
if (!container.classList.contains(CLASSES.HIDDEN) &&
!container.parentElement.classList.contains(CLASSES.HIDDEN)) {
formcontainercount++;
}
});
let expandedcount = 0;
const formcontainercount = $(SELECTORS.FORMCONTAINER).length;
$(SELECTORS.FORMCONTAINER).each((_, collapsecontainer) => {
if (collapsecontainer.classList.contains(CLASSES.SHOW)) {
expandedcount++;
+122 -2
View File
@@ -485,6 +485,24 @@ abstract class moodleform {
$this->_form->setDefaults($default_values);
}
/**
* Use this method to indicate that the fieldsets should be shown as expanded
* and all other fieldsets should be hidden.
* The method is applicable to header elements only.
*
* @param array $shownonly array of header element names
* @return void
*/
public function filter_shown_headers(array $shownonly): void {
$toshow = [];
foreach ($shownonly as $show) {
if ($this->_form->elementExists($show) && $this->_form->getElementType($show) == 'header') {
$toshow[] = $show;
}
}
$this->_form->filter_shown_headers($toshow);
}
/**
* Check that form was submitted. Does not check validity of submitted data.
*
@@ -1636,6 +1654,14 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
*/
var $_disableShortforms = false;
/**
* Array whose keys are the only elements to be shown.
* Rest of the elements that are not in this array will be hidden.
*
* @var array
*/
protected $_shownonlyelements = [];
/** @var bool whether to automatically initialise the form change detector this form. */
protected $_use_form_change_checker = true;
@@ -1830,6 +1856,45 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
$this->_collapsibleElements[$headername] = !$expanded;
}
/**
* Use this method to indicate that the fieldsets should be shown and expanded
* and all other fieldsets should be hidden.
* The method is applicable to header elements only.
*
* @param array $shownonly array of header element names
* @return void
*/
public function filter_shown_headers(array $shownonly): void {
$this->_shownonlyelements = [];
if (empty($shownonly)) {
return;
}
foreach ($shownonly as $headername) {
$element = $this->getElement($headername);
if ($element->getType() == 'header') {
$this->_shownonlyelements[] = $headername;
$this->setExpanded($headername);
}
}
}
/**
* Use this method to check if the fieldsets could be shown.
* The method is applicable to header elements only.
*
* @param string $headername header element name to check in the shown only elements array.
* @return void
*/
public function is_shown(string $headername): bool {
if (empty($headername)) {
return true;
}
if (empty($this->_shownonlyelements)) {
return true;
}
return in_array($headername, $this->_shownonlyelements);
}
/**
* Use this method to add show more/less status element required for passing
* over the advanced elements visibility status on the form submission.
@@ -2012,15 +2077,22 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
}
if ($element->getType() == 'header') {
if (!$this->is_shown($headername)) {
$this->setExpanded($headername, false);
continue;
}
if ($headercounter === 1 && !isset($this->_collapsibleElements[$headername])) {
// By default the first section is always expanded, except if a state has already been set.
$this->setExpanded($headername, true);
} else if (($headercounter === 2 && $headerscount === 2) && !isset($this->_collapsibleElements[$headername])) {
} else if (
($headercounter === 2 && $headerscount === 2)
&& !isset($this->_collapsibleElements[$headername])
) {
// The second section is always expanded if the form only contains 2 sections),
// except if a state has already been set.
$this->setExpanded($headername, true);
}
} else if ($anyrequiredorerror) {
} else if ($anyrequiredorerror && (empty($headername) || $this->is_shown($headername))) {
// If any error or required field are present within the header, we need to expand it.
$this->setExpanded($headername, true, true);
} else if (!isset($this->_collapsibleElements[$headername])) {
@@ -2032,12 +2104,38 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
// Pass the array to renderer object.
$renderer->setCollapsibleElements($this->_collapsibleElements);
}
$this->accept_set_nonvisible_elements($renderer);
if (method_exists($renderer, 'set_sticky_footer') && !empty($this->_stickyfooterelement)) {
$renderer->set_sticky_footer($this->_stickyfooterelement);
}
parent::accept($renderer);
}
/**
* Checking non-visible elements to set when accepting a renderer.
* @param HTML_QuickForm_Renderer $renderer
*/
private function accept_set_nonvisible_elements($renderer) {
if (!method_exists($renderer, 'set_nonvisible_elements') || $this->_disableShortforms) {
return;
}
$nonvisibles = [];
foreach (array_keys($this->_elements) as $index) {
$element =& $this->_elements[$index];
if ($element->getType() != 'header') {
continue;
}
$headername = $element->getName();
if (!$this->is_shown($headername)) {
$nonvisibles[] = $headername;
}
}
// Pass the array to renderer object.
$renderer->set_nonvisible_elements($nonvisibles);
}
/**
* Adds one or more element names that indicate the end of a fieldset
*
@@ -3116,6 +3214,14 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
/** @var string advanced class HTML. */
protected $_advancedHTML;
/**
* Array whose keys are element names should be hidden.
* If the key exists this is an invisible element.
*
* @var array
*/
protected $_nonvisibleelements = [];
/**
* Constructor
*/
@@ -3175,6 +3281,15 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
$this->_collapsibleElements = $elements;
}
/**
* Setting non visible elements
*
* @param array $elements
*/
public function set_nonvisible_elements($elements) {
$this->_nonvisibleelements = $elements;
}
/**
* What to do when starting the form
*
@@ -3437,6 +3552,11 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
}
}
// Hide fieldsets not included in the shown only elements.
if (in_array($header->getName(), $this->_nonvisibleelements)) {
$fieldsetclasses[] = 'd-none';
}
if (isset($this->_advancedElements[$name])){
$fieldsetclasses[] = 'containsadvancedelements';
}
+1 -1
View File
@@ -52,7 +52,7 @@
}
}}
{{#text}}
<div class="availabilityinfo {{classes}}">
<div class="availabilityinfo {{classes}}" data-region="availabilityinfo">
{{^isrestricted}}
<span class="badge badge-info">{{{text}}}</span>
{{/isrestricted}}
+1
View File
@@ -44,6 +44,7 @@ information provided here is intended especially for developers.
* The action_menu::set_constraint() method is deprecated. Please use action_menu::set_boundary() instead.
* New \core\output\activity_header::get_heading_level() method to get the heading level for a given heading level depending whether
the page displays a heading for the activity (usually a h2 heading containing the activity name).
* New method moodleform::filter_shown_headers() is created to show some expanded headers only and hide the rest.
=== 4.2 ===
+15
View File
@@ -1362,6 +1362,21 @@ $activity-add-hover: theme-color-level('primary', -10) !default;
padding: map-get($spacers, 1) map-get($spacers, 3);
background-color: $gray-200;
@include border-radius($activity-item-border-radius);
.editavailability {
padding: map-get($spacers, 1) map-get($spacers, 3);
@include border-radius(1rem);
:hover {
background-color: $gray-400;
}
a {
@include border-radius(0.5rem);
color: $body-color;
text-decoration: none;
}
}
}
&.section-summary {
+12
View File
@@ -29018,6 +29018,18 @@ span.editinstructions .alert-link {
background-color: #e9ecef;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability {
padding: 0.25rem 1rem;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability :hover {
background-color: #ced4da;
}
.course-section .availabilityinfo .editavailability a {
border-radius: 0.5rem;
color: #1d2125;
text-decoration: none;
}
.course-section.section-summary {
padding-left: 1rem;
padding-right: 1rem;
+12
View File
@@ -29018,6 +29018,18 @@ span.editinstructions .alert-link {
background-color: #e9ecef;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability {
padding: 0.25rem 1rem;
border-radius: 1rem;
}
.course-section .availabilityinfo .editavailability :hover {
background-color: #ced4da;
}
.course-section .availabilityinfo .editavailability a {
border-radius: 0.5rem;
color: #1d2125;
text-decoration: none;
}
.course-section.section-summary {
padding-left: 1rem;
padding-right: 1rem;