| author | ymh <ymh.work@gmail.com> |
| Fri, 02 Oct 2015 11:27:17 +0200 | |
| changeset 1068 | 7623f9af9272 |
| parent 1045 | b06345320ffb |
| child 1072 | ac1eacb3aa33 |
| 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 { |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
11 |
id: _data.id, |
| 974 | 12 |
begin: _data.begin.milliseconds, |
13 |
end: _data.end.milliseconds, |
|
14 |
content: { |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
15 |
data: (_data.content ? _data.content.data || {} : {}), |
| 975 | 16 |
description: _data.description, |
17 |
title: _data.title, |
|
| 974 | 18 |
audio: _data.audio |
19 |
}, |
|
|
1045
b06345320ffb
Altered ldt_annotate serializer to allow for serializing id for editing annotation + Added Markers widget that allows to make and edit 0 duration annotations.
durandn
parents:
1035
diff
changeset
|
20 |
id: _data.id ? _data.id : "", // If annotation is new, id will be undefined |
| 974 | 21 |
tags: _data.getTagTexts(), |
22 |
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
|
23 |
project: _data.project_id, |
| 974 | 24 |
type_title: _annType.title, |
25 |
type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
|
26 |
meta: { |
|
27 |
created: _data.created, |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
28 |
creator: _data.creator, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
29 |
modified: _data.modified, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
30 |
contributor: _data.contributor |
| 904 | 31 |
} |
| 1013 | 32 |
}; |
| 904 | 33 |
}, |
| 979 | 34 |
deserializeAnnotation : function(_anndata, _source) { |
35 |
var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
36 |
_ann.description = _anndata.content.description || ""; |
|
37 |
_ann.title = _anndata.content.title || ""; |
|
38 |
_ann.creator = _anndata.meta.creator || ""; |
|
39 |
_ann.created = new Date(_anndata.meta.created); |
|
40 |
_ann.setMedia(_anndata.media, _source); |
|
41 |
var _anntype = _source.getElement(_anndata.type); |
|
42 |
if (!_anntype) { |
|
43 |
_anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
44 |
_anntype.title = _anndata.type_title; |
|
45 |
_source.getAnnotationTypes().push(_anntype); |
|
46 |
} |
|
47 |
_ann.setAnnotationType(_anntype.id); |
|
48 |
var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
49 |
var _tags = _source.getTags(true).searchByTitle(_title, true); |
|
50 |
if (_tags.length) { |
|
51 |
var _tag = _tags[0]; |
|
52 |
} |
|
53 |
else { |
|
54 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
55 |
_tag.title = _title; |
|
56 |
_source.getTags().push(_tag); |
|
57 |
} |
|
58 |
return _tag.id; |
|
59 |
}); |
|
60 |
_ann.setTags(_tagIds); |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
61 |
_ann.setBeginEnd(_anndata.begin, _anndata.end); |
| 979 | 62 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
63 |
_ann.audio = _anndata.content.audio; |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
64 |
}; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
65 |
if (_anndata.content.data) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
66 |
_ann.content = { data: _anndata.content.data }; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
67 |
}; |
| 979 | 68 |
_source.getAnnotations().push(_ann); |
69 |
}, |
|
| 904 | 70 |
serialize : function(_source) { |
| 979 | 71 |
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
|
72 |
}, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
73 |
deSerialize : function(_data, _source) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
74 |
if (typeof _data == "string") { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
75 |
_data = JSON.parse(_data); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
76 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
77 |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
78 |
_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
|
79 |
_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
|
80 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
| 979 | 81 |
this.deserializeAnnotation(_data, _source); |
| 904 | 82 |
} |
| 998 | 83 |
}; |
84 |
||
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
85 |
/* End ldt_annotate serializer */ |