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

Allow AKSlot creation via scheduler

This implements #120
parent 94aa9fd0
Branches
No related tags found
No related merge requests found
......@@ -133,7 +133,8 @@ class RoomViewSet(EventSlugMixin, mixins.RetrieveModelMixin, mixins.ListModelMix
return Room.objects.filter(event=self.event)
class AKSlotViewSet(EventSlugMixin, mixins.RetrieveModelMixin, mixins.ListModelMixin, viewsets.GenericViewSet):
class AKSlotViewSet(EventSlugMixin, mixins.RetrieveModelMixin, mixins.CreateModelMixin, mixins.UpdateModelMixin,
mixins.ListModelMixin, viewsets.GenericViewSet):
permission_classes = (permissions.DjangoModelPermissionsOrAnonReadOnly,)
serializer_class = AKSlotSerializer
......
......@@ -134,9 +134,19 @@
eventChange: updateEvent,
eventReceive: updateEvent,
editable: true,
selectable: true,
drop: function (info) {
info.draggedEl.parentNode.removeChild(info.draggedEl);
},
select: function (info) {
console.log(info);
$('#id_start').val(info.startStr);
$('#id_end').val(info.endStr);
$('#id_room').val(info.resource._resource.id);
$('#id_duration').val(Math.abs(info.end-info.start)/1000/60/60);
$('#id_ak').val("");
$('#newAKSlotModal').modal('show');
},
allDaySlot: false,
nowIndicator: true,
now: "{% timestamp_now event.timezone %}",
......@@ -232,11 +242,63 @@
}
reloadBtn.click(reload);
function addSlot() {
let ak = $('#id_ak').val();
if(ak === "") {
alert("{% trans "Bitte AK auswählen" %}");
}
else {
$.ajax({
url: "{% url "model:AKSlot-list" event_slug=event.slug %}",
type: 'POST',
data: {
start: $('#id_start').val(),
duration: $('#id_duration').val(),
room: $('#id_room').val(),
ak: ak,
event: "{{ event.pk }}"
},
success: function (response) {
$('#newAKSlotModal').modal('hide');
reload();
},
error: function (response) {
console.error(response);
alert("{% trans 'Could not create slot' %}");
}
});
}
}
$('#newAKSlotModalSubmitButton').click(addSlot);
});
</script>
</head>
<body>
<div class="modal" id="newAKSlotModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% trans "Add slot" %}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form>
{% bootstrap_form akSlotAddForm %}
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="newAKSlotModalSubmitButton">{% trans "Add" %}</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans "Cancel" %}</button>
</div>
</div>
</div>
</div>
<div class="box p-3">
<div class="row header pb-2">
<div class="col">
......
......@@ -8,6 +8,7 @@ from django.views.generic import ListView, DetailView, UpdateView
from AKModel.models import AKSlot, AKTrack, Event, AK, AKCategory
from AKModel.views import AdminViewMixin, FilterByEventSlugMixin, EventSlugMixin, IntermediateAdminView
from AKScheduling.forms import AKInterestForm
from AKSubmission.forms import AKAddSlotForm
class UnscheduledSlotsAdminView(AdminViewMixin, FilterByEventSlugMixin, ListView):
......@@ -40,6 +41,8 @@ class SchedulingAdminView(AdminViewMixin, FilterByEventSlugMixin, ListView):
context["start"] = self.event.start
context["end"] = self.event.end
context["akSlotAddForm"] = AKAddSlotForm(self.event)
return context
......
......@@ -186,3 +186,14 @@ class AKOrgaMessageForm(forms.ModelForm):
'event': forms.HiddenInput,
'text': forms.Textarea,
}
class AKAddSlotForm(forms.Form):
start = forms.CharField(label=_("Start"), disabled=True)
end = forms.CharField(label=_("End"), disabled=True)
duration = forms.CharField(label=_("Duration"), disabled=True)
room = forms.IntegerField(label=_("Room"), disabled=True)
def __init__(self, event):
super().__init__()
self.fields['ak'] = forms.ModelChoiceField(event.ak_set.all(), label=_("AK"))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment