| author | durandn |
| Fri, 03 Jul 2015 16:48:41 +0200 | |
| changeset 1035 | c1bc8a2b1468 |
| parent 1013 | 392ddcd212d7 |
| child 1045 | b06345320ffb |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* ldt_annotate serializer: Used when Putting annotations on the platform */ |
| 904 | 2 |
|
3 |
if (typeof IriSP.serializers === "undefined") { |
|
| 998 | 4 |
IriSP.serializers = {}; |
| 904 | 5 |
} |
6 |
||
7 |
IriSP.serializers.ldt_annotate = { |
|
| 974 | 8 |
serializeAnnotation : function(_data, _source) { |
9 |
var _annType = _data.getAnnotationType(); |
|
10 |
return { |
|
11 |
begin: _data.begin.milliseconds, |
|
12 |
end: _data.end.milliseconds, |
|
13 |
content: { |
|
| 975 | 14 |
description: _data.description, |
15 |
title: _data.title, |
|
| 974 | 16 |
audio: _data.audio |
17 |
}, |
|
18 |
tags: _data.getTagTexts(), |
|
19 |
media: _data.getMedia().id, |
|
|
1035
c1bc8a2b1468
Allow the annotation serializer to extract project_id for use in some widget when it is provided in the data
durandn
parents:
1013
diff
changeset
|
20 |
project: _data.project_id, |
| 974 | 21 |
type_title: _annType.title, |
22 |
type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
|
23 |
meta: { |
|
24 |
created: _data.created, |
|
25 |
creator: _data.creator |
|
| 904 | 26 |
} |
| 1013 | 27 |
}; |
| 904 | 28 |
}, |
| 979 | 29 |
deserializeAnnotation : function(_anndata, _source) { |
30 |
var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
31 |
_ann.description = _anndata.content.description || ""; |
|
32 |
_ann.title = _anndata.content.title || ""; |
|
33 |
_ann.creator = _anndata.meta.creator || ""; |
|
34 |
_ann.created = new Date(_anndata.meta.created); |
|
35 |
_ann.setMedia(_anndata.media, _source); |
|
36 |
var _anntype = _source.getElement(_anndata.type); |
|
37 |
if (!_anntype) { |
|
38 |
_anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
39 |
_anntype.title = _anndata.type_title; |
|
40 |
_source.getAnnotationTypes().push(_anntype); |
|
41 |
} |
|
42 |
_ann.setAnnotationType(_anntype.id); |
|
43 |
var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
44 |
var _tags = _source.getTags(true).searchByTitle(_title, true); |
|
45 |
if (_tags.length) { |
|
46 |
var _tag = _tags[0]; |
|
47 |
} |
|
48 |
else { |
|
49 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
50 |
_tag.title = _title; |
|
51 |
_source.getTags().push(_tag); |
|
52 |
} |
|
53 |
return _tag.id; |
|
54 |
}); |
|
55 |
_ann.setTags(_tagIds); |
|
56 |
_ann.setBegin(_anndata.begin); |
|
57 |
_ann.setEnd(_anndata.end); |
|
58 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
59 |
_ann.audio = _anndata.content.audio; |
|
60 |
} |
|
61 |
_source.getAnnotations().push(_ann); |
|
62 |
}, |
|
| 904 | 63 |
serialize : function(_source) { |
| 979 | 64 |
return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
65 |
}, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
66 |
deSerialize : function(_data, _source) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
67 |
if (typeof _data == "string") { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
68 |
_data = JSON.parse(_data); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
69 |
} |
| 974 | 70 |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
71 |
_source.addList('tag', new IriSP.Model.List(_source.directory)); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
72 |
_source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
73 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
| 979 | 74 |
this.deserializeAnnotation(_data, _source); |
| 904 | 75 |
} |
| 998 | 76 |
}; |
77 |
||
78 |
/* End ldt_annotate serializer */ |