forked from 0x2620/pandora
add/remove annotations
This commit is contained in:
parent
b13c43c832
commit
8d6cf495f7
2 changed files with 31 additions and 5 deletions
|
@ -2,6 +2,7 @@
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
|
import ox
|
||||||
from ox.utils import json
|
from ox.utils import json
|
||||||
from ox.django.decorators import login_required_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
|
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
|
@login_required_json
|
||||||
def removeAnnotation(request):
|
def removeAnnotations(request):
|
||||||
'''
|
'''
|
||||||
param data {
|
param data {
|
||||||
id:
|
ids: []
|
||||||
}
|
}
|
||||||
return {'status': {'code': int, 'text': string},
|
return {'status': {'code': int, 'text': string},
|
||||||
'data': {
|
'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)
|
return render_to_json_response(response)
|
||||||
actions.register(removeAnnotation, cache=False)
|
actions.register(removeAnnotations, cache=False)
|
||||||
|
|
||||||
|
|
||||||
@login_required_json
|
@login_required_json
|
||||||
|
@ -112,7 +124,7 @@ def editAnnotation(request):
|
||||||
'''
|
'''
|
||||||
response = json_response({})
|
response = json_response({})
|
||||||
data = json.loads(request.POST['data'])
|
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):
|
if a.editable(request.user):
|
||||||
a.value = data['value']
|
a.value = data['value']
|
||||||
a.start = data['in']
|
a.start = data['in']
|
||||||
|
|
|
@ -1824,6 +1824,20 @@
|
||||||
togglesize: function(event, data) {
|
togglesize: function(event, data) {
|
||||||
UI.set({videoSize: data.size});
|
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) {
|
updateAnnotation: function(event, data) {
|
||||||
//fixme: check that edit was successfull
|
//fixme: check that edit was successfull
|
||||||
Ox.print('updateAnnotation', data);
|
Ox.print('updateAnnotation', data);
|
||||||
|
|
Loading…
Reference in a new issue