Skip to content

Commit

Permalink
button to randomize individual seeds on set detail page for one user
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Dec 5, 2023
1 parent 7d0f568 commit 5c074ca
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/WeBWorK/ContentGenerator/Instructor/ProblemSetDetail.pm
Original file line number Diff line number Diff line change
Expand Up @@ -940,14 +940,35 @@ sub fieldHTML ($c, $userID, $setID, $problemID, $globalRecord, $userRecord, $fie
my $value = $forUsers ? $userValue : $globalValue;
$value = format_set_name_display($value =~ s/\s*,\s*/,/gr) if $field eq 'restricted_release';

$inputType = $c->text_field(
my @field_args = (
"$recordType.$recordID.$field", $value,
id => "$recordType.$recordID.${field}_id",
data => { override => "$recordType.$recordID.$field.override_id" },
class => 'form-control form-control-sm',
$forUsers && $check ? (aria_labelledby => "$recordType.$recordID.$field.label") : (),
$field eq 'restricted_release' || $field eq 'source_file' ? (dir => 'ltr') : ()
);
if ($field eq 'problem_seed') {
# Insert a randomization button
$inputType = Mojo::ByteStream->new($c->tag(
'div',
class => 'input-group input-group-sm',
style => 'min-width: 7rem',
$c->number_field(@field_args, min => 0)->to_string
. $c->tag(
'button',
type => 'button',
class => 'btn btn-sm btn-secondary',
title => 'randomize',
onclick =>
"(function() {document.getElementById('$recordType.$recordID.${field}_id').value = Math.floor(Math.random() * 10000);})();",
$c->tag('i', class => 'fa-solid fa-shuffle')
)
))->html_unescape;
warn(ref($inputType));
} else {
$inputType = $c->text_field(@field_args);
}
}
} elsif ($choose) {
# If $field matches /:/, then multiple fields are used.
Expand Down

0 comments on commit 5c074ca

Please sign in to comment.