| author | veltr |
| Fri, 13 Apr 2012 18:08:19 +0200 | |
| branch | new-model |
| changeset 860 | 7fd843e0dc4e |
| parent 858 | ad1ffe0c0955 |
| child 864 | 5e76a06b961c |
| 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", |
|
10 |
deserializer : function(_data, _container) { |
|
11 |
var _res = new IriSP.Model.Media(_data.id, _container); |
|
12 |
_res.url = _data.href; |
|
13 |
_res.title = _data.meta["dc:title"]; |
|
14 |
_res.description = _data.meta["dc:description"]; |
|
15 |
_res.setDuration(_data.meta["dc:duration"]); |
|
16 |
return _res; |
|
| 858 | 17 |
}, |
| 860 | 18 |
serializer : function(_data, _container) { |
19 |
return { |
|
20 |
id : _container.unNamespace(_data.id), |
|
21 |
href : _data.url, |
|
22 |
meta : { |
|
23 |
"dc:title" : _data.title, |
|
24 |
"dc:description" : _data.description, |
|
25 |
"dc:duration" : _data.duration.milliseconds |
|
26 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
27 |
} |
| 860 | 28 |
} |
29 |
}, |
|
30 |
tag : { |
|
31 |
serialized_name : "tags", |
|
32 |
model_name : "tag", |
|
33 |
deserializer : function(_data, _container) { |
|
34 |
var _res = new IriSP.Model.Tag(_data.id, _container); |
|
35 |
_res.title = _data.meta["dc:title"]; |
|
36 |
return _res; |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
37 |
}, |
| 860 | 38 |
serializer : function(_data, _container) { |
39 |
return { |
|
40 |
id : _container.unNamespace(_data.id), |
|
41 |
meta : { |
|
42 |
"dc:title" : _data.title |
|
43 |
} |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
44 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
45 |
} |
| 860 | 46 |
}, |
47 |
annotationTypes : { |
|
48 |
serialized_name : "annotation-types", |
|
49 |
deserializer : function(_data, _container) { |
|
50 |
var _res = new IriSP.Model.AnnotationType(_data.id, _container); |
|
51 |
_res.title = _data["dc:title"]; |
|
52 |
_res.description = _data["dc:description"]; |
|
53 |
return _res; |
|
54 |
}, |
|
55 |
serializer : function(_data, _container) { |
|
56 |
return { |
|
57 |
id : _container.unNamespace(_data.id), |
|
58 |
"dc:title" : _data.title, |
|
59 |
"dc:description" : _data.description |
|
60 |
} |
|
61 |
} |
|
62 |
}, |
|
63 |
annotation : { |
|
64 |
serialized_name : "annotations", |
|
65 |
deserializer : function(_data, _container) { |
|
66 |
var _res = new IriSP.Model.Annotation(_data.id, _container); |
|
67 |
_res.title = _data.content.title; |
|
68 |
_res.description = _data.content.description; |
|
69 |
_res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
70 |
var _c = parseInt(_data.color).toString(16); |
|
71 |
while (_c.length < 6) { |
|
72 |
_c = '0' + _c; |
|
73 |
} |
|
74 |
_res.color = '#' + _c; |
|
75 |
_res.setMedia(_data.media, _container); |
|
76 |
_res.setAnnotationType(_data.meta["id-ref"]); |
|
77 |
_res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
78 |
_res.setBegin(_data.begin); |
|
79 |
_res.setEnd(_data.end); |
|
80 |
return _res; |
|
81 |
}, |
|
82 |
serializer : function(_data, _container) { |
|
83 |
return { |
|
84 |
id : _container.unNamespace(_data.id), |
|
85 |
content : { |
|
86 |
title : _data.title, |
|
87 |
description : _data.description |
|
88 |
}, |
|
89 |
media : _container.unNamespace(_data.media.contents), |
|
90 |
meta : { |
|
91 |
"id-ref" : _container.unNamespace(_data.annotationType.contents), |
|
92 |
"dc:created" : IriSP.Model.dateToIso(_data.created) |
|
93 |
}, |
|
94 |
tags : _data.getTags().map(function(_el, _id) { |
|
95 |
return { |
|
96 |
"id-ref" : _container.unNamespace(_id) |
|
97 |
} |
|
98 |
}) |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
}, |
|
103 |
serialize : function(_container) { |
|
104 |
var _res = {}, |
|
105 |
_this = this; |
|
106 |
_container.each(function(_list, _typename) { |
|
107 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
108 |
return _this.types[_typename].serializer(_el, _container); |
|
109 |
}); |
|
110 |
}); |
|
111 |
return _res; |
|
112 |
}, |
|
113 |
deSerialize : function(_data, _container) { |
|
114 |
IriSP._(this.types).each(function(_type, _typename) { |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
115 |
if (typeof _data[_type.serialized_name] !== "undefined") { |
| 858 | 116 |
var _list = new IriSP.Model.List(_container.directory); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
117 |
IriSP._(_data[_type.serialized_name]).each(function(_el) { |
| 860 | 118 |
_list.addElement(_type.deserializer(_el, _container)); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
119 |
}); |
| 860 | 120 |
_container.addList(_typename, _list); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
121 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
122 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
123 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
124 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 858 | 125 |
_container.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
126 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
127 |
_container.setDefaultCurrentMedia(); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
128 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
129 |
} |