| author | veltr |
| Thu, 19 Apr 2012 19:20:41 +0200 | |
| branch | new-model |
| changeset 872 | d777d05a16e4 |
| parent 868 | a525cc2214e7 |
| child 875 | 43629caa77bc |
| 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", |
|
11 |
model_name : "media", |
|
| 864 | 12 |
deserializer : function(_data, _source) { |
13 |
var _res = new IriSP.Model.Media(_data.id, _source); |
|
| 866 | 14 |
_res.video = ( |
15 |
typeof _data.url !== "undefined" |
|
16 |
? _data.url |
|
17 |
: ( |
|
18 |
typeof _data.href !== "undefined" |
|
19 |
? _data.href |
|
20 |
: null |
|
21 |
) |
|
22 |
); |
|
23 |
if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
24 |
_res.streamer = _data.meta.item.value; |
|
25 |
} |
|
| 860 | 26 |
_res.title = _data.meta["dc:title"]; |
27 |
_res.description = _data.meta["dc:description"]; |
|
28 |
_res.setDuration(_data.meta["dc:duration"]); |
|
29 |
return _res; |
|
| 858 | 30 |
}, |
| 864 | 31 |
serializer : function(_data, _source) { |
| 860 | 32 |
return { |
| 864 | 33 |
id : _source.unNamespace(_data.id), |
| 866 | 34 |
url : _data.video, |
| 860 | 35 |
meta : { |
36 |
"dc:title" : _data.title, |
|
37 |
"dc:description" : _data.description, |
|
38 |
"dc:duration" : _data.duration.milliseconds |
|
39 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
40 |
} |
| 860 | 41 |
} |
42 |
}, |
|
43 |
tag : { |
|
44 |
serialized_name : "tags", |
|
45 |
model_name : "tag", |
|
| 864 | 46 |
deserializer : function(_data, _source) { |
47 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
| 860 | 48 |
_res.title = _data.meta["dc:title"]; |
49 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
50 |
}, |
| 864 | 51 |
serializer : function(_data, _source) { |
| 860 | 52 |
return { |
| 864 | 53 |
id : _source.unNamespace(_data.id), |
| 860 | 54 |
meta : { |
55 |
"dc:title" : _data.title |
|
56 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
57 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
58 |
} |
| 860 | 59 |
}, |
| 864 | 60 |
annotationType : { |
| 860 | 61 |
serialized_name : "annotation-types", |
| 864 | 62 |
deserializer : function(_data, _source) { |
63 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
| 860 | 64 |
_res.title = _data["dc:title"]; |
65 |
_res.description = _data["dc:description"]; |
|
66 |
return _res; |
|
67 |
}, |
|
| 864 | 68 |
serializer : function(_data, _source) { |
| 860 | 69 |
return { |
| 864 | 70 |
id : _source.unNamespace(_data.id), |
| 860 | 71 |
"dc:title" : _data.title, |
72 |
"dc:description" : _data.description |
|
73 |
} |
|
74 |
} |
|
75 |
}, |
|
76 |
annotation : { |
|
77 |
serialized_name : "annotations", |
|
| 864 | 78 |
deserializer : function(_data, _source) { |
79 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
80 |
_res.title = _data.content.title || ""; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
81 |
_res.description = _data.content.description || ""; |
| 860 | 82 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
83 |
var _c = parseInt(_data.color).toString(16); |
|
84 |
while (_c.length < 6) { |
|
85 |
_c = '0' + _c; |
|
86 |
} |
|
87 |
_res.color = '#' + _c; |
|
| 864 | 88 |
_res.setMedia(_data.media, _source); |
| 860 | 89 |
_res.setAnnotationType(_data.meta["id-ref"]); |
90 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
91 |
_res.setBegin(_data.begin); |
|
92 |
_res.setEnd(_data.end); |
|
| 864 | 93 |
_res.creator = _data.meta["dc:creator"]; |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
94 |
_res.project = _data.meta.project; |
| 860 | 95 |
return _res; |
96 |
}, |
|
| 864 | 97 |
serializer : function(_data, _source) { |
| 860 | 98 |
return { |
| 864 | 99 |
id : _source.unNamespace(_data.id), |
| 860 | 100 |
content : { |
101 |
title : _data.title, |
|
102 |
description : _data.description |
|
103 |
}, |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
104 |
media : _source.unNamespace(_data.media.id), |
| 860 | 105 |
meta : { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
106 |
"id-ref" : _source.unNamespace(_data.annotationType.id), |
| 864 | 107 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
108 |
"dc:creator" : _data.creator, |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
109 |
project : _source.projectId |
| 860 | 110 |
}, |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
111 |
tags : IriSP._(_data.tag.id).map(function(_d) { |
| 860 | 112 |
return { |
| 864 | 113 |
"id-ref" : _source.unNamespace(_id) |
| 860 | 114 |
} |
115 |
}) |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
}, |
|
| 864 | 120 |
serialize : function(_source) { |
| 860 | 121 |
var _res = {}, |
122 |
_this = this; |
|
| 866 | 123 |
_source.forEach(function(_list, _typename) { |
| 864 | 124 |
if (typeof _this.types[_typename] !== "undefined") { |
125 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
126 |
return _this.types[_typename].serializer(_el, _source); |
|
127 |
}); |
|
128 |
} |
|
| 860 | 129 |
}); |
130 |
return _res; |
|
131 |
}, |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
132 |
loadData : function(_url, _callback) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
133 |
IriSP.jQuery.getJSON(_url, _callback) |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
134 |
}, |
| 864 | 135 |
deSerialize : function(_data, _source) { |
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
136 |
if (typeof _data !== "object" && _data === null) { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
137 |
return; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
138 |
} |
| 866 | 139 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 864 | 140 |
var _listdata = _data[_type.serialized_name]; |
141 |
if (typeof _listdata !== "undefined") { |
|
142 |
var _list = new IriSP.Model.List(_source.directory); |
|
143 |
if (_listdata.hasOwnProperty("length")) { |
|
144 |
var _l = _listdata.length; |
|
145 |
for (var _i = 0; _i < _l; _i++) { |
|
| 866 | 146 |
_list.push(_type.deserializer(_listdata[_i], _source)); |
| 864 | 147 |
} |
148 |
} else { |
|
| 866 | 149 |
_list.push(_type.deserializer(_listdata, _source)); |
| 864 | 150 |
} |
151 |
_source.addList(_typename, _list); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
152 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
153 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
154 |
|
|
872
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
155 |
if (typeof _data.meta !== "undefined") { |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
156 |
_source.projectId = _data.meta.id; |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
157 |
} |
|
d777d05a16e4
finished AnnotationsList and started New PolemicWidget
veltr
parents:
868
diff
changeset
|
158 |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
159 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 864 | 160 |
_source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
161 |
} |
| 864 | 162 |
_source.setDefaultCurrentMedia(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
163 |
} |
| 868 | 164 |
} |
165 |