Skip to content

Commit

Permalink
Refinements to delete button and input field in personalized points g…
Browse files Browse the repository at this point in the history
…oal modal
  • Loading branch information
mikaelGusse committed Aug 19, 2024
1 parent 67f5158 commit 4172f22
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
5 changes: 4 additions & 1 deletion exercise/static/exercise/personalized_points_goal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
$(document).ready(function() {
const $pointsGoalForm = $('#pointsGoalForm');
const $inputField = $('#id_personalized_points_goal_input');
// If points-goal is a number then input it into the field
if (typeof $pointsGoalForm.data('points-goal') === 'number') {
$inputField.val($pointsGoalForm.data('points-goal'))};
$inputField.focus();
$pointsGoalForm.on('submit', function(event) {
event.preventDefault();
Expand All @@ -14,7 +17,7 @@ $(document).ready(function() {
if (!isNumber && !isPercentage) {
$('#validation-alert').show();
setTimeout(function() {
$('#validation-errors-alert').hide();
$('#validation-alert').hide();
}, 5000);
return;
}
Expand Down
1 change: 1 addition & 0 deletions exercise/templates/exercise/_user_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ <h3 class="panel-title">
{% csrf_token %}
{% if user.id %}
{% get_max_module_points module.id user.id as max_points %}
{% get_points_goal module.id user.id as points_goal %}
{% if max_points > 0 and user.id %}
<a class="page-modal aplus-button--secondary aplus-button--xs" style="float: right; margin-left: 5px;" role="button" href="{% url 'save_points_goal_form_view' course_slug=course.url instance_slug=instance.url module_slug=module.url %}" data-module-id="{{ module.id }}" title="{% translate 'POINTS_GOAL_TOOLTIP' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-screenshot" aria-hidden="true"></span> {% translate 'POINTS_GOAL' %}
Expand Down
25 changes: 15 additions & 10 deletions exercise/templates/exercise/personalized_points_goal_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

{% get_max_module_points module.id user.id as max_points %}
{% get_module_points module.id user.id as points %}
{% get_points_goal module.id user.id as points_goal %}

<div class="content">
<div class="header">
Expand Down Expand Up @@ -36,6 +37,7 @@ <h4 class="title" id="pointsGoalModalLabel">{% translate "PERSONALIZED_POINTS_MO
data-personalized-points-goal-text="{% translate 'PERSONALIZED_POINTS_GOAL ' %}"
data-personalized-points-goal-tooltip-text="{% translate 'POINTS_GOAL' %}"
data-points="{{ points }}"
data-points-goal={{ points_goal }}
>
{% csrf_token %}
<div class="form-group">
Expand All @@ -50,16 +52,19 @@ <h4 class="title" id="pointsGoalModalLabel">{% translate "PERSONALIZED_POINTS_MO
<div style="display: flex;">
<button type="submit" class="aplus-button--default aplus-button--md" style="margin-top: 10px;">{% translate "SAVE" %}</button>
</form>
<form id="deletePointsGoalForm" method="POST"
action="{% url 'save_points_goal_form_view' course_slug=course.url instance_slug=instance.url module_slug=module.url %}"
data-module-url="{{module.url|lower}}"
data-personalized-points-goal-text="{% translate 'PERSONALIZED_POINTS_GOAL ' %}"
data-personalized-points-goal-tooltip-text="{% translate 'POINTS_GOAL' %}"
data-points="{{ points }}"
>
{% csrf_token %}
<button type="submit" class="aplus-button--danger aplus-button--md" style="margin-top: 10px; margin-left: 5px;">{% translate "REMOVE" %}</button>
</form>
{% if points_goal != False %}
<form id="deletePointsGoalForm" method="POST"
action="{% url 'save_points_goal_form_view' course_slug=course.url instance_slug=instance.url module_slug=module.url %}"
data-module-url="{{module.url|lower}}"
data-personalized-points-goal-text="{% translate 'PERSONALIZED_POINTS_GOAL ' %}"
data-personalized-points-goal-tooltip-text="{% translate 'POINTS_GOAL' %}"
data-points="{{ points }}"
data-points-goal={{ points_goal }}
>
{% csrf_token %}
<button type="submit" class="aplus-button--danger aplus-button--md" style="margin-top: 10px; margin-left: 5px;">{% translate "REMOVE" %}</button>
</form>
{% endif %}
</div>

</div>
12 changes: 11 additions & 1 deletion exercise/templatetags/exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _

from course.models import CourseInstance, CourseModule
from course.models import CourseInstance, CourseModule, StudentModuleGoal
from lib.errors import TagUsageError
from lib.helpers import format_points as _format_points, is_ajax as _is_ajax
from userprofile.models import UserProfile
Expand Down Expand Up @@ -82,6 +82,16 @@ def get_max_module_points(module: int, student: int) -> int:
return cached_module.max_points


@register.simple_tag
def get_points_goal(module: int, student: int) -> int:
student = UserProfile.objects.get(id=student)
module = CourseModule.objects.get(id=module)
try:
return StudentModuleGoal.objects.get(module=module, student=student).personalized_points_goal_points
except StudentModuleGoal.DoesNotExist:
return False


def _is_accessible(context, entry, t):
if t and t > _prepare_now(context):
return False
Expand Down
2 changes: 1 addition & 1 deletion locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ msgid "PERSONALIZED_POINTS_GOAL"
msgstr "Pistetavoite"

msgid "PERSONALIZED_POINTS_MODAL_LESS_THAN_REQUIRED"
msgstr "Pistetavoite ei voi olla vähemmän kuin moduulin läpipääsyyn vaaditut pisteet"
msgstr "Pistetavoite ei voi olla vähemmän kuin moduulin läpäisyyn vaaditut pisteet"

msgid "PERSONALIZED_POINTS_MODAL_REMOVE_SUCCESS"
msgstr "Pistetavoite poistettu onnistuneesti"
Expand Down

0 comments on commit 4172f22

Please sign in to comment.