Added server side sort view for agenda items. See #2452.

This commit is contained in:
Norman Jäckel 2017-02-01 14:23:59 +01:00
parent bcff33330c
commit 8c53b53a9d
2 changed files with 20 additions and 4 deletions

View File

@ -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});
}
};
}

View File

@ -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.')})