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