Inscription en perm
This commit is contained in:
parent
634c4ad4ff
commit
6d81735a55
10 changed files with 105 additions and 7 deletions
18
event/static/js/enrol_event.js
Normal file
18
event/static/js/enrol_event.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
$(function(){
|
||||
function initEnrolment(elt) {
|
||||
elt = $(elt);
|
||||
elt.find("form.enrolment").on("submit", function() {
|
||||
elt.addClass("sending-request");
|
||||
var form = this;
|
||||
var url = form.action + "?ajax";
|
||||
$.post(url, $(form).serialize(), function(data) {
|
||||
elt.html(data);
|
||||
elt.removeClass("sending-request");
|
||||
initEnrolment(elt);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
$.each($(".activity-summary"), function(i, item) { initEnrolment(item) });
|
||||
});
|
|
@ -71,7 +71,7 @@
|
|||
{% endwith %}
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
s'inscrire (TODO)
|
||||
{% enrol_btn activity request.user %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
|
||||
{% block title %}{% trans "Évènement" %}{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
{{ block.super }}
|
||||
<script type="text/javascript" src="{% static "js/enrol_event.js" %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ event.title}}
|
||||
{% if perms.event.event_can_change and user.is_staff %}
|
||||
|
@ -49,7 +54,9 @@
|
|||
de <strong>{{ activity.beginning | time:"H:i" }}</strong>
|
||||
à <strong>{{ activity.end| time:"H:i" }}</strong>
|
||||
</span>
|
||||
{% include "event/activity_summary.html" with activity=activity %}
|
||||
<div class="activity-summary">
|
||||
{% include "event/activity_summary.html" with activity=activity %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
6
event/templates/event/tags/enrol_btn.html
Normal file
6
event/templates/event/tags/enrol_btn.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{% load i18n %}
|
||||
<form method="POST" action="{% url "event:enrol_activity" activity.pk %}" class="enrolment {{ enrolled|yesno:"enrolled,unenrolled" }}">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="goal" value="{{ enrolled|yesno:"unenrol,enrol" }}" />
|
||||
{{ enrolled|yesno:_("Inscrit,") }} <input type="submit" value="{{ enrolled|yesno:_("Se désinscrire,S'inscrire") }}" class="btn btn-warning"/>
|
||||
</form>
|
|
@ -7,3 +7,10 @@ register = template.Library()
|
|||
@register.filter()
|
||||
def get_herited(activity, attrname):
|
||||
return activity.get_herited(attrname)
|
||||
|
||||
@register.inclusion_tag("event/tags/enrol_btn.html")
|
||||
def enrol_btn(activity, user):
|
||||
return {
|
||||
"enrolled": activity.staff.filter(id=user.id).exists(),
|
||||
"activity": activity,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.conf.urls import url
|
||||
from event.views import Index, EventView, ActivityView
|
||||
from event.views import Index, EventView, ActivityView, EnrolActivityView
|
||||
|
||||
app_name = 'event'
|
||||
urlpatterns = [
|
||||
|
@ -7,4 +7,6 @@ urlpatterns = [
|
|||
url(r'^(?P<slug>[-\w]+)/$', EventView.as_view(), name='event'),
|
||||
url(r'^activity/(?P<pk>[0-9]+)/$', ActivityView.as_view(),
|
||||
name='activity'),
|
||||
url(r'^activity/(?P<pk>[0-9]+)/enrol/$',
|
||||
EnrolActivityView.as_view(), name="enrol_activity"),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.views.generic import DetailView
|
||||
from django.views.generic import TemplateView, DetailView, View
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.http import JsonResponse, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Event, Activity
|
||||
from equipment.models import EquipmentAttribution
|
||||
|
@ -34,3 +36,22 @@ class ActivityView(LoginRequiredMixin, DetailView):
|
|||
.filter(activity=activity)
|
||||
.prefetch_related('equipment'))
|
||||
return context
|
||||
|
||||
|
||||
class EnrolActivityView(LoginRequiredMixin, View):
|
||||
http_method_names = ['post']
|
||||
|
||||
def post(self, request, pk, *args, **kwargs):
|
||||
activity = get_object_or_404(Activity, id=pk)
|
||||
action = request.POST.get("goal", None)
|
||||
success = True
|
||||
if action == "enrol":
|
||||
activity.staff.add(request.user)
|
||||
elif action == "unenrol":
|
||||
activity.staff.remove(request.user)
|
||||
else:
|
||||
success = False
|
||||
if "ajax" in request.GET:
|
||||
return render(request, "event/activity_summary.html",
|
||||
{"activity": activity})
|
||||
return HttpResponseRedirect(reverse("event:activity", kwargs={"pk":pk}))
|
||||
|
|
|
@ -359,4 +359,21 @@ a.module {
|
|||
.glyphicon.dunno {
|
||||
color: #5599C4 !important; }
|
||||
|
||||
.sending-request {
|
||||
position: relative; }
|
||||
.sending-request:after {
|
||||
content: "Chargement...";
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
opacity: 0.8;
|
||||
color: #777;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
z-index: 5;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 8%; }
|
||||
|
||||
/*# sourceMappingURL=global.css.map */
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -250,3 +250,23 @@ a.module {
|
|||
color:$dunno_color!important;
|
||||
}
|
||||
}
|
||||
|
||||
.sending-request {
|
||||
position: relative;
|
||||
|
||||
&:after {
|
||||
content: "Chargement...";
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
opacity: 0.8;
|
||||
color: #777;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
z-index: 5;
|
||||
top: 0;
|
||||
left: 0;
|
||||
padding: 8%;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue