3 if (typeof IriSP.serializers === "undefined") { |
3 if (typeof IriSP.serializers === "undefined") { |
4 IriSP.serializers = {} |
4 IriSP.serializers = {} |
5 } |
5 } |
6 |
6 |
7 IriSP.serializers.ldt_annotate = { |
7 IriSP.serializers.ldt_annotate = { |
8 types : { |
8 serializeAnnotation : function(_data, _source) { |
9 annotation : { |
9 var _annType = _data.getAnnotationType(); |
10 serialized_name : "annotations", |
10 return { |
11 serializer : function(_data, _source) { |
11 begin: _data.begin.milliseconds, |
12 var _annType = _data.getAnnotationType(); |
12 end: _data.end.milliseconds, |
13 return { |
13 content: { |
14 begin: _data.begin.milliseconds, |
14 description: _data.description, |
15 end: _data.end.milliseconds, |
15 title: _data.title, |
16 content: { |
16 audio: _data.audio |
17 data: _data.description, |
17 }, |
18 audio: _data.audio |
18 tags: _data.getTagTexts(), |
19 }, |
19 media: _data.getMedia().id, |
20 tags: _data.getTagTexts(), |
20 type_title: _annType.title, |
21 media: _data.getMedia().id, |
21 type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
22 type_title: _annType.title, |
22 meta: { |
23 type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ) |
23 created: _data.created, |
24 } |
24 creator: _data.creator |
25 } |
25 } |
26 } |
26 } |
27 }, |
27 }, |
28 serialize : function(_source) { |
28 serialize : function(_source) { |
29 var _res = {}, |
29 var _this = this |
30 _this = this; |
30 _res = { |
31 _source.forEach(function(_list, _typename) { |
31 "objects": _source.getAnnotations().map(function(_annotation) { |
32 if (typeof _this.types[_typename] !== "undefined") { |
32 return _this.serializeAnnotation(_annotation, _source); |
33 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
33 }) |
34 return _this.types[_typename].serializer(_el, _source); |
34 }; |
35 }); |
|
36 } |
|
37 }); |
|
38 _res.meta = { |
|
39 creator: _source.creator, |
|
40 created: _source.created |
|
41 } |
|
42 return JSON.stringify(_res); |
35 return JSON.stringify(_res); |
43 }, |
36 }, |
44 deSerialize : function(_data, _source) { |
37 deSerialize : function(_data, _source) { |
45 if (typeof _data == "string") { |
38 if (typeof _data == "string") { |
46 _data = JSON.parse(_data); |
39 _data = JSON.parse(_data); |
47 } |
40 } |
|
41 |
48 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
42 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
49 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
43 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
50 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
44 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
51 if (typeof _data.annotations == "object" && _data.annotations && _data.annotations.length) { |
45 IriSP._(_data.objects).each(function(_anndata) { |
52 var _anndata = _data.annotations[0], |
46 var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
53 _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
47 _ann.description = _anndata.content.description || ""; |
54 _ann.description = _anndata.content.data || ""; |
48 _ann.title = _anndata.content.title || ""; |
55 _ann.title = _data.creator || ""; |
49 _ann.creator = _anndata.meta.creator || ""; |
56 _ann.created = new Date(_data.meta.created); |
50 _ann.created = new Date(_anndata.meta.created); |
57 _ann.setMedia(_anndata.media, _source); |
51 _ann.setMedia(_anndata.media, _source); |
58 var _anntypes = _source.getAnnotationTypes(true).searchByTitle(_anndata.type_title); |
52 var _anntype = _source.getElement(_anndata.type); |
59 if (_anntypes.length) { |
53 if (!_anntype) { |
60 var _anntype = _anntypes[0]; |
54 _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
61 } else { |
|
62 var _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
63 _anntype.title = _anndata.type_title; |
55 _anntype.title = _anndata.type_title; |
64 _source.getAnnotationTypes().push(_anntype); |
56 _source.getAnnotationTypes().push(_anntype); |
65 } |
57 } |
66 _ann.setAnnotationType(_anntype.id); |
58 _ann.setAnnotationType(_anntype.id); |
67 var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
59 var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
68 var _tags = _source.getTags(true).searchByTitle(_title); |
60 var _tags = _source.getTags(true).searchByTitle(_title, true); |
69 if (_tags.length) { |
61 if (_tags.length) { |
70 var _tag = _tags[0]; |
62 var _tag = _tags[0]; |
71 } |
63 } |
72 else { |
64 else { |
73 _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
65 _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |