| author | durandn |
| Fri, 03 Jul 2015 16:54:26 +0200 | |
| changeset 1036 | 3b88465041d6 |
| parent 1032 | 74ac0be7655c |
| child 1068 | 7623f9af9272 |
| permissions | -rw-r--r-- |
| 1015 | 1 |
/* Start ldt-serializer.js */ |
| 868 | 2 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
3 |
if (typeof IriSP.serializers === "undefined") { |
| 998 | 4 |
IriSP.serializers = {}; |
|
856
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 |
} |
|
| 1013 | 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) { |
|
| 1002 | 61 |
switch (typeof _at.media) { |
62 |
case "object": |
|
63 |
return (_at.media === _data); |
|
64 |
case "string": |
|
65 |
return (_at.media === _data.id); |
|
66 |
default: |
|
67 |
var _ann = _at.getAnnotations(); |
|
68 |
if (_ann) { |
|
69 |
for (var i = 0; i < _ann.length; i++) { |
|
70 |
if (_ann[i].getMedia() === _data) { |
|
71 |
return true; |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
return false; |
|
| 983 | 77 |
}).map(function(_at) { |
78 |
return { |
|
79 |
"id-ref": _at.id |
|
| 1013 | 80 |
}; |
| 983 | 81 |
}) |
| 1013 | 82 |
}; |
| 983 | 83 |
_dest.lists.push(_list); |
84 |
_dest.views[0].contents.push(_data.id); |
|
| 860 | 85 |
} |
86 |
}, |
|
87 |
tag : { |
|
88 |
serialized_name : "tags", |
|
| 864 | 89 |
deserializer : function(_data, _source) { |
90 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
| 860 | 91 |
_res.title = _data.meta["dc:title"]; |
92 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
93 |
}, |
| 983 | 94 |
serializer : function(_data, _source, _dest) { |
| 1002 | 95 |
if (_source.regenerateTags && !_data.regenerated) { |
96 |
return; |
|
97 |
} |
|
| 983 | 98 |
var _res = { |
| 916 | 99 |
id : _data.id, |
| 860 | 100 |
meta : { |
| 983 | 101 |
"dc:title": _data.title || "", |
102 |
"dc:description": _data.description || "", |
|
103 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
104 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
105 |
"dc:creator" : _data.creator || _source.creator, |
|
|
1032
74ac0be7655c
small corrections to allow js compilation
ymh <ymh.work@gmail.com>
parents:
1015
diff
changeset
|
106 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator |
| 860 | 107 |
} |
| 1013 | 108 |
}; |
| 983 | 109 |
_dest.tags.push(_res); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
110 |
} |
| 860 | 111 |
}, |
| 864 | 112 |
annotationType : { |
| 860 | 113 |
serialized_name : "annotation-types", |
| 864 | 114 |
deserializer : function(_data, _source) { |
115 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
| 860 | 116 |
_res.title = _data["dc:title"]; |
117 |
_res.description = _data["dc:description"]; |
|
118 |
return _res; |
|
119 |
}, |
|
| 983 | 120 |
serializer : function(_data, _source, _dest) { |
121 |
var _res = { |
|
| 916 | 122 |
id : _data.id, |
| 983 | 123 |
"dc:title": _data.title || "", |
124 |
"dc:description": _data.description || "", |
|
125 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
126 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
127 |
"dc:creator" : _data.creator || _source.creator, |
|
|
1032
74ac0be7655c
small corrections to allow js compilation
ymh <ymh.work@gmail.com>
parents:
1015
diff
changeset
|
128 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator |
| 1013 | 129 |
}; |
| 983 | 130 |
_dest["annotation-types"].push(_res); |
131 |
_dest.views[0].annotation_types.push(_data.id); |
|
| 860 | 132 |
} |
133 |
}, |
|
134 |
annotation : { |
|
135 |
serialized_name : "annotations", |
|
| 864 | 136 |
deserializer : function(_data, _source) { |
137 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
138 |
_res.title = _data.content.title || ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
139 |
_res.description = _data.content.description || ""; |
| 876 | 140 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
141 |
_res.thumbnail = _data.content.img.src; |
|
142 |
} |
|
|
1036
3b88465041d6
Annotations creation date is now the actual annotation creation date instead of the ensemble creation date
durandn
parents:
1032
diff
changeset
|
143 |
_res.created = IriSP.Model.isoToDate(_data.created); |
|
875
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
144 |
if (typeof _data.color !== "undefined") { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
145 |
var _c = parseInt(_data.color).toString(16); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
146 |
while (_c.length < 6) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
147 |
_c = '0' + _c; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
148 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
149 |
_res.color = '#' + _c; |
| 860 | 150 |
} |
| 1002 | 151 |
_res.content = _data.content; |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
152 |
_res.setMedia(_data.media); |
| 860 | 153 |
_res.setAnnotationType(_data.meta["id-ref"]); |
154 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
| 983 | 155 |
_res.keywords = _res.getTagTexts(); |
| 860 | 156 |
_res.setBegin(_data.begin); |
157 |
_res.setEnd(_data.end); |
|
| 876 | 158 |
_res.creator = _data.meta["dc:creator"] || ""; |
159 |
_res.project = _data.meta.project || ""; |
|
| 880 | 160 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
161 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
162 |
} |
|
| 914 | 163 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
164 |
_res.audio = _data.content.audio; |
|
| 913 | 165 |
} |
| 860 | 166 |
return _res; |
167 |
}, |
|
| 983 | 168 |
serializer : function(_data, _source, _dest) { |
169 |
var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
|
170 |
var _res = { |
|
| 916 | 171 |
id : _data.id, |
| 904 | 172 |
begin : _data.begin.milliseconds, |
173 |
end : _data.end.milliseconds, |
|
| 1002 | 174 |
content : IriSP._.defaults( |
175 |
{}, |
|
176 |
{ |
|
177 |
title : _data.title, |
|
178 |
description : _data.description, |
|
| 983 | 179 |
audio : _data.audio, |
180 |
img: { |
|
181 |
src: _data.thumbnail |
|
182 |
} |
|
| 860 | 183 |
}, |
| 1002 | 184 |
_data.content, |
185 |
{ |
|
186 |
title: "", |
|
187 |
description: "" |
|
188 |
} |
|
189 |
), |
|
| 983 | 190 |
color: _color, |
| 916 | 191 |
media : _data.media.id, |
| 860 | 192 |
meta : { |
| 983 | 193 |
"id-ref" : _data.getAnnotationType().id, |
194 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
195 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
196 |
"dc:creator" : _data.creator || _source.creator, |
|
|
1032
74ac0be7655c
small corrections to allow js compilation
ymh <ymh.work@gmail.com>
parents:
1015
diff
changeset
|
197 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator |
| 983 | 198 |
// project : _source.projectId |
| 1002 | 199 |
} |
| 1013 | 200 |
}; |
| 1002 | 201 |
if (_source.regenerateTags) { |
202 |
_res.tags = IriSP._(_data.keywords).map(function(_kw) { |
|
203 |
return { |
|
204 |
"id-ref": _source.__keywords[_kw.toLowerCase()].id |
|
| 1013 | 205 |
}; |
| 1002 | 206 |
}); |
207 |
} else { |
|
208 |
_res.tags = IriSP._(_data.tag.id).map(function(_id) { |
|
| 860 | 209 |
return { |
| 916 | 210 |
"id-ref" : _id |
| 1013 | 211 |
}; |
| 1002 | 212 |
}); |
| 860 | 213 |
} |
| 1002 | 214 |
_res.content.title = _data.title || _res.content.title || ""; |
| 983 | 215 |
_dest.annotations.push(_res); |
| 860 | 216 |
} |
| 900 | 217 |
}, |
218 |
mashup : { |
|
| 919 | 219 |
serialized_name : "lists", |
| 900 | 220 |
deserializer : function(_data, _source) { |
| 919 | 221 |
if (typeof _data.meta !== "object" || typeof _data.meta.listtype !== "string" || _data.meta.listtype !== "mashup") { |
222 |
return undefined; |
|
223 |
} |
|
| 900 | 224 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
225 |
_res.title = _data.meta["dc:title"]; |
|
226 |
_res.description = _data.meta["dc:description"]; |
|
| 983 | 227 |
_res.creator = _data.meta["dc:creator"]; |
228 |
_res.setAnnotationsById(_data.items); |
|
| 900 | 229 |
return _res; |
230 |
}, |
|
| 983 | 231 |
serializer : function(_data, _source, _dest) { |
232 |
var _res = { |
|
| 919 | 233 |
meta : { |
| 983 | 234 |
"dc:title": _data.title || "", |
235 |
"dc:description": _data.description || "", |
|
236 |
"dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
237 |
"dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
238 |
"dc:creator" : _data.creator || _source.creator, |
|
239 |
"dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
| 919 | 240 |
listtype: "mashup" |
241 |
}, |
|
242 |
items: _data.segments.map(function(_annotation) { |
|
| 983 | 243 |
return _annotation.annotation.id; |
| 919 | 244 |
}), |
245 |
id: _data.id |
|
| 1013 | 246 |
}; |
| 983 | 247 |
_dest.lists.push(_res); |
| 900 | 248 |
} |
| 860 | 249 |
} |
250 |
}, |
|
| 864 | 251 |
serialize : function(_source) { |
| 983 | 252 |
var _res = { |
253 |
meta: { |
|
254 |
"dc:creator": _source.creator, |
|
255 |
"dc:contributor" : _source.contributor || _source.creator, |
|
256 |
"dc:created": IriSP.Model.dateToIso(_source.created), |
|
257 |
"dc:modified" : IriSP.Model.dateToIso(_source.modified), |
|
258 |
"dc:title": _source.title || "", |
|
259 |
"dc:description": _source.description || "", |
|
260 |
id: _source.projectId || _source.id |
|
261 |
}, |
|
262 |
views: [ |
|
263 |
{ |
|
264 |
id: IriSP.Model.getUID(), |
|
265 |
contents: [], |
|
266 |
annotation_types: [] |
|
267 |
} |
|
268 |
], |
|
269 |
lists: [], |
|
270 |
"annotation-types": [], |
|
271 |
medias: [], |
|
272 |
tags: [], |
|
273 |
annotations: [] |
|
274 |
}, |
|
| 860 | 275 |
_this = this; |
| 1002 | 276 |
if (_source.regenerateTags) { |
277 |
_source.__keywords = {}; |
|
278 |
_source.getAnnotations().forEach(function(a) { |
|
279 |
IriSP._(a.keywords).each(function(kw) { |
|
280 |
var lkw = kw.toLowerCase(); |
|
281 |
if (typeof _source.__keywords[lkw] === "undefined") { |
|
282 |
_source.__keywords[lkw] = { |
|
283 |
id: IriSP.Model.getUID(), |
|
284 |
title: kw, |
|
285 |
regenerated: true |
|
| 1013 | 286 |
}; |
| 1002 | 287 |
} |
288 |
}); |
|
289 |
}); |
|
290 |
IriSP._(_source.__keywords).each(function(kw) { |
|
291 |
_this.types.tag.serializer(kw, _source, _res); |
|
| 1013 | 292 |
}); |
| 1002 | 293 |
} |
| 866 | 294 |
_source.forEach(function(_list, _typename) { |
| 864 | 295 |
if (typeof _this.types[_typename] !== "undefined") { |
| 983 | 296 |
_list.forEach(function(_el) { |
297 |
_this.types[_typename].serializer(_el, _source, _res); |
|
| 864 | 298 |
}); |
299 |
} |
|
| 860 | 300 |
}); |
| 904 | 301 |
return JSON.stringify(_res); |
| 860 | 302 |
}, |
| 864 | 303 |
deSerialize : function(_data, _source) { |
| 882 | 304 |
if (typeof _data !== "object" || _data === null) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
305 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
306 |
} |
| 866 | 307 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 916 | 308 |
var _listdata = _data[_type.serialized_name], |
309 |
_list = new IriSP.Model.List(_source.directory); |
|
| 882 | 310 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
| 864 | 311 |
if (_listdata.hasOwnProperty("length")) { |
312 |
var _l = _listdata.length; |
|
313 |
for (var _i = 0; _i < _l; _i++) { |
|
| 919 | 314 |
var _element = _type.deserializer(_listdata[_i], _source); |
315 |
if (typeof _element !== "undefined" && _element) { |
|
316 |
_list.push(_element); |
|
317 |
} |
|
| 864 | 318 |
} |
319 |
} else { |
|
| 919 | 320 |
var _element = _type.deserializer(_listdata, _source); |
321 |
if (typeof _element !== "undefined" && _element) { |
|
322 |
_list.push(_element); |
|
323 |
} |
|
| 864 | 324 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
325 |
} |
| 916 | 326 |
_source.addList(_typename, _list); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
327 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
328 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
329 |
if (typeof _data.meta !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
330 |
_source.projectId = _data.meta.id; |
| 1002 | 331 |
_source.title = _data.meta["dc:title"] || _data.meta.title || ""; |
332 |
_source.description = _data.meta["dc:description"] || _data.meta.description || ""; |
|
333 |
_source.creator = _data.meta["dc:creator"] || _data.meta.creator || ""; |
|
334 |
_source.contributor = _data.meta["dc:contributor"] || _data.meta.contributor || _source.creator; |
|
335 |
_source.created = IriSP.Model.isoToDate(_data.meta["dc:created"] || _data.meta.created); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
336 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
337 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
338 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 957 | 339 |
_source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
340 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
341 |
} |
| 998 | 342 |
}; |
| 868 | 343 |
|
|
1032
74ac0be7655c
small corrections to allow js compilation
ymh <ymh.work@gmail.com>
parents:
1015
diff
changeset
|
344 |
/* End of LDT Platform Serializer */ |