diff --git a/openslides/agenda/static/js/agenda/site.js b/openslides/agenda/static/js/agenda/site.js index c0ca5d19f..d29637ac2 100644 --- a/openslides/agenda/static/js/agenda/site.js +++ b/openslides/agenda/static/js/agenda/site.js @@ -581,9 +581,7 @@ angular.module('OpenSlidesApp.agenda.site', [ if (event.dest.nodesScope.item) { parentID = event.dest.nodesScope.item.id; } - angular.forEach(event.dest.nodesScope.$modelValue, function(item, index) { - $http.patch('/rest/agenda/item/' + item.id + '/', {parent_id: parentID, weight: index}); - }); + $http.post('/rest/agenda/item/sort/', {nodes: event.dest.nodesScope.$modelValue, parent_id: parentID}); } }; } diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index e2a9d9307..75d8d1cbe 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -47,7 +47,7 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV result = (has_perm(self.request.user, 'agenda.can_see') and has_perm(self.request.user, 'agenda.can_see_hidden_items') and has_perm(self.request.user, 'agenda.can_manage')) - elif self.action in ('speak', 'sort_speakers', 'numbering'): + elif self.action in ('speak', 'sort_speakers', 'numbering', 'sort'): result = (has_perm(self.request.user, 'agenda.can_see') and has_perm(self.request.user, 'agenda.can_manage')) else: @@ -237,3 +237,21 @@ class ItemViewSet(ListModelMixin, RetrieveModelMixin, UpdateModelMixin, GenericV """ Item.objects.number_all(numeral_system=config['agenda_numeral_system']) return Response({'detail': _('The agenda has been numbered.')}) + + @list_route(methods=['post']) + def sort(self, request): + """ + Sort agenda items. + """ + nodes = request.data.get('nodes', []) + parent_id = request.data.get('parent_id') + items = [] + with transaction.atomic(): + for index, node in enumerate(nodes): + item = Item.objects.get(pk=node['id']) + item.parent_id = parent_id + item.weight = index + item.save(skip_autoupdate=True) + items.append(item) + inform_changed_data(items) + return Response({'detail': _('The agenda has been sorted.')})