| author | veltr |
| Tue, 26 Jun 2012 14:22:29 +0200 | |
| branch | new-model |
| changeset 919 | 972099304059 |
| parent 917 | eb8677d3a663 |
| child 957 | 4da0a5740b6c |
| 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 |
}, |
| 864 | 34 |
serializer : function(_data, _source) { |
| 860 | 35 |
return { |
| 916 | 36 |
id : _data.id, |
| 866 | 37 |
url : _data.video, |
| 860 | 38 |
meta : { |
39 |
"dc:title" : _data.title, |
|
40 |
"dc:description" : _data.description, |
|
41 |
"dc:duration" : _data.duration.milliseconds |
|
42 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
43 |
} |
| 860 | 44 |
} |
45 |
}, |
|
46 |
tag : { |
|
47 |
serialized_name : "tags", |
|
48 |
model_name : "tag", |
|
| 864 | 49 |
deserializer : function(_data, _source) { |
50 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
| 860 | 51 |
_res.title = _data.meta["dc:title"]; |
52 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
53 |
}, |
| 864 | 54 |
serializer : function(_data, _source) { |
| 860 | 55 |
return { |
| 916 | 56 |
id : _data.id, |
| 860 | 57 |
meta : { |
58 |
"dc:title" : _data.title |
|
59 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
60 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
61 |
} |
| 860 | 62 |
}, |
| 864 | 63 |
annotationType : { |
| 860 | 64 |
serialized_name : "annotation-types", |
| 864 | 65 |
deserializer : function(_data, _source) { |
66 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
| 860 | 67 |
_res.title = _data["dc:title"]; |
68 |
_res.description = _data["dc:description"]; |
|
69 |
return _res; |
|
70 |
}, |
|
| 864 | 71 |
serializer : function(_data, _source) { |
| 860 | 72 |
return { |
| 916 | 73 |
id : _data.id, |
| 860 | 74 |
"dc:title" : _data.title, |
75 |
"dc:description" : _data.description |
|
76 |
} |
|
77 |
} |
|
78 |
}, |
|
79 |
annotation : { |
|
80 |
serialized_name : "annotations", |
|
| 864 | 81 |
deserializer : function(_data, _source) { |
82 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
83 |
_res.title = _data.content.title || ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
84 |
_res.description = _data.content.description || ""; |
| 876 | 85 |
if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
86 |
_res.thumbnail = _data.content.img.src; |
|
87 |
} |
|
| 860 | 88 |
_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
|
89 |
if (typeof _data.color !== "undefined") { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
90 |
var _c = parseInt(_data.color).toString(16); |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
91 |
while (_c.length < 6) { |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
92 |
_c = '0' + _c; |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
93 |
} |
|
43629caa77bc
Big refactoring of widget files + started migration of segmentwidget
veltr
parents:
872
diff
changeset
|
94 |
_res.color = '#' + _c; |
| 860 | 95 |
} |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
96 |
_res.setMedia(_data.media); |
| 860 | 97 |
_res.setAnnotationType(_data.meta["id-ref"]); |
98 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
99 |
_res.setBegin(_data.begin); |
|
100 |
_res.setEnd(_data.end); |
|
| 876 | 101 |
_res.creator = _data.meta["dc:creator"] || ""; |
102 |
_res.project = _data.meta.project || ""; |
|
| 880 | 103 |
if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
104 |
_res.source = JSON.parse(_data.meta["dc:source"].content); |
|
105 |
} |
|
| 914 | 106 |
if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
107 |
_res.audio = _data.content.audio; |
|
| 913 | 108 |
} |
| 860 | 109 |
return _res; |
110 |
}, |
|
| 864 | 111 |
serializer : function(_data, _source) { |
| 860 | 112 |
return { |
| 916 | 113 |
id : _data.id, |
| 904 | 114 |
begin : _data.begin.milliseconds, |
115 |
end : _data.end.milliseconds, |
|
| 860 | 116 |
content : { |
117 |
title : _data.title, |
|
| 914 | 118 |
description : _data.description, |
119 |
audio : _data.audio |
|
| 860 | 120 |
}, |
| 916 | 121 |
media : _data.media.id, |
| 860 | 122 |
meta : { |
| 916 | 123 |
"id-ref" : _data.annotationType.id, |
| 864 | 124 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
125 |
"dc:creator" : _data.creator, |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
126 |
project : _source.projectId |
| 860 | 127 |
}, |
| 904 | 128 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
| 860 | 129 |
return { |
| 916 | 130 |
"id-ref" : _id |
| 860 | 131 |
} |
| 914 | 132 |
}) |
| 860 | 133 |
} |
134 |
} |
|
| 900 | 135 |
}, |
136 |
mashup : { |
|
| 919 | 137 |
serialized_name : "lists", |
| 900 | 138 |
deserializer : function(_data, _source) { |
| 919 | 139 |
if (typeof _data.meta !== "object" || typeof _data.meta.listtype !== "string" || _data.meta.listtype !== "mashup") { |
140 |
return undefined; |
|
141 |
} |
|
| 900 | 142 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
143 |
_res.title = _data.meta["dc:title"]; |
|
144 |
_res.description = _data.meta["dc:description"]; |
|
| 919 | 145 |
for (var _i = 0; _i < _data.items.length; _i++) { |
146 |
_res.addSegmentById(_data.items[_i]); |
|
| 900 | 147 |
} |
148 |
return _res; |
|
149 |
}, |
|
150 |
serializer : function(_data, _source) { |
|
151 |
return { |
|
| 919 | 152 |
meta : { |
153 |
"dc:title": _data.title, |
|
154 |
"dc:description": _data.description, |
|
155 |
listtype: "mashup" |
|
156 |
}, |
|
157 |
items: _data.segments.map(function(_annotation) { |
|
| 916 | 158 |
return _id; |
| 919 | 159 |
}), |
160 |
id: _data.id |
|
| 900 | 161 |
} |
162 |
} |
|
| 860 | 163 |
} |
164 |
}, |
|
| 864 | 165 |
serialize : function(_source) { |
| 860 | 166 |
var _res = {}, |
167 |
_this = this; |
|
| 866 | 168 |
_source.forEach(function(_list, _typename) { |
| 864 | 169 |
if (typeof _this.types[_typename] !== "undefined") { |
170 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
171 |
return _this.types[_typename].serializer(_el, _source); |
|
172 |
}); |
|
173 |
} |
|
| 860 | 174 |
}); |
| 904 | 175 |
return JSON.stringify(_res); |
| 860 | 176 |
}, |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
177 |
loadData : function(_url, _callback) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
178 |
IriSP.jQuery.getJSON(_url, _callback) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
179 |
}, |
| 864 | 180 |
deSerialize : function(_data, _source) { |
| 882 | 181 |
if (typeof _data !== "object" || _data === null) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
182 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
183 |
} |
| 866 | 184 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 916 | 185 |
var _listdata = _data[_type.serialized_name], |
186 |
_list = new IriSP.Model.List(_source.directory); |
|
| 882 | 187 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
| 864 | 188 |
if (_listdata.hasOwnProperty("length")) { |
189 |
var _l = _listdata.length; |
|
190 |
for (var _i = 0; _i < _l; _i++) { |
|
| 919 | 191 |
var _element = _type.deserializer(_listdata[_i], _source); |
192 |
if (typeof _element !== "undefined" && _element) { |
|
193 |
_list.push(_element); |
|
194 |
} |
|
| 864 | 195 |
} |
196 |
} else { |
|
| 919 | 197 |
var _element = _type.deserializer(_listdata, _source); |
198 |
if (typeof _element !== "undefined" && _element) { |
|
199 |
_list.push(_element); |
|
200 |
} |
|
| 864 | 201 |
} |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
202 |
} |
| 916 | 203 |
_source.addList(_typename, _list); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
204 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
205 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
206 |
if (typeof _data.meta !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
207 |
_source.projectId = _data.meta.id; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
208 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
209 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
210 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 919 | 211 |
_source.mainMedia = _data.meta.main_media["id-ref"]; |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
212 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
213 |
} |
| 868 | 214 |
} |
215 |