|
1 if (typeof IriSP.serializers === "undefined") { |
|
2 IriSP.serializers = {} |
|
3 } |
|
4 |
|
5 IriSP.serializers.cinecast = { |
|
6 types : { |
|
7 media : { |
|
8 serialized_name : "medias", |
|
9 model_name : "media", |
|
10 deserializer : function(_data, _source) { |
|
11 var _res = new IriSP.Model.Media(_data.id, _source); |
|
12 _res.url = _data.href; |
|
13 _res.title = _data.meta.title; |
|
14 _res.description = _data.meta.synopsis; |
|
15 _res.setDuration(_data.meta.duration); |
|
16 return _res; |
|
17 }, |
|
18 serializer : function(_data, _source) { |
|
19 return { |
|
20 id : _source.unNamespace(_data.id), |
|
21 url : _data.url, |
|
22 meta : { |
|
23 title : _data.title, |
|
24 synopsis : _data.description, |
|
25 duration : _data.duration.milliseconds |
|
26 } |
|
27 } |
|
28 } |
|
29 }, |
|
30 tag : { |
|
31 serialized_name : "tags", |
|
32 model_name : "tag", |
|
33 deserializer : function(_data, _source) { |
|
34 var _res = new IriSP.Model.Tag(_data.id, _source); |
|
35 _res.title = _data.meta.description; |
|
36 return _res; |
|
37 }, |
|
38 serializer : function(_data, _source) { |
|
39 return { |
|
40 id : _source.unNamespace(_data.id), |
|
41 meta : { |
|
42 description : _data.title |
|
43 } |
|
44 } |
|
45 } |
|
46 }, |
|
47 annotationType : { |
|
48 serialized_name : "annotation_types", |
|
49 deserializer : function(_data, _source) { |
|
50 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
51 _res.title = _source.getNamespaced(_data.id).name; |
|
52 _res.description = _data.meta.description; |
|
53 return _res; |
|
54 }, |
|
55 serializer : function(_data, _source) { |
|
56 return { |
|
57 id : _source.unNamespace(_data.id), |
|
58 meta : { |
|
59 description : _data.description |
|
60 } |
|
61 } |
|
62 } |
|
63 }, |
|
64 annotation : { |
|
65 serialized_name : "annotations", |
|
66 deserializer : function(_data, _source) { |
|
67 var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
68 _res.title = _data.meta.creator_name; |
|
69 _res.description = _data.content.data; |
|
70 _res.created = IriSP.Model.isoToDate(_data.meta.created); |
|
71 var _c = parseInt(_data.color).toString(16); |
|
72 while (_c.length < 6) { |
|
73 _c = '0' + _c; |
|
74 } |
|
75 _res.color = '#' + _c; |
|
76 _res.setMedia(_data.media, _source); |
|
77 _res.setAnnotationType(_data.type); |
|
78 _res.setTags(IriSP._(_data.tags).map(function(_t) { |
|
79 if (typeof _source.contents.tag === "undefined") { |
|
80 _source.contents.tag = new IriSP.Model.List(_source.directory); |
|
81 } |
|
82 if (_source.contents.tag.hasId(_t)) { |
|
83 return _t; |
|
84 } else { |
|
85 var _id = _t.toLowerCase() |
|
86 .replace(/#/g,'') |
|
87 .replace(/^(\d)/,'_$1') |
|
88 .replace(/[áâäàã]/g,'a') |
|
89 .replace(/ç/g,'c') |
|
90 .replace(/[éèêë]/g,'e') |
|
91 .replace(/[íìîï]/g,'i') |
|
92 .replace(/ñ/g,'n') |
|
93 .replace(/[óòôöõ]/g,'o') |
|
94 .replace(/œ/g,'oe') |
|
95 .replace(/[úùûü]/g,'u') |
|
96 .replace(/ÿ/g,'y') |
|
97 .replace(/[^A-Za-z0-9_]/g,''), |
|
98 _tag = new IriSP.Model.Tag(_id, _source); |
|
99 _tag.title = _t; |
|
100 _source.contents.tag.addElement(_tag); |
|
101 return _id; |
|
102 } |
|
103 })); |
|
104 _res.setBegin(_data.begin); |
|
105 _res.setEnd(_data.end); |
|
106 _res.creator = _data.meta.creator; |
|
107 return _res; |
|
108 }, |
|
109 serializer : function(_data, _source) { |
|
110 return { |
|
111 id : _source.unNamespace(_data.id), |
|
112 content : { |
|
113 data : _data.description |
|
114 }, |
|
115 begin : _data.begin.milliseconds, |
|
116 end : _data.begin.milliseconds, |
|
117 media : _source.unNamespace(_data.media.contents), |
|
118 type : _source.unNamespace(_data.annotationType.contents), |
|
119 meta : { |
|
120 created : IriSP.Model.dateToIso(_data.created), |
|
121 creator : _data.creator, |
|
122 creator_name : _data.title |
|
123 }, |
|
124 tags : _data.getTags().map(function(_el) { |
|
125 return _source.unNamespace(_el.id) |
|
126 }) |
|
127 } |
|
128 } |
|
129 } |
|
130 }, |
|
131 serialize : function(_source) { |
|
132 var _res = { |
|
133 format : "http://advene.org/ns/cinelab/" |
|
134 }, |
|
135 _this = this, |
|
136 _nsls = _source.listNamespaces(true); |
|
137 _res.imports = []; |
|
138 for (var _i = 0; _i < _nsls.length; _i++) { |
|
139 if (typeof _source.directory.namespaces[_nsls[_i]] !== "undefined") { |
|
140 _res.imports.push({ |
|
141 id : _nsls[_i], |
|
142 url : _source.directory.namespaces[_nsls[_i]] |
|
143 }) |
|
144 } |
|
145 } |
|
146 _source.each(function(_list, _typename) { |
|
147 if (typeof _this.types[_typename] !== "undefined") { |
|
148 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
149 return _this.types[_typename].serializer(_el, _source); |
|
150 }); |
|
151 } |
|
152 }); |
|
153 return _res; |
|
154 }, |
|
155 deSerialize : function(_data, _source) { |
|
156 if (typeof _data.imports !== "undefined") { |
|
157 IriSP._(_data.imports).each(function(_import) { |
|
158 _source.directory.namespaces[_import.id] = _import.url; |
|
159 }) |
|
160 } |
|
161 IriSP._(this.types).each(function(_type, _typename) { |
|
162 var _listdata = _data[_type.serialized_name]; |
|
163 if (typeof _listdata !== "undefined") { |
|
164 var _list = new IriSP.Model.List(_source.directory); |
|
165 if (_listdata.hasOwnProperty("length")) { |
|
166 var _l = _listdata.length; |
|
167 for (var _i = 0; _i < _l; _i++) { |
|
168 _list.addElement(_type.deserializer(_listdata[_i], _source)); |
|
169 } |
|
170 } else { |
|
171 _list.addElement(_type.deserializer(_listdata, _source)); |
|
172 } |
|
173 _source.addList(_typename, _list); |
|
174 } |
|
175 }); |
|
176 |
|
177 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
178 _source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
179 } |
|
180 _source.setDefaultCurrentMedia(); |
|
181 } |
|
182 } |