Skip to content
Snippets Groups Projects
Commit b67838fc authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Use new AJAX based interest indication on AK overview views

Additionally, remove obsolete logging
parent 7633372b
No related branches found
No related tags found
1 merge request!111add interest window
Pipeline #48617 failed with stage
in 44 seconds
......@@ -68,7 +68,6 @@
data: {
},
success: function (response) {
console.log(response);
btn.html('{% fa5_icon 'check' 'fas' %}');
btn.off('click');
$('#interest-counter').html(response.interest_counter);
......
{% load i18n %}
{% load fontawesome_5 %}
<script>
document.addEventListener('DOMContentLoaded', function () {
// CSRF Protection/Authentication
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
function indicate_interest(ak_id, btn) {
$.ajax({
url: "{% url "model:AK-list" event_slug=event.slug %}" + ak_id + "/indicate-interest/",
type: 'POST',
data: {
},
success: function (response) {
btn.html('{% fa5_icon 'check' 'fas' %}');
btn.off('click');
},
error: function (response) {
if(response.status === 403)
alert("{% trans 'Interest indication currently not allowed. Sorry.' %}");
else
alert("{% trans 'Could not save your interest. Sorry.' %}");
}
});
}
// Update counter
$('.btn-interest').click(function () {
indicate_interest($(this).data('ak_id'), $(this));
});
});
</script>
......@@ -19,6 +19,8 @@
white-space: nowrap;
}
</style>
{% include "AKSubmission/ak_interest_script.html" %}
{% endblock %}
{% block breadcrumbs %}
......
......@@ -52,9 +52,11 @@
<a href="{% url 'submit:ak_edit' event_slug=event.slug pk=ak.pk %}" data-toggle="tooltip"
title="{% trans 'Edit' %}"
class="btn btn-success">{% fa5_icon 'pencil-alt' 'fas' %}</a>
<a href="{% url 'submit:overview_inc_interest' event_slug=event.slug pk=ak.pk %}" data-toggle="tooltip"
title="{% trans 'Show Interest' %}"
class="btn btn-primary">{% fa5_icon 'thumbs-up' 'fas' %}</a>
{% if interest_indication_active %}
<span data-ak_id="{{ ak.pk }}" data-toggle="tooltip"
title="{% trans 'Show Interest' %}"
class="btn btn-primary btn-interest" style="cursor: pointer">{% fa5_icon 'thumbs-up' 'fas' %}</span>
{% endif %}
{% endif %}
</td>
</tr>
......
......@@ -28,6 +28,8 @@
}
</style>
{% include "AKSubmission/ak_interest_script.html" %}
{% if event.active %}
<link href="{% static 'common/vendor/select2/select2.min.css' %}" rel="stylesheet" />
<script src="{% static 'common/vendor/select2/select2.min.js' %}"></script>
......
......@@ -74,6 +74,10 @@ class AKOverviewView(FilterByEventSlugMixin, ListView):
context["active_category"] = self.get_active_category_name(context)
context['table_title'] = self.get_table_title(context)
# Display interest indication button?
current_timestamp = datetime.now().astimezone(self.event.timezone)
context['interest_indication_active'] = ak_interest_indication_active(self.event, current_timestamp)
return context
......@@ -137,10 +141,11 @@ class AKDetailView(EventSlugMixin, DetailView):
context = super().get_context_data(object_list=object_list, **kwargs)
context["availabilities"] = Availability.objects.filter(ak=context["ak"])
current_timestamp = datetime.now().astimezone(self.event.timezone)
# Is this AK taking place now or soon (used for top page visualization)
context["featured_slot_type"] = "NONE"
if apps.is_installed("AKPlan"):
current_timestamp = datetime.now().astimezone(self.event.timezone)
in_two_hours = current_timestamp + timedelta(hours=2)
slots = context["ak"].akslot_set.filter(start__isnull=False, room__isnull=False)
for slot in slots:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment