| author | veltr |
| Fri, 18 May 2012 18:23:51 +0200 | |
| branch | new-model |
| changeset 904 | 510ebab76fa3 |
| parent 902 | 14022f1d49ab |
| child 908 | f56199193fad |
| 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 { |
| 864 | 32 |
id : _source.unNamespace(_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 { |
| 864 | 52 |
id : _source.unNamespace(_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 { |
| 864 | 69 |
id : _source.unNamespace(_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 |
} |
| 864 | 92 |
_res.setMedia(_data.media, _source); |
| 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 |
} |
|
| 860 | 102 |
return _res; |
103 |
}, |
|
| 864 | 104 |
serializer : function(_data, _source) { |
| 860 | 105 |
return { |
| 864 | 106 |
id : _source.unNamespace(_data.id), |
| 904 | 107 |
begin : _data.begin.milliseconds, |
108 |
end : _data.end.milliseconds, |
|
| 860 | 109 |
content : { |
110 |
title : _data.title, |
|
111 |
description : _data.description |
|
112 |
}, |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
113 |
media : _source.unNamespace(_data.media.id), |
| 860 | 114 |
meta : { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
115 |
"id-ref" : _source.unNamespace(_data.annotationType.id), |
| 864 | 116 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
117 |
"dc:creator" : _data.creator, |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
118 |
project : _source.projectId |
| 860 | 119 |
}, |
| 904 | 120 |
tags : IriSP._(_data.tag.id).map(function(_id) { |
| 860 | 121 |
return { |
| 864 | 122 |
"id-ref" : _source.unNamespace(_id) |
| 860 | 123 |
} |
124 |
}) |
|
125 |
} |
|
126 |
} |
|
| 900 | 127 |
}, |
128 |
mashup : { |
|
129 |
serialized_name : "mashups", |
|
130 |
deserializer : function(_data, _source) { |
|
131 |
var _res = new IriSP.Model.Mashup(_data.id, _source); |
|
132 |
_res.title = _data.meta["dc:title"]; |
|
133 |
_res.description = _data.meta["dc:description"]; |
|
134 |
for (var _i = 0; _i < _data.segments.length; _i++) { |
|
135 |
_res.addSegmentById(_data.segments[_i]); |
|
136 |
} |
|
137 |
return _res; |
|
138 |
}, |
|
139 |
serializer : function(_data, _source) { |
|
140 |
return { |
|
141 |
"dc:title": _data.title, |
|
142 |
"dc:description": _data.description, |
|
143 |
segments: _data.segments.map(function(_annotation) { |
|
144 |
return _source.unNamespace(_id); |
|
145 |
}) |
|
146 |
} |
|
147 |
} |
|
| 860 | 148 |
} |
149 |
}, |
|
| 864 | 150 |
serialize : function(_source) { |
| 860 | 151 |
var _res = {}, |
152 |
_this = this; |
|
| 866 | 153 |
_source.forEach(function(_list, _typename) { |
| 864 | 154 |
if (typeof _this.types[_typename] !== "undefined") { |
155 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
156 |
return _this.types[_typename].serializer(_el, _source); |
|
157 |
}); |
|
158 |
} |
|
| 860 | 159 |
}); |
| 904 | 160 |
return JSON.stringify(_res); |
| 860 | 161 |
}, |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
162 |
loadData : function(_url, _callback) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
163 |
IriSP.jQuery.getJSON(_url, _callback) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
164 |
}, |
| 864 | 165 |
deSerialize : function(_data, _source) { |
| 882 | 166 |
if (typeof _data !== "object" || _data === null) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
167 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
168 |
} |
| 866 | 169 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 864 | 170 |
var _listdata = _data[_type.serialized_name]; |
| 882 | 171 |
if (typeof _listdata !== "undefined" && _listdata !== null) { |
| 864 | 172 |
var _list = new IriSP.Model.List(_source.directory); |
173 |
if (_listdata.hasOwnProperty("length")) { |
|
174 |
var _l = _listdata.length; |
|
175 |
for (var _i = 0; _i < _l; _i++) { |
|
| 866 | 176 |
_list.push(_type.deserializer(_listdata[_i], _source)); |
| 864 | 177 |
} |
178 |
} else { |
|
| 866 | 179 |
_list.push(_type.deserializer(_listdata, _source)); |
| 864 | 180 |
} |
181 |
_source.addList(_typename, _list); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
182 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
183 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
184 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
185 |
if (typeof _data.meta !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
186 |
_source.projectId = _data.meta.id; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
187 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
188 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
189 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 864 | 190 |
_source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
191 |
} |
| 864 | 192 |
_source.setDefaultCurrentMedia(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
193 |
} |
| 868 | 194 |
} |
195 |