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