From 8d6cf495f7e5ba6c406e2c2012bd74051d7a705e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Feb 2011 20:16:21 +0530 Subject: [PATCH] add/remove annotations --- pandora/annotation/views.py | 22 +++++++++++++++++----- static/js/pandora.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/pandora/annotation/views.py b/pandora/annotation/views.py index c60266c04..20a6938b0 100644 --- a/pandora/annotation/views.py +++ b/pandora/annotation/views.py @@ -2,6 +2,7 @@ # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division +import ox from ox.utils import json from ox.django.decorators import login_required_json from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response @@ -81,19 +82,30 @@ actions.register(addAnnotation, cache=False) @login_required_json -def removeAnnotation(request): +def removeAnnotations(request): ''' param data { - id: + ids: [] } return {'status': {'code': int, 'text': string}, 'data': { } } ''' - response = {'status': {'code': 501, 'text': 'not implemented'}} + response = json_response({}) + data = json.loads(request.POST['data']) + ids = map(ox.from32, data['ids']) + failed = [] + for a in models.Annotation.objects.filter(id__in=ids): + if a.editable(request.user): + a.delete() + else: + failed.append(a.get_id) + if failed: + response = json_response(status=403, text='permission denied') + response['data']['ids'] = failed return render_to_json_response(response) -actions.register(removeAnnotation, cache=False) +actions.register(removeAnnotations, cache=False) @login_required_json @@ -112,7 +124,7 @@ def editAnnotation(request): ''' response = json_response({}) data = json.loads(request.POST['data']) - a = get_object_or_404_json(models.Annotation, pk=data['id']) + a = get_object_or_404_json(models.Annotation, pk=ox.from32(data['id'])) if a.editable(request.user): a.value = data['value'] a.start = data['in'] diff --git a/static/js/pandora.js b/static/js/pandora.js index edd7c6ac7..2ccf8e1d7 100755 --- a/static/js/pandora.js +++ b/static/js/pandora.js @@ -1824,6 +1824,20 @@ togglesize: function(event, data) { UI.set({videoSize: data.size}); }, + addAnnotation: function(event, data) { + Ox.print('addAnnotation', data); + data.item = app.user.ui.item; + data.value = 'Click to change text'; + pandora.api.addAnnotation(data, function(result) { + app.$ui.editor.addAnnotation(data.layer, result.data.annotation); + }); + }, + removeAnnotations: function(event, data) { + pandora.api.removeAnnotations(data, function(result) { + //fixme: check for errors + app.$ui.editor.removeAnnotations(data.layer, data.ids); + }); + }, updateAnnotation: function(event, data) { //fixme: check that edit was successfull Ox.print('updateAnnotation', data);