| author | veltr |
| Tue, 17 Apr 2012 20:19:46 +0200 | |
| branch | new-model |
| changeset 868 | a525cc2214e7 |
| parent 866 | 3bf7aa8216e5 |
| child 872 | d777d05a16e4 |
| 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); |
|
| 860 | 80 |
_res.title = _data.content.title; |
81 |
_res.description = _data.content.description; |
|
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"]; |
| 860 | 94 |
return _res; |
95 |
}, |
|
| 864 | 96 |
serializer : function(_data, _source) { |
| 860 | 97 |
return { |
| 864 | 98 |
id : _source.unNamespace(_data.id), |
| 860 | 99 |
content : { |
100 |
title : _data.title, |
|
101 |
description : _data.description |
|
102 |
}, |
|
| 864 | 103 |
media : _source.unNamespace(_data.media.contents), |
| 860 | 104 |
meta : { |
| 864 | 105 |
"id-ref" : _source.unNamespace(_data.annotationType.contents), |
106 |
"dc:created" : IriSP.Model.dateToIso(_data.created), |
|
107 |
"dc:creator" : _data.creator |
|
| 860 | 108 |
}, |
109 |
tags : _data.getTags().map(function(_el, _id) { |
|
110 |
return { |
|
| 864 | 111 |
"id-ref" : _source.unNamespace(_id) |
| 860 | 112 |
} |
113 |
}) |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
}, |
|
| 864 | 118 |
serialize : function(_source) { |
| 860 | 119 |
var _res = {}, |
120 |
_this = this; |
|
| 866 | 121 |
_source.forEach(function(_list, _typename) { |
| 864 | 122 |
if (typeof _this.types[_typename] !== "undefined") { |
123 |
_res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
124 |
return _this.types[_typename].serializer(_el, _source); |
|
125 |
}); |
|
126 |
} |
|
| 860 | 127 |
}); |
128 |
return _res; |
|
129 |
}, |
|
| 864 | 130 |
deSerialize : function(_data, _source) { |
| 866 | 131 |
IriSP._(this.types).forEach(function(_type, _typename) { |
| 864 | 132 |
var _listdata = _data[_type.serialized_name]; |
133 |
if (typeof _listdata !== "undefined") { |
|
134 |
var _list = new IriSP.Model.List(_source.directory); |
|
135 |
if (_listdata.hasOwnProperty("length")) { |
|
136 |
var _l = _listdata.length; |
|
137 |
for (var _i = 0; _i < _l; _i++) { |
|
| 866 | 138 |
_list.push(_type.deserializer(_listdata[_i], _source)); |
| 864 | 139 |
} |
140 |
} else { |
|
| 866 | 141 |
_list.push(_type.deserializer(_listdata, _source)); |
| 864 | 142 |
} |
143 |
_source.addList(_typename, _list); |
|
|
856
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 |
}); |
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
146 |
|
|
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
147 |
if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
| 864 | 148 |
_source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
149 |
} |
| 864 | 150 |
_source.setDefaultCurrentMedia(); |
|
856
41c574c807d1
basic implementation of model: media, annotation type, annotation
veltr
parents:
diff
changeset
|
151 |
} |
| 868 | 152 |
} |
153 |