Skip to content

Commit

Permalink
Improve UI when checkboxes selected
Browse files Browse the repository at this point in the history
  • Loading branch information
damianhxy committed Oct 31, 2023
1 parent 5f204ba commit 65f7d2e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
31 changes: 26 additions & 5 deletions app/assets/javascripts/edit_assessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@
});

// Penalties tab
let initial_load = true; // determines if the page is loading for the first time, if so, don't clear the fields

$('#unlimited_submissions').on('change', function() {
const checked = $(this).prop('checked');
const $max_submissions = $('#assessment_max_submissions');
$max_submissions.prop('disabled', checked);
if (checked) {
$max_submissions.val(-1);
$max_submissions.val('Unlimited submissions');
} else if (!initial_load) {
$max_submissions.val('');
}
});

Expand All @@ -58,17 +62,22 @@
const $max_grace_days = $('#assessment_max_grace_days');
$max_grace_days.prop('disabled', checked);
if (checked) {
$max_grace_days.val('Unlimited grace days');
} else if (!initial_load) {
$max_grace_days.val('');
}
});

$('#use_default_late_penalty').on('change', function() {
const checked = $(this).prop('checked');
const $latePenaltyField = $('#assessment_late_penalty_attributes_value').parent();
const $latePenaltyValue = $('#assessment_late_penalty_attributes_value');
const $latePenaltyField = $latePenaltyValue.parent();
$latePenaltyField.find('input').prop('disabled', checked);
$latePenaltyField.find('select').prop('disabled', checked);
if (checked) {
$('#assessment_late_penalty_attributes_value').val('');
$latePenaltyValue.val('Course default');
} else if (!initial_load) {
$latePenaltyValue.val('');
}
});

Expand All @@ -77,20 +86,32 @@
const $version_threshold = $('#assessment_version_threshold');
$version_threshold.prop('disabled', checked);
if (checked) {
$version_threshold.val('Course default');
} else if (!initial_load) {
$version_threshold.val('');
}
});

$('#use_default_version_penalty').on('change', function() {
const checked = $(this).prop('checked');
const $versionPenaltyField = $('#assessment_version_penalty_attributes_value').parent();
const $versionPenaltyValue = $('#assessment_version_penalty_attributes_value');
const $versionPenaltyField = $versionPenaltyValue.parent();
$versionPenaltyField.find('input').prop('disabled', checked);
$versionPenaltyField.find('select').prop('disabled', checked);
if (checked) {
$('#assessment_version_penalty_attributes_value').val('');
$versionPenaltyValue.val('Course default');
} else if (!initial_load) {
$versionPenaltyValue.val('');
}
});

// Trigger on page load
$('#unlimited_submissions').trigger('change');
$('#unlimited_grace_days').trigger('change');
$('#use_default_late_penalty').trigger('change');
$('#use_default_version_threshold').trigger('change');
$('#use_default_version_penalty').trigger('change');
initial_load = false;
});

})();
Expand Down
5 changes: 0 additions & 5 deletions app/views/assessments/_edit_penalties.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
help_text: "The maximum number of times a student can submit the assessment. \
<br>If set to -1, unlimited submissions are allowed.".html_safe,
placeholder: "10",
disabled: @has_unlimited_submissions,
wrap_class: %w[input-field no-padding-bottom] %>
<%= label_tag(:unlimited_submissions, nil, class: "input-default") do %>
<%= check_box_tag :unlimited_submissions, "1", @has_unlimited_submissions %>
Expand All @@ -12,7 +11,6 @@
<%= f.text_field :max_grace_days,
help_text: "Maximum number of grace days that a student can spend on this assessment. \
<br>If left blank, all available grace days can be spent on this assessment.".html_safe,
disabled: @has_unlimited_grace_days,
wrap_class: %w[input-field no-padding-bottom] %>
<%= label_tag(:unlimited_grace_days) do %>
<%= check_box_tag :unlimited_grace_days, "1", @has_unlimited_grace_days %>
Expand All @@ -24,7 +22,6 @@
help_text: "The penalty applied to late submissions after a student runs out of grace days.
It represents the number of points or a percentage of the total score removed per day, and must be a non-negative
number.<br>If left blank, the course default is used.".html_safe,
disabled: @uses_default_late_penalty,
wrap_class: %w[input-field no-padding-bottom] %>
<%= label_tag(:use_default_late_penalty) do %>
<%= check_box_tag :use_default_late_penalty, "1", @uses_default_late_penalty %>
Expand All @@ -36,7 +33,6 @@
each additional submission is penalized according to the version penalty.
<br>If set to -1, no submissions are penalized.
<br>If left blank, the course default is used.".html_safe,
disabled: @uses_default_version_threshold,
wrap_class: %w[input-field no-padding-bottom] %>
<%= label_tag(:use_default_version_threshold) do %>
<%= check_box_tag :use_default_version_threshold, "1", @uses_default_version_threshold %>
Expand All @@ -49,7 +45,6 @@
threshold, and must be a non-negative number.
For example, if this is set to 1 point and the version threshold to 3, the fifth version of a student's submissions would be docked 2 points.
<br>If left blank, the course default is used.".html_safe,
disabled: @uses_default_version_penalty,
wrap_class: %w[input-field no-padding-bottom] %>
<%= label_tag(:use_default_version_penalty) do %>
<%= check_box_tag :use_default_version_penalty, "1", @uses_default_version_penalty %>
Expand Down

0 comments on commit 65f7d2e

Please sign in to comment.