Skip to content

Commit

Permalink
If an achievement item can not be used, then disable the "Use Reward"…
Browse files Browse the repository at this point in the history
… button.

This fixes issue openwebwork#2279.

For now this just makes the "Use Reward" button disabled if there are no
sets that the achievement item can act one.  With a little more effort a
message could be shown when the button is clicked instead.
  • Loading branch information
drgrice1 committed Jan 16, 2024
1 parent 72ed1f0 commit 0ea994d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 21 deletions.
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/AddNewTestGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
&& between($set->open_date, $set->due_date);
}

return unless @openGateways;

return $c->c(
$c->tag('p', $c->maketext('Add a new version for which test?')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/DoubleProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
}
}

return unless @openSets;

return $c->c(
$c->tag(
'p',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/DoubleSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set which you would like to be worth twice as much.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/DuplicateProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
}
}

return unless @openSets;

return $c->c(
$c->tag(
'p',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set whose close date you would like to extend.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ExtendDueDateGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
&& between($set->open_date, $set->due_date);
}

return unless @openGateways;

return $c->c(
$c->tag('p', $c->maketext('Extend the close date for which test?')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/FullCreditProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
}
}

return unless @openSets;

return $c->c(
$c->tag(
'p',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/FullCreditSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Please choose the set for which all problems should be given full credit.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/HalfCreditProb.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
}
}

return unless @openSets;

return $c->c(
$c->tag(
'p',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/HalfCreditSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Please choose the set for which all problems should have half credit added.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ReducedCred.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set which you would like to enable partial credit for.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ResetIncorrectAttempts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
}
}

return unless @openSets;

return $c->c(
$c->tag(
'p',
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ResurrectGW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
|| ($set->reduced_scoring_date && after($set->reduced_scoring_date)));
}

return unless @closed_gateway_sets;

return $c->c(
$c->tag('p', $c->maketext('Resurrect which test?')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/ResurrectHW.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
|| ($sets->[$i]->reduced_scoring_date && after($sets->[$i]->reduced_scoring_date)));
}

return unless @closedSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set which you would like to resurrect.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
2 changes: 2 additions & 0 deletions lib/WeBWorK/AchievementItems/SuperExtendDueDate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ sub print_form ($self, $sets, $setProblemIds, $c) {
if (between($sets->[$i]->open_date, $sets->[$i]->due_date) && $sets->[$i]->assignment_type eq 'default');
}

return unless @openSets;

return $c->c(
$c->tag('p', $c->maketext('Choose the set whose close date you would like to extend.')),
WeBWorK::AchievementItems::form_popup_menu_row(
Expand Down
45 changes: 24 additions & 21 deletions templates/ContentGenerator/Achievements/achievement_items.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,37 @@
<h3><%= maketext($item->name) %></h3>
% }
<p><%= maketext($item->description) %></p>
% my $form = $item->print_form($sets, $setProblemIds, $c);
% # Print a modal popup for each item which contains the form necessary to get the data to use the item.
<%= link_to maketext('Use Reward') => '#modal_' . $item->id,
role => 'button',
class => 'btn btn-secondary',
class => 'btn btn-secondary' . ($form ? '' : ' disabled'),
id => 'popup_' . $item->id,
data => { bs_toggle => 'modal' } =%>
<div id="<%= 'modal_' . $item->id %>" class="modal hide fade" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><%= maketext($item->name) %></h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<%= maketext('close') %>"></button>
</div>
<%= form_for current_route, method => 'POST', name => "itemform_$itemNumber",
class => 'achievementitemform', begin =%>
<div class="modal-body">
<%= $item->print_form($sets, $setProblemIds, $c) =%>
<%= hidden_field useditem => $itemNumber =%>
<%= $c->hidden_authen_fields("achievement_${itemNumber}_") =%>
</div>
<div class="modal-footer">
<%= submit_button maketext('Submit'), class => 'btn btn-primary' =%>
$form ? (data => { bs_toggle => 'modal' }) : () =%>
% if ($form) {
<div id="<%= 'modal_' . $item->id %>" class="modal hide fade" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><%= maketext($item->name) %></h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<%= maketext('close') %>"></button>
</div>
<%= end =%>
<%= form_for current_route, method => 'POST', name => "itemform_$itemNumber",
class => 'achievementitemform', begin =%>
<div class="modal-body">
<%= $form =%>
<%= hidden_field useditem => $itemNumber =%>
<%= $c->hidden_authen_fields("achievement_${itemNumber}_") =%>
</div>
<div class="modal-footer">
<%= submit_button maketext('Submit'), class => 'btn btn-primary' =%>
</div>
<%= end =%>
</div>
</div>
</div>
</div>
% }
</div>
% $itemNumber++;
% }
Expand Down

0 comments on commit 0ea994d

Please sign in to comment.