Skip to content

Commit

Permalink
finalize bartender availability comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Janssen-dev committed Oct 5, 2024
1 parent 1ae6f44 commit ef15d3a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
7 changes: 7 additions & 0 deletions alexia/apps/general/templatetags/get_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import template

register = template.Library()

@register.filter
def get_item(key, dictionary):
return dictionary.get(key)
4 changes: 3 additions & 1 deletion alexia/apps/scheduling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def event_list_view(request):
# Net als onze BartenderAvailabilities
bartender_availabilities = BartenderAvailability.objects.filter(
user_id=request.user.pk).values('event_id', 'availability_id', 'comment')

bartender_availabilities = {ba['event_id']: ba for ba in bartender_availabilities}

return render(request, 'scheduling/event_list.html', locals())

Expand Down Expand Up @@ -340,7 +342,7 @@ def set_bartender_availability_comment(request):
return HttpResponseBadRequest("NOTOK")

comment = request.POST.get('comment')
if len(comment) > BartenderAvailability.comment.max_length:
if len(comment) > 100:
return HttpResponseBadRequest("TOOLONG")
availability = get_object_or_404(BartenderAvailability, event=event, user=request.user)
availability.comment = comment
Expand Down
3 changes: 2 additions & 1 deletion assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ $(function () {
event_id: event_id,
availability_id: $(this).val()
}, function (data) {
$('#assigned_bartenders_' + event_id).html(data).effect("highlight");
$('#assigned_bartenders_' + event_id).html(data);
$('#bartender_availability_comment_' + event_id).css('visibility', 'visible');
}, "text");
});

Expand Down
22 changes: 5 additions & 17 deletions templates/scheduling/event_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends 'base_app.html' %}
{% load get_item %}

{% block title %}{% trans 'Planning' %}{% endblock title %}

Expand Down Expand Up @@ -105,30 +106,17 @@ <h1>
<td>
{% if not e.is_closed and request.organization in e.participants.all %}
{% if not e.organizer.assigns_tenders or not user in e.get_assigned_bartenders %}
{% for ba in bartender_availabilities %}
{% if ba.event_id == e.pk or forloop.last %}
{% with ba=e.pk|get_item:bartender_availabilities %}
<div style="display: flex; height: 100%; align-items: center">
{% include "scheduling/partials/availability_comment.html" %}
<select class="bartender_availability form-control" data-event-id="{{ e.pk }}">
<option value="-1">---</option>
{% for a in availabilities %}
<option value="{{ a.pk }}"{% if ba.availability_id == a.pk %} selected="selected"{% endif %}>{{ a.name }}</option>
<option value="{{ a.pk }}"{% if ba.availability_id == a.pk and ba.event_id == e.pk %} selected="selected"{% endif %}>{{ a.name }}</option>
{% endfor %}
</select>
{% include "scheduling/partials/availability_comment.html" %}
</div>
{% endif %}
{% empty %}
<div style="display: flex; height: 100%; align-items: center">
{% include "scheduling/partials/availability_comment.html" %}
<select class="bartender_availability form-control" data-event-id="{{ e.pk }}">
<option value="-1">---</option>
{% for a in availabilities %}
<option value="{{ a.pk }}"{% if ba.availability_id == a.pk %} selected="selected"{% endif %}>{{ a.name }}</option>
{% endfor %}
</select>
</div>
{% endfor %}

{% endwith %}
{% endif %}
{% endif %}
</td>
Expand Down
6 changes: 3 additions & 3 deletions templates/scheduling/partials/availability_comment.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div title="{{ba.comment}}" class="bartender_availability_comment" style="margin-right: 1rem" data-event-id="{{e.pk}}">
<span class="glyphicon glyphicon-comment"></span>
</div>
<div {% if ba.event_id == e.pk %} title="{{ba.comment}}" {%endif%} id="bartender_availability_comment_{{e.pk}}" class="bartender_availability_comment" style="margin-left: 1rem;{%if not ba %}visibility: hidden{% endif %}" data-event-id="{{e.pk}}">
<span class="glyphicon glyphicon-comment"></span>
</div>

0 comments on commit ef15d3a

Please sign in to comment.