Skip to content

Commit

Permalink
MDL-73232 core_courseformat: Inform user when max number of sections …
Browse files Browse the repository at this point in the history
…reached

* Disable the Add new Section button when max has been reached
* It also grays out the (+) button between sections and display a tooltip
  • Loading branch information
laurentdavid committed Jun 18, 2024
1 parent 2bf886f commit 286cc42
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 14 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.

25 changes: 25 additions & 0 deletions course/format/amd/src/local/content/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,16 @@ export default class extends BaseComponent {
ACTIONMENUTOGGLER: `[data-toggle="dropdown"]`,
// Availability modal selectors.
OPTIONSRADIO: `[type='radio']`,
COURSE_ADDSECTION: `#course-addsection`,
NOMORESECTION: `.add-no-more-sections`,
};
// Component css classes.
this.classes = {
DISABLED: `text-body`,
ITALIC: `font-italic`,
DISPLAYNONE: `d-none`,
DISPLAYFLEX: `d-flex`,
ADDCONTENTDISABLED: `add-content-disabled`
};
}

Expand Down Expand Up @@ -681,9 +686,29 @@ export default class extends BaseComponent {
const targets = this.getElements(this.selectors.ADDSECTION);
targets.forEach(element => {
element.classList.toggle(this.classes.DISABLED, locked);
element.classList.toggle(this.classes.ADDCONTENTDISABLED, locked);
element.classList.toggle(this.classes.ITALIC, locked);
this.setElementLocked(element, locked);
// We tweak the element to show a tooltip.
if (locked) {
element.setAttribute('data-toggle', 'tooltip');
element.setAttribute('data-placement', 'left');
getString('sectionaddmax', 'core_courseformat').then((text) => element.setAttribute('title', text));
element.style.pointerEvents = null;
element.style.userSelect = null;
} else {
element.removeAttribute('data-toggle');
element.removeAttribute('title');
element.removeAttribute('data-original-title');
}
});
const courseAddSection = this.getElement(this.selectors.COURSE_ADDSECTION);
const addSection = courseAddSection.querySelector(this.selectors.ADDSECTION);
addSection.classList.toggle(this.classes.DISPLAYNONE, locked);
addSection.classList.toggle(this.classes.DISPLAYFLEX, !locked);
const noMoreSections = courseAddSection.querySelector(this.selectors.NOMORESECTION);
noMoreSections.classList.toggle(this.classes.DISPLAYNONE, !locked);
noMoreSections.classList.toggle(this.classes.DISPLAYFLEX, locked);
}

/**
Expand Down
35 changes: 23 additions & 12 deletions course/format/templates/local/content/addsection.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,29 @@
</a>
{{/decrease}}
{{#addsections}}

<a href="{{{url}}}"
class="btn add-section d-flex justify-content-center align-items-center p-3"
data-add-sections="{{title}}"
data-new-sections="{{newsection}}"
data-action="addSection"
{{#insertafter}} data-id="{{id}}" {{/insertafter}}
>
{{#pix}} t/add, core {{/pix}}
{{title}}
</a>

<a href="{{{url}}}"
class="d-none btn add-section justify-content-center align-items-center p-3"
data-add-sections="{{title}}"
data-new-sections="{{newsection}}"
data-action="addSection"
{{#insertafter}} data-id="{{id}}" {{/insertafter}}
>
{{#pix}} t/add, core {{/pix}}
{{title}}
</a>
<div class="d-none add-no-more-sections justify-content-center align-items-center p-3 flex-column">
<div>
{{#pix}}t/block, moodle{{/pix}}
</div>
<span class="font-italic">
{{#str}}maxsectionaddmessage, core_courseformat{{/str}}
</span>
</div>
{{/addsections}}
</div>
{{/showaddsection}}
{{^showaddsection}}
<div id="course-addsection" class="changenumsections bulk-hidden mt-5">
<span>No more section</span>
</div>
{{/showaddsection}}
2 changes: 2 additions & 0 deletions lang/en/courseformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
$string['courseindexoptions'] = 'Course index options';
$string['nobulkaction'] = 'No bulk actions available';
$string['preference:coursesectionspreferences'] = 'Section user preferences for course {$a}';
$string['maxsectionaddmessage'] = 'You have reached the maximum number of sections allowed for a course.';
$string['privacy:metadata:preference:coursesectionspreferences'] = 'Section user preferences like collapsed and expanded.';
$string['section_hide_feedback'] = 'Course section {$a->name} hidden.';
$string['section_hide_feedback_batch'] = 'Selected {$a->count} course sections hidden.';
Expand All @@ -73,6 +74,7 @@
$string['section_delete_feedback'] = 'Course section {$a->name} deleted.';
$string['section_delete_feedback_batch'] = 'Selected {$a->count} course sections deleted.';
$string['sectionavailability_title'] = 'Section availability';
$string['sectionaddmax'] = 'You have reached the maximum number of sections allowed for a course...';
$string['sectiondelete_info'] = 'This will delete {$a->name} and all the activities it contains.';
$string['sectiondelete_title'] = 'Delete section?';
$string['sectionsavailability'] = 'Sections availability';
Expand Down
17 changes: 17 additions & 0 deletions theme/boost/scss/moodle/course.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,12 @@ $divider-hover-color: $primary !default;
color: $primary;
}
}
.add-no-more-sections {
border-top: $divider-width dashed $border-color;
font-size: $font-size-sm;
font-weight: normal;
color: $dark;
}

/* Single section page specific styles */

Expand Down Expand Up @@ -1615,6 +1621,17 @@ $divider-hover-color: $primary !default;
}
}

.btn.add-content-disabled {
@include border-radius($rounded-pill);
color: theme-color-level("secondary", $alert-color-level);
background-color: theme-color-level("secondary", $alert-bg-level);
&:hover,
&:focus {
color: color-yiq($secondary);
background-color: $secondary;
}
}

/* Bulk editing */

.bulkenabled {
Expand Down
17 changes: 17 additions & 0 deletions theme/boost/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -29057,6 +29057,13 @@ span.editinstructions .alert-link {
color: #0f6cbf;
}

.add-no-more-sections {
border-top: 2px dashed #dee2e6;
font-size: 0.8203125rem;
font-weight: normal;
color: #343a40;
}

/* Single section page specific styles */
.single-section > ul > .course-section.hidden .section-item {
background-color: inherit;
Expand Down Expand Up @@ -29776,6 +29783,16 @@ span.editinstructions .alert-link {
font-size: 14px;
}

.btn.add-content-disabled {
border-radius: 50rem;
color: #6b6e71;
background-color: #f5f6f8;
}
.btn.add-content-disabled:hover, .btn.add-content-disabled:focus {
color: #1d2125;
background-color: #ced4da;
}

/* Bulk editing */
.bulkenabled .bulk-hidden {
display: none !important;
Expand Down
17 changes: 17 additions & 0 deletions theme/classic/style/moodle.css
Original file line number Diff line number Diff line change
Expand Up @@ -29057,6 +29057,13 @@ span.editinstructions .alert-link {
color: #0f6cbf;
}

.add-no-more-sections {
border-top: 2px dashed #dee2e6;
font-size: 0.8203125rem;
font-weight: normal;
color: #343a40;
}

/* Single section page specific styles */
.single-section > ul > .course-section.hidden .section-item {
background-color: inherit;
Expand Down Expand Up @@ -29776,6 +29783,16 @@ span.editinstructions .alert-link {
font-size: 14px;
}

.btn.add-content-disabled {
border-radius: 50rem;
color: #6b6e71;
background-color: #f5f6f8;
}
.btn.add-content-disabled:hover, .btn.add-content-disabled:focus {
color: #1d2125;
background-color: #ced4da;
}

/* Bulk editing */
.bulkenabled .bulk-hidden {
display: none !important;
Expand Down

0 comments on commit 286cc42

Please sign in to comment.