23 created: _data.created, |
23 created: _data.created, |
24 creator: _data.creator |
24 creator: _data.creator |
25 } |
25 } |
26 } |
26 } |
27 }, |
27 }, |
|
28 deserializeAnnotation : function(_anndata, _source) { |
|
29 var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
30 _ann.description = _anndata.content.description || ""; |
|
31 _ann.title = _anndata.content.title || ""; |
|
32 _ann.creator = _anndata.meta.creator || ""; |
|
33 _ann.created = new Date(_anndata.meta.created); |
|
34 _ann.setMedia(_anndata.media, _source); |
|
35 var _anntype = _source.getElement(_anndata.type); |
|
36 if (!_anntype) { |
|
37 _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
38 _anntype.title = _anndata.type_title; |
|
39 _source.getAnnotationTypes().push(_anntype); |
|
40 } |
|
41 _ann.setAnnotationType(_anntype.id); |
|
42 var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
43 var _tags = _source.getTags(true).searchByTitle(_title, true); |
|
44 if (_tags.length) { |
|
45 var _tag = _tags[0]; |
|
46 } |
|
47 else { |
|
48 _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
49 _tag.title = _title; |
|
50 _source.getTags().push(_tag); |
|
51 } |
|
52 return _tag.id; |
|
53 }); |
|
54 _ann.setTags(_tagIds); |
|
55 _ann.setBegin(_anndata.begin); |
|
56 _ann.setEnd(_anndata.end); |
|
57 if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
58 _ann.audio = _anndata.content.audio; |
|
59 } |
|
60 _source.getAnnotations().push(_ann); |
|
61 }, |
28 serialize : function(_source) { |
62 serialize : function(_source) { |
29 var _this = this |
63 return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
30 _res = { |
|
31 "objects": _source.getAnnotations().map(function(_annotation) { |
|
32 return _this.serializeAnnotation(_annotation, _source); |
|
33 }) |
|
34 }; |
|
35 return JSON.stringify(_res); |
|
36 }, |
64 }, |
37 deSerialize : function(_data, _source) { |
65 deSerialize : function(_data, _source) { |
38 if (typeof _data == "string") { |
66 if (typeof _data == "string") { |
39 _data = JSON.parse(_data); |
67 _data = JSON.parse(_data); |
40 } |
68 } |
41 |
69 |
42 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
70 _source.addList('tag', new IriSP.Model.List(_source.directory)); |
43 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
71 _source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
44 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
72 _source.addList('annotation', new IriSP.Model.List(_source.directory)); |
45 IriSP._(_data.objects).each(function(_anndata) { |
73 this.deserializeAnnotation(_data, _source); |
46 var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
47 _ann.description = _anndata.content.description || ""; |
|
48 _ann.title = _anndata.content.title || ""; |
|
49 _ann.creator = _anndata.meta.creator || ""; |
|
50 _ann.created = new Date(_anndata.meta.created); |
|
51 _ann.setMedia(_anndata.media, _source); |
|
52 var _anntype = _source.getElement(_anndata.type); |
|
53 if (!_anntype) { |
|
54 _anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
55 _anntype.title = _anndata.type_title; |
|
56 _source.getAnnotationTypes().push(_anntype); |
|
57 } |
|
58 _ann.setAnnotationType(_anntype.id); |
|
59 var _tagIds = IriSP._(_anndata.tags).map(function(_title) { |
|
60 var _tags = _source.getTags(true).searchByTitle(_title, true); |
|
61 if (_tags.length) { |
|
62 var _tag = _tags[0]; |
|
63 } |
|
64 else { |
|
65 _tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
66 _tag.title = _title; |
|
67 _source.getTags().push(_tag); |
|
68 } |
|
69 return _tag.id; |
|
70 }); |
|
71 _ann.setTags(_tagIds); |
|
72 _ann.setBegin(_anndata.begin); |
|
73 _ann.setEnd(_anndata.end); |
|
74 if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
|
75 _ann.audio = _anndata.content.audio; |
|
76 } |
|
77 _source.getAnnotations().push(_ann); |
|
78 }); |
|
79 } |
74 } |
80 } |
75 } |