Skip to content

Commit

Permalink
MDL-83056 core_course: Disable subsection add link when max reached
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentdavid committed Jan 6, 2025
1 parent 035a7b1 commit 5a2b19b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion course/format/amd/build/local/content/actions.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion course/format/amd/build/local/content/actions.min.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions course/format/amd/src/local/content/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default class extends BaseComponent {
COURSEADDSECTION: `#course-addsection`,
MAXSECTIONSWARNING: `[data-region='max-sections-warning']`,
ADDSECTIONREGION: `[data-region='section-addsection']`,
ADDSECTIONREGIONLINK: `a[data-region='section-addsection']`,
BODY: `body`,
};
// Component css classes.
Expand Down Expand Up @@ -817,6 +818,9 @@ export default class extends BaseComponent {
// Set the full addSection Visible if it was not.
const addSection = document.querySelector(this.selectors.COURSEADDSECTION);
addSection.classList.remove(this.classes.DISPLAYNONE);
document.querySelectorAll(this.selectors.ADDSECTIONREGIONLINK).forEach((element) => {
element.classList.toggle(this.classes.DISABLED, locked);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ class before_activitychooserbutton_exported_handler {
public static function callback(before_activitychooserbutton_exported $hook): void {
/** @var section_info $section */
$section = $hook->get_section();

if (!permission::can_add_subsection($section)) {
if ($section->is_delegated()) {
return;
}

$attributes = [
'class' => 'dropdown-item',
'class' => 'dropdown-item' . (permission::can_add_subsection($section) ? '' : ' disabled'),
'data-action' => 'addModule',
'data-modname' => 'subsection',
'data-sectionnum' => $section->sectionnum,
'data-region' => 'section-addsection',
];
if ($hook->get_cm()) {
$attributes['data-beforemod'] = $hook->get_cm()->id;
Expand Down

0 comments on commit 5a2b19b

Please sign in to comment.