add/remove annotations

This commit is contained in:
j 2011-02-11 20:16:21 +05:30
parent 866d60b467
commit 283e8663f3
2 changed files with 31 additions and 5 deletions

View file

@ -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']

View file

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