| author | veltr |
| Tue, 29 Jan 2013 15:38:41 +0100 | |
| changeset 991 | 2b036bd80f6d |
| parent 983 | 97fef7a4b189 |
| child 998 | 9521347ede1d |
| permissions | -rw-r--r-- |
| 868 | 1 |
/* LDT Platform Serializer */ |
2 |
||
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
3 |
if (typeof IriSP.serializers === "undefined") { |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
4 |
IriSP.serializers = {} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
5 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
6 |
|
| 868 | 7 |
IriSP.serializers.ldt = { |
| 860 | 8 |
types : { |
9 |
media : { |
|
10 |
serialized_name : "medias", |
|
| 864 | 11 |
deserializer : function(_data, _source) { |
12 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
| 866 | 13 |
_res.video = ( |
14 |
typeof _data.url !== "undefined" |
|
15 |
? _data.url |
|
16 |
: ( |
|
17 |
typeof _data.href !== "undefined" |
|
18 |
? _data.href |
|
19 |
: null |
|
20 |
) |
|
21 |
); |
|
22 |
if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
23 |
_res.streamer = _data.meta.item.value; |
|
24 |
} |
|
| 860 | 25 |
_res.title = _data.meta["dc:title"]; |
26 |
_res.description = _data.meta["dc:description"]; |
|
27 |
_res.setDuration(_data.meta["dc:duration"]); |
|
| 917 | 28 |
_res.url = _data.meta.url; |
29 |
if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") { |
|
30 |
_res.thumbnail = _data.meta.img.src; |
|
31 |
} |
|
| 860 | 32 |
return _res; |
| 858 | 33 |
}, |
| 983 | 34 |
serializer : function(_data, _source, _dest) { |
35 |
var _res = { |
|
| 916 | 36 |
id : _data.id, |
| 866 | 37 |
url : _data.video, |
| 860 | 38 |
meta : { |
| 983 | 39 |
"dc:title": _data.title || "", |
40 |
"dc:description": _data.description || "", |
|
41 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
42 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
43 |
"dc:creator" : _data.creator || _source.creator, |
|
44 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 860 | 45 |
"dc:duration" : _data.duration.milliseconds |
46 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
47 |
} |
| 983 | 48 |
_dest.medias.push(_res); |
49 |
var _list = { |
|
50 |
id: IriSP.Model.getUID(), |
|
51 |
meta : { |
|
52 |
"dc:title": _data.title || "", |
|
53 |
"dc:description": _data.description || "", |
|
54 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
55 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
56 |
"dc:creator" : _data.creator || _source.creator, |
|
57 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
58 |
"id-ref": _data.id |
|
59 |
}, |
|
60 |
items: _source.getAnnotationTypes().filter(function(_at) { |
|
61 |
return _at.media === _data; |
|
62 |
}).map(function(_at) { |
|
63 |
return { |
|
64 |
"id-ref": _at.id |
|
65 |
} |
|
66 |
}) |
|
67 |
} |
|
68 |
_dest.lists.push(_list); |
|
69 |
_dest.views[0].contents.push(_data.id); |
|
| 860 | 70 |
} |
71 |
}, |
|
72 |
tag : { |
|
73 |
serialized_name : "tags", |
|
74 |
model_name : "tag", |
|
| 864 | 75 |
deserializer : function(_data, _source) { |
76 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
| 860 | 77 |
_res.title = _data.meta["dc:title"]; |
78 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
79 |
}, |
| 983 | 80 |
serializer : function(_data, _source, _dest) { |
81 |
var _res = { |
|
| 916 | 82 |
id : _data.id, |
| 860 | 83 |
meta : { |
| 983 | 84 |
"dc:title": _data.title || "", |
85 |
"dc:description": _data.description || "", |
|
86 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
87 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
88 |
"dc:creator" : _data.creator || _source.creator, |
|
89 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 860 | 90 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
91 |
} |
| 983 | 92 |
_dest.tags.push(_res); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
93 |
} |
| 860 | 94 |
}, |
| 864 | 95 |
annotationType : { |
| 860 | 96 |
serialized_name : "annotation-types", |
| 864 | 97 |
deserializer : function(_data, _source) { |
98 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
| 860 | 99 |
_res.title = _data["dc:title"]; |
100 |
_res.description = _data["dc:description"]; |
|
101 |
return _res; |
|
102 |
}, |
|
| 983 | 103 |
serializer : function(_data, _source, _dest) { |
104 |
var _res = { |
|
| 916 | 105 |
id : _data.id, |
| 983 | 106 |
"dc:title": _data.title || "", |
107 |
"dc:description": _data.description || "", |
|
108 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
109 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
110 |
"dc:creator" : _data.creator || _source.creator, |
|
111 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 860 | 112 |
} |
| 983 | 113 |
_dest["annotation-types"].push(_res); |
114 |
_dest.views[0].annotation_types.push(_data.id); |
|
| 860 | 115 |
} |
116 |
}, |
|
117 |
annotation : { |
|
118 |
serialized_name : "annotations", |
|
| 864 | 119 |
deserializer : function(_data, _source) { |
120 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
121 |
_res.title = _data.content.title || ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
122 |
_res.description = _data.content.description || ""; |
| 876 | 123 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
124 |
_res.thumbnail = _data.content.img.src; |
|
125 |
} |
|
| 860 | 126 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
127 |
if (typeof _data.color !== "undefined") { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
128 |
var _c = parseInt(_data.color).toString(16); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
129 |
while (_c.length < 6) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
130 |
_c = '0' + _c; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
131 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
132 |
_res.color = '#' + _c; |
| 860 | 133 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
134 |
_res.setMedia(_data.media); |
| 860 | 135 |
_res.setAnnotationType(_data.meta["id-ref"]); |
136 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
| 983 | 137 |
_res.keywords = _res.getTagTexts(); |
| 860 | 138 |
_res.setBegin(_data.begin); |
139 |
_res.setEnd(_data.end); |
|
| 876 | 140 |
_res.creator = _data.meta["dc:creator"] || ""; |
141 |
_res.project = _data.meta.project || ""; |
|
| 880 | 142 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
143 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
144 |
} |
|
| 914 | 145 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
146 |
_res.audio = _data.content.audio; |
|
| 913 | 147 |
} |
| 860 | 148 |
return _res; |
149 |
}, |
|
| 983 | 150 |
serializer : function(_data, _source, _dest) { |
151 |
var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
|
152 |
var _res = { |
|
| 916 | 153 |
id : _data.id, |
| 904 | 154 |
begin : _data.begin.milliseconds, |
155 |
end : _data.end.milliseconds, |
|
| 860 | 156 |
content : { |
| 983 | 157 |
title : _data.title || "", |
158 |
description : _data.description || "", |
|
159 |
audio : _data.audio, |
|
160 |
img: { |
|
161 |
src: _data.thumbnail |
|
162 |
} |
|
| 860 | 163 |
}, |
| 983 | 164 |
color: _color, |
| 916 | 165 |
media : _data.media.id, |
| 860 | 166 |
meta : { |
| 983 | 167 |
"id-ref" : _data.getAnnotationType().id, |
168 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
169 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
170 |
"dc:creator" : _data.creator || _source.creator, |
|
171 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
172 |
// project : _source.projectId |
|
| 860 | 173 |
}, |
| 904 | 174 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
| 860 | 175 |
return { |
| 916 | 176 |
"id-ref" : _id |
| 860 | 177 |
} |
| 914 | 178 |
}) |
| 860 | 179 |
} |
| 983 | 180 |
_dest.annotations.push(_res); |
| 860 | 181 |
} |
| 900 | 182 |
}, |
183 |
mashup : { |
|
| 919 | 184 |
serialized_name : "lists", |
| 900 | 185 |
deserializer : function(_data, _source) { |
| 919 | 186 |
if (typeof _data.meta !== "object" || typeof _data.meta.listtype !== "string" || _data.meta.listtype !== "mashup") { |
187 |
return undefined; |
|
188 |
} |
|
| 900 | 189 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
190 |
_res.title = _data.meta["dc:title"]; |
|
191 |
_res.description = _data.meta["dc:description"]; |
|
| 983 | 192 |
_res.creator = _data.meta["dc:creator"]; |
193 |
_res.setAnnotationsById(_data.items); |
|
| 900 | 194 |
return _res; |
195 |
}, |
|
| 983 | 196 |
serializer : function(_data, _source, _dest) { |
197 |
var _res = { |
|
| 919 | 198 |
meta : { |
| 983 | 199 |
"dc:title": _data.title || "", |
200 |
"dc:description": _data.description || "", |
|
201 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
202 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
203 |
"dc:creator" : _data.creator || _source.creator, |
|
204 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 919 | 205 |
listtype: "mashup" |
206 |
}, |
|
207 |
items: _data.segments.map(function(_annotation) { |
|
| 983 | 208 |
return _annotation.annotation.id; |
| 919 | 209 |
}), |
210 |
id: _data.id |
|
| 900 | 211 |
} |
| 983 | 212 |
_dest.lists.push(_res); |
| 900 | 213 |
} |
| 860 | 214 |
} |
215 |
}, |
|
| 864 | 216 |
serialize : function(_source) { |
| 983 | 217 |
var _res = { |
218 |
meta: { |
|
219 |
"dc:creator": _source.creator, |
|
220 |
"dc:contributor" : _source.contributor || _source.creator, |
|
221 |
"dc:created": IriSP.Model.dateToIso(_source.created), |
|
222 |
"dc:modified" : IriSP.Model.dateToIso(_source.modified), |
|
223 |
"dc:title": _source.title || "", |
|
224 |
"dc:description": _source.description || "", |
|
225 |
id: _source.projectId || _source.id |
|
226 |
}, |
|
227 |
views: [ |
|
228 |
{ |
|
229 |
id: IriSP.Model.getUID(), |
|
230 |
contents: [], |
|
231 |
annotation_types: [] |
|
232 |
} |
|
233 |
], |
|
234 |
lists: [], |
|
235 |
"annotation-types": [], |
|
236 |
medias: [], |
|
237 |
tags: [], |
|
238 |
annotations: [] |
|
239 |
}, |
|
| 860 | 240 |
_this = this; |
| 866 | 241 |
_source.forEach(function(_list, _typename) { |
| 864 | 242 |
if (typeof _this.types[_typename] !== "undefined") { |
| 983 | 243 |
_list.forEach(function(_el) { |
244 |
_this.types[_typename].serializer(_el, _source, _res); |
|
| 864 | 245 |
}); |
246 |
} |
|
| 860 | 247 |
}); |
| 904 | 248 |
return JSON.stringify(_res); |
| 860 | 249 |
}, |
| 864 | 250 |
deSerialize : function(_data, _source) { |
| 882 | 251 |
if (typeof _data !== "object" || _data === null) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
252 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
253 |
} |
| 866 | 254 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 916 | 255 |
var _listdata = _data[_type.serialized_name], |
256 |
_list = new IriSP.Model.List(_source.directory); |
|
| 882 | 257 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
| 864 | 258 |
if (_listdata.hasOwnProperty("length")) { |
259 |
var _l = _listdata.length; |
|
260 |
for (var _i = 0; _i < _l; _i++) { |
|
| 919 | 261 |
var _element = _type.deserializer(_listdata[_i], _source); |
262 |
if (typeof _element !== "undefined" && _element) { |
|
263 |
_list.push(_element); |
|
264 |
} |
|
| 864 | 265 |
} |
266 |
} else { |
|
| 919 | 267 |
var _element = _type.deserializer(_listdata, _source); |
268 |
if (typeof _element !== "undefined" && _element) { |
|
269 |
_list.push(_element); |
|
270 |
} |
|
| 864 | 271 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
272 |
} |
| 916 | 273 |
_source.addList(_typename, _list); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
274 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
275 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
276 |
if (typeof _data.meta !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
277 |
_source.projectId = _data.meta.id; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
278 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
279 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
280 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 957 | 281 |
_source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
282 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
283 |
} |
| 868 | 284 |
} |
285 |