| author | veltr |
| Mon, 16 Apr 2012 19:10:32 +0200 | |
| branch | new-model |
| changeset 864 | 5e76a06b961c |
| parent 860 | 7fd843e0dc4e |
| child 866 | 3bf7aa8216e5 |
| 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); |
|
| 860 | 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 |
}, |
| 864 | 18 |
serializer : function(_data, _source) { |
| 860 | 19 |
return { |
| 864 | 20 |
id : _source.unNamespace(_data.id), |
| 860 | 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", |
|
| 864 | 33 |
deserializer : function(_data, _source) { |
34 |
var _res = new IriSP.Model.Tag(_data.id, _source); |
|
| 860 | 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 |
}, |
| 864 | 38 |
serializer : function(_data, _source) { |
| 860 | 39 |
return { |
| 864 | 40 |
id : _source.unNamespace(_data.id), |
| 860 | 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 |
}, |
| 864 | 47 |
annotationType : { |
| 860 | 48 |
serialized_name : "annotation-types", |
| 864 | 49 |
deserializer : function(_data, _source) { |
50 |
var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
| 860 | 51 |
_res.title = _data["dc:title"]; |
52 |
_res.description = _data["dc:description"]; |
|
53 |
return _res; |
|
54 |
}, |
|
| 864 | 55 |
serializer : function(_data, _source) { |
| 860 | 56 |
return { |
| 864 | 57 |
id : _source.unNamespace(_data.id), |
| 860 | 58 |
"dc:title" : _data.title, |
59 |
"dc:description" : _data.description |
|
60 |
} |
|
61 |
} |
|
62 |
}, |
|
63 |
annotation : { |
|
64 |
serialized_name : "annotations", |
|
| 864 | 65 |
deserializer : function(_data, _source) { |
66 |
var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
| 860 | 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; |
|
| 864 | 75 |
_res.setMedia(_data.media, _source); |
| 860 | 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); |
|
| 864 | 80 |
_res.creator = _data.meta["dc:creator"]; |
| 860 | 81 |
return _res; |
82 |
}, |
|
| 864 | 83 |
serializer : function(_data, _source) { |
| 860 | 84 |
return { |
| 864 | 85 |
id : _source.unNamespace(_data.id), |
| 860 | 86 |
content : { |
87 |
title : _data.title, |
|
88 |
description : _data.description |
|
89 |
}, |
|
| 864 | 90 |
media : _source.unNamespace(_data.media.contents), |
| 860 | 91 |
meta : { |
| 864 | 92 |
"id-ref" : _source.unNamespace(_data.annotationType.contents), |
93 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
94 |
"dc:creator" : _data.creator |
|
| 860 | 95 |
}, |
96 |
tags : _data.getTags().map(function(_el, _id) { |
|
97 |
return { |
|
| 864 | 98 |
"id-ref" : _source.unNamespace(_id) |
| 860 | 99 |
} |
100 |
}) |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
}, |
|
| 864 | 105 |
serialize : function(_source) { |
| 860 | 106 |
var _res = {}, |
107 |
_this = this; |
|
| 864 | 108 |
_source.each(function(_list, _typename) { |
109 |
if (typeof _this.types[_typename] !== "undefined") { |
|
110 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
111 |
return _this.types[_typename].serializer(_el, _source); |
|
112 |
}); |
|
113 |
} |
|
| 860 | 114 |
}); |
115 |
return _res; |
|
116 |
}, |
|
| 864 | 117 |
deSerialize : function(_data, _source) { |
| 860 | 118 |
IriSP._(this.types).each(function(_type, _typename) { |
| 864 | 119 |
var _listdata = _data[_type.serialized_name]; |
120 |
if (typeof _listdata !== "undefined") { |
|
121 |
var _list = new IriSP.Model.List(_source.directory); |
|
122 |
if (_listdata.hasOwnProperty("length")) { |
|
123 |
var _l = _listdata.length; |
|
124 |
for (var _i = 0; _i < _l; _i++) { |
|
125 |
_list.addElement(_type.deserializer(_listdata[_i], _source)); |
|
126 |
} |
|
127 |
} else { |
|
128 |
_list.addElement(_type.deserializer(_listdata, _source)); |
|
129 |
} |
|
130 |
_source.addList(_typename, _list); |
|
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
131 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
132 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
133 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
134 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 864 | 135 |
_source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
136 |
} |
| 864 | 137 |
_source.setDefaultCurrentMedia(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
138 |
} |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
139 |
} |