Skip to content

Commit bbd0cf9

Browse files
committed
Add validation of the accomodation time factor.
1 parent 261c645 commit bbd0cf9

File tree

6 files changed

+57
-24
lines changed

6 files changed

+57
-24
lines changed

htdocs/js/ActionTabs/actiontabs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
actionLink.addEventListener('show.bs.tab', () => {
77
if (takeAction) takeAction.value = actionLink.textContent;
88
if (currentAction) currentAction.value = actionLink.dataset.action;
9+
takeAction.formNoValidate = actionLink.dataset.noValidate ? true : false;
910
});
1011
});
1112

htdocs/js/UserList/userlist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959
} else {
6060
element?.classList.remove('is-invalid');
61-
if (element.id in event_listeners) {
61+
if (element && element.id in event_listeners) {
6262
element?.removeEventListener('change', event_listeners[element.id]);
6363
delete event_listeners[element.id];
6464
}

lib/WeBWorK/ContentGenerator/Instructor/UserList.pm

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,39 @@ use constant FIELDS => [
9898
'recitation', 'comment', 'permission', 'password'
9999
];
100100

101-
# Note that only the editable fields need a type (i.e. all but user_id),
102-
# and only the text fields need a size.
101+
# Note that only the editable fields need a type (i.e. all but user_id).
102+
# The fields of type text or number may also include optional attributes for the HTML input.
103103
use constant FIELD_PROPERTIES => {
104104
user_id => { name => x('Login Name') },
105-
first_name => { name => x('First Name'), type => 'text', size => 10 },
106-
last_name => { name => x('Last Name'), type => 'text', size => 10 },
107-
email_address => { name => x('Email Address'), type => 'text', size => 20 },
108-
student_id => { name => x('Student ID'), type => 'text', size => 11 },
109-
status => { name => x('Enrollment Status'), type => 'status' },
110-
accommodation_time_factor => { name => x('Accommodation Time Factor'), type => 'text', size => 5 },
111-
section => { name => x('Section'), type => 'text', size => 3 },
112-
recitation => { name => x('Recitation'), type => 'text', size => 3 },
113-
comment => { name => x('Comment'), type => 'text', size => 20 },
114-
permission => { name => x('Permission Level'), type => 'permission' },
115-
password => { name => x('Password'), type => 'password' },
105+
first_name => { name => x('First Name'), type => 'text', attributes => { size => 10 } },
106+
last_name => { name => x('Last Name'), type => 'text', attributes => { size => 10 } },
107+
email_address => { name => x('Email Address'), type => 'text', attributes => { size => 20 } },
108+
student_id => { name => x('Student ID'), type => 'text', attributes => { size => 11 } },
109+
status => { name => x('Enrollment Status'), type => 'status' },
110+
accommodation_time_factor => {
111+
name => x('Accommodation Time Factor'),
112+
type => 'number',
113+
attributes => {
114+
size => 5,
115+
min => 1,
116+
step => 'any',
117+
title => 'Enter a decimal number that is greater than or equal to 1.'
118+
},
119+
perlValidate => sub {
120+
my $value = shift;
121+
return $value !~ /^(\d+(\.\d*)?|\.\d+)$/ || $value <= 0
122+
? (x(
123+
'Accomodation time factor for [_1] unchanged. '
124+
. 'A value was given that is not a decimal number or is not greater than or equal to 1.'
125+
))[0]
126+
: 0;
127+
}
128+
},
129+
section => { name => x('Section'), type => 'text', attributes => { size => 3 } },
130+
recitation => { name => x('Recitation'), type => 'text', attributes => { size => 3 } },
131+
comment => { name => x('Comment'), type => 'text', attributes => { size => 20 } },
132+
permission => { name => x('Permission Level'), type => 'permission' },
133+
password => { name => x('Password'), type => 'password' },
116134
};
117135

118136
sub pre_header_initialize ($c) {
@@ -519,7 +537,14 @@ sub save_edit_handler ($c) {
519537

520538
for my $field ($User->NONKEYFIELDS()) {
521539
my $newValue = $c->param("user.$userID.$field");
522-
$User->$field($newValue) if defined $newValue;
540+
next unless defined $newValue;
541+
if (ref(FIELD_PROPERTIES()->{$field}{perlValidate}) eq 'CODE'
542+
&& (my $error = FIELD_PROPERTIES()->{$field}{perlValidate}->($newValue)))
543+
{
544+
$c->addbadmessage($c->maketext($error, $userID));
545+
next;
546+
}
547+
$User->$field($newValue);
523548
}
524549
$db->putUser($User);
525550

templates/ContentGenerator/Instructor/UserList.html.ep

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@
5959
<%= link_to maketext($formTitles->{$actionID}) => "#$actionID",
6060
class => "nav-link action-link$active$disabled",
6161
id => "$actionID-tab",
62-
data => { action => $actionID, bs_toggle => 'tab', bs_target => "#$actionID" },
62+
data => {
63+
action => $actionID,
64+
bs_toggle => 'tab',
65+
bs_target => "#$actionID",
66+
$actionID eq 'cancel_edit' ? (no_validate => 1) : ()
67+
},
6368
role => 'tab',
6469
'aria-controls' => $actionID,
65-
'aria-selected' => $active ? 'true' : 'false' =%>
70+
'aria-selected' => $active ? 'true' : 'false', =%>
6671
</li>
6772
% end
6873
% content_for 'tab-content' => begin

templates/ContentGenerator/Instructor/UserList/user_list_field.html.ep

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
% my $fieldName = 'user.' . $user->user_id . '.' . $field;
22
% my $properties = $fieldProperties->{$field};
33
%
4-
% if ($properties->{type} eq 'text') {
4+
% if ($properties->{type} eq 'text' || $properties->{type} eq 'number') {
55
% my $value = $user->$field;
66
% if ($c->{editMode}) {
7-
<%= text_field $fieldName => $value, id => $fieldName . '_id', size => $properties->{size},
7+
% my $field_method = "$properties->{type}_field";
8+
<%= $c->$field_method($fieldName => $value, id => $fieldName . '_id', %{$properties->{attributes} // {}},
89
class => 'form-control form-control-sm d-inline w-auto',
9-
'aria-labelledby' => ($fieldName =~ s/^.*\.([^.]*)$/$1/r) . '_header' =%>
10+
'aria-labelledby' => ($fieldName =~ s/^.*\.([^.]*)$/$1/r) . '_header') =%>
1011
% } else {
1112
% if ($field eq 'email_address') {
1213
% if ($value =~ /\S/) {

templates/HelpFiles/InstructorUserList.html.ep

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@
145145
<dt><%= maketext('Give one student or several students additional time for all timed tests.') %></dt>
146146
<dd>
147147
<%= maketext('Click on the "Select" checkbox next to the names of the students that additional time is to be '
148-
. 'assigned, click on the radio button for editing selected users and then click the "Edit" button .'
149-
. 'Set the "Accesibility Time Factor" to the desired multiplier for each student selected. The time '
150-
. 'that a student will have to complete a timed test will be the product of the "Test Time Limit" for the '
151-
. 'test set in the "Sets Manager" and the "Accommodation Time Factor" set here.') =%>
148+
. 'assigned, click on the radio button for editing selected users, and then click the "Edit" button. '
149+
. 'Set the "Accommodation Time Factor" to the desired multiplier for each student selected (this must be a '
150+
. 'decimal number that is greater than or equal to 1). The time that a student will have to complete a '
151+
. 'timed test will be the product of the "Test Time Limit" for the test set in the "Sets Manager" and '
152+
. 'the "Accommodation Time Factor" set here.') =%>
152153
</dd>
153154

154155
<dt><%= maketext('Extend the number of attempts allowed a student on a given problem.') %></dt>

0 commit comments

Comments
 (0)