6 |
6 |
7 IriSP.serializers.ldt_annotate = { |
7 IriSP.serializers.ldt_annotate = { |
8 serializeAnnotation : function(_data, _source) { |
8 serializeAnnotation : function(_data, _source) { |
9 var _annType = _data.getAnnotationType(); |
9 var _annType = _data.getAnnotationType(); |
10 return { |
10 return { |
|
11 id: _data.id, |
11 begin: _data.begin.milliseconds, |
12 begin: _data.begin.milliseconds, |
12 end: _data.end.milliseconds, |
13 end: _data.end.milliseconds, |
13 content: { |
14 content: { |
|
15 data: (_data.content ? _data.content.data || {} : {}), |
14 description: _data.description, |
16 description: _data.description, |
15 title: _data.title, |
17 title: _data.title, |
16 audio: _data.audio |
18 audio: _data.audio |
17 }, |
19 }, |
18 id: _data.id ? _data.id : "", // If annotation is new, id will be undefined |
20 id: _data.id ? _data.id : "", // If annotation is new, id will be undefined |
21 project: _data.project_id, |
23 project: _data.project_id, |
22 type_title: _annType.title, |
24 type_title: _annType.title, |
23 type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
25 type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
24 meta: { |
26 meta: { |
25 created: _data.created, |
27 created: _data.created, |
26 creator: _data.creator |
28 creator: _data.creator, |
|
29 modified: _data.modified, |
|
30 contributor: _data.contributor |
27 } |
31 } |
28 }; |
32 }; |
29 }, |
33 }, |
30 deserializeAnnotation : function(_anndata, _source) { |
34 deserializeAnnotation : function(_anndata, _source) { |
31 var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
35 var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
52 _source.getTags().push(_tag); |
56 _source.getTags().push(_tag); |
53 } |
57 } |
54 return _tag.id; |
58 return _tag.id; |
55 }); |
59 }); |
56 _ann.setTags(_tagIds); |
60 _ann.setTags(_tagIds); |
57 _ann.setBegin(_anndata.begin); |
61 _ann.setBeginEnd(_anndata.begin, _anndata.end); |
58 _ann.setEnd(_anndata.end); |
|
59 if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
62 if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
60 _ann.audio = _anndata.content.audio; |
63 _ann.audio = _anndata.content.audio; |
61 } |
64 }; |
|
65 if (_anndata.content.data) { |
|
66 _ann.content = { data: _anndata.content.data }; |
|
67 }; |
62 _source.getAnnotations().push(_ann); |
68 _source.getAnnotations().push(_ann); |
63 }, |
69 }, |
64 serialize : function(_source) { |
70 serialize : function(_source) { |
65 return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
71 return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
66 }, |
72 }, |
67 deSerialize : function(_data, _source) { |
73 deSerialize : function(_data, _source) { |
68 if (typeof _data == "string") { |
74 if (typeof _data == "string") { |
69 _data = JSON.parse(_data); |
75 _data = JSON.parse(_data); |
70 } |
76 } |
71 |
77 |
72 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
78 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
73 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
79 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
74 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
80 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
75 this.deserializeAnnotation(_data, _source); |
81 this.deserializeAnnotation(_data, _source); |
76 } |
82 } |