Skip to content

Commit

Permalink
#26 integers disabled samecm nocm (#27)
Browse files Browse the repository at this point in the history
* #26 - disabled attribute for modules without completion moved outside of option value

* #26 - store values as integers, not strings

* #26 - always have an existing default module selected to prevent choosing "none"

* #26 - do not let the current module be selectable on the client side

* #26 - prevent storing an irrelevant module id

* #26 - fix: Variable "currentCmId" must be all lower-case

* #26 - fix: "1 hour after completion of activity Act1" text was not found in the page

Used the wrong value member var

* #26 - fix: explicitly enable completion for the activities
  • Loading branch information
danowar2k authored Feb 26, 2024
1 parent dd4abd1 commit 520f33e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
12 changes: 8 additions & 4 deletions classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,23 @@ protected function get_javascript_init_params($course, cm_info $cm = null, secti
}
$activitysel = [];
if ($course->enablecompletion != 0) {
$cm = get_fast_modinfo($course);
$currentcmid = $cm ? $cm->id : 0;
$modinfo = get_fast_modinfo($course);

$s = [];
// Gets only sections with content.
foreach ($cm->get_sections() as $sectionnum => $section) {
$sectioninfo = $cm->get_section_info($sectionnum);
foreach ($modinfo->get_sections() as $sectionnum => $section) {
$sectioninfo = $modinfo->get_section_info($sectionnum);
$s['name'] = $sectioninfo->name;
if (empty($s['name'])) {
$s['name'] = get_string('section') . ' ' . $sectionnum;
}
$s['coursemodules'] = [];
foreach ($section as $cmid) {
$module = $cm->get_cm($cmid);
if ($currentcmid == $cmid) {
continue;
}
$module = $modinfo->get_cm($cmid);
// Get only course modules which are not deleted.
if ($module->deletioninprogress == 0) {
$s['coursemodules'][] = [
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/availability_relativedate_ui.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Feature: availability_relativedate ui
| startdate | ## -10 days 17:00 ## |
| enddate | ## +2 weeks 17:00 ## |
And the following "activities" exist:
| activity | name | intro | course | idnumber | section | visible |
| page | Page A | intro | C1 | pageA | 1 | 1 |
| page | Page B | intro | C1 | pageB | 1 | 1 |
| activity | name | intro | course | idnumber | section | visible | completion |
| page | Page A | intro | C1 | pageA | 1 | 1 | 1 |
| page | Page B | intro | C1 | pageB | 1 | 1 | 1 |
And the following "users" exist:
| username |
| teacher1 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ M.availability_relativedate.form.getNode = function(json) {
html += '</select></label>';
html += '<label><select name="relativecoursemodule"' + (json.s != 7 ? ' style="display: none;"' : '') + '>';

var defaultCourseModuleId = 0;

for (i = 0; i < this.activitySelector.length; i++) {
html += '<option disabled>' + this.activitySelector[i].name + '</option>';
for (j = 0; j < this.activitySelector[i].coursemodules.length; j++) {
html += '<option value="' + this.activitySelector[i].coursemodules[j].id;
html += '<option value="' + this.activitySelector[i].coursemodules[j].id + '"';
if (this.activitySelector[i].coursemodules[j].completionenabled == 0) {
html += ' disabled';
} else {
if (!defaultCourseModuleId) {
defaultCourseModuleId = this.activitySelector[i].coursemodules[j].id;
}
}
html += '">' + this.activitySelector[i].coursemodules[j].name + '</option>';
html += '>' + this.activitySelector[i].coursemodules[j].name + '</option>';
}
}
html += '</select></label>';
Expand All @@ -103,7 +109,7 @@ M.availability_relativedate.form.getNode = function(json) {
}
node.one('select[name=relativestart]').set('value', i);

i = 0;
i = defaultCourseModuleId;
if (json.m !== undefined) {
i = json.m;
}
Expand Down Expand Up @@ -133,10 +139,13 @@ M.availability_relativedate.form.getNode = function(json) {
};

M.availability_relativedate.form.fillValue = function(value, node) {
value.n = node.one('select[name=relativenumber]').get('value');
value.d = node.one('select[name=relativednw]').get('value');
value.s = node.one('select[name=relativestart]').get('value');
value.m = node.one('select[name=relativecoursemodule]').get('value');
value.n = Number(node.one('select[name=relativenumber]').get('value'));
value.d = Number(node.one('select[name=relativednw]').get('value'));
value.s = Number(node.one('select[name=relativestart]').get('value'));
value.m = 0;
if (value.s == 7) {
value.m = Number(node.one('select[name=relativecoursemodule]').get('value'));
}
};

M.availability_relativedate.form.fillErrors = function(errors, node) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,20 @@ M.availability_relativedate.form.getNode = function(json) {
html += '</select></label>';
html += '<label><select name="relativecoursemodule"' + (json.s != 7 ? ' style="display: none;"' : '') + '>';

var defaultCourseModuleId = 0;

for (i = 0; i < this.activitySelector.length; i++) {
html += '<option disabled>' + this.activitySelector[i].name + '</option>';
for (j = 0; j < this.activitySelector[i].coursemodules.length; j++) {
html += '<option value="' + this.activitySelector[i].coursemodules[j].id;
html += '<option value="' + this.activitySelector[i].coursemodules[j].id + '"';
if (this.activitySelector[i].coursemodules[j].completionenabled == 0) {
html += ' disabled';
} else {
if (!defaultCourseModuleId) {
defaultCourseModuleId = this.activitySelector[i].coursemodules[j].id;
}
}
html += '">' + this.activitySelector[i].coursemodules[j].name + '</option>';
html += '>' + this.activitySelector[i].coursemodules[j].name + '</option>';
}
}
html += '</select></label>';
Expand All @@ -103,7 +109,7 @@ M.availability_relativedate.form.getNode = function(json) {
}
node.one('select[name=relativestart]').set('value', i);

i = 0;
i = defaultCourseModuleId;
if (json.m !== undefined) {
i = json.m;
}
Expand Down Expand Up @@ -133,10 +139,13 @@ M.availability_relativedate.form.getNode = function(json) {
};

M.availability_relativedate.form.fillValue = function(value, node) {
value.n = node.one('select[name=relativenumber]').get('value');
value.d = node.one('select[name=relativednw]').get('value');
value.s = node.one('select[name=relativestart]').get('value');
value.m = node.one('select[name=relativecoursemodule]').get('value');
value.n = Number(node.one('select[name=relativenumber]').get('value'));
value.d = Number(node.one('select[name=relativednw]').get('value'));
value.s = Number(node.one('select[name=relativestart]').get('value'));
value.m = 0;
if (value.s == 7) {
value.m = Number(node.one('select[name=relativecoursemodule]').get('value'));
}
};

M.availability_relativedate.form.fillErrors = function(errors, node) {
Expand Down
23 changes: 16 additions & 7 deletions yui/src/form/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ M.availability_relativedate.form.getNode = function(json) {
html += '</select></label>';
html += '<label><select name="relativecoursemodule"' + (json.s != 7 ? ' style="display: none;"' : '') + '>';

var defaultCourseModuleId = 0;

for (i = 0; i < this.activitySelector.length; i++) {
html += '<option disabled>' + this.activitySelector[i].name + '</option>';
for (j = 0; j < this.activitySelector[i].coursemodules.length; j++) {
html += '<option value="' + this.activitySelector[i].coursemodules[j].id;
html += '<option value="' + this.activitySelector[i].coursemodules[j].id + '"';
if (this.activitySelector[i].coursemodules[j].completionenabled == 0) {
html += ' disabled';
} else {
if (!defaultCourseModuleId) {
defaultCourseModuleId = this.activitySelector[i].coursemodules[j].id;
}
}
html += '">' + this.activitySelector[i].coursemodules[j].name + '</option>';
html += '>' + this.activitySelector[i].coursemodules[j].name + '</option>';
}
}
html += '</select></label>';
Expand All @@ -101,7 +107,7 @@ M.availability_relativedate.form.getNode = function(json) {
}
node.one('select[name=relativestart]').set('value', i);

i = 0;
i = defaultCourseModuleId;
if (json.m !== undefined) {
i = json.m;
}
Expand Down Expand Up @@ -131,10 +137,13 @@ M.availability_relativedate.form.getNode = function(json) {
};

M.availability_relativedate.form.fillValue = function(value, node) {
value.n = node.one('select[name=relativenumber]').get('value');
value.d = node.one('select[name=relativednw]').get('value');
value.s = node.one('select[name=relativestart]').get('value');
value.m = node.one('select[name=relativecoursemodule]').get('value');
value.n = Number(node.one('select[name=relativenumber]').get('value'));
value.d = Number(node.one('select[name=relativednw]').get('value'));
value.s = Number(node.one('select[name=relativestart]').get('value'));
value.m = 0;
if (value.s == 7) {
value.m = Number(node.one('select[name=relativecoursemodule]').get('value'));
}
};

M.availability_relativedate.form.fillErrors = function(errors, node) {
Expand Down

0 comments on commit 520f33e

Please sign in to comment.