1 /* LDT Platform Serializer */ |
|
2 |
|
3 if (typeof IriSP.serializers === "undefined") { |
|
4 IriSP.serializers = {} |
|
5 } |
|
6 |
|
7 IriSP.serializers.ldt = { |
|
8 types : { |
|
9 media : { |
|
10 serialized_name : "medias", |
|
11 deserializer : function(_data, _source) { |
|
12 var _res = new IriSP.Model.Media(_data.id, _source); |
|
13 _res.video = ( |
|
14 typeof _data.url !== "undefined" |
|
15 ? _data.url |
|
16 : ( |
|
17 typeof _data.href !== "undefined" |
|
18 ? _data.href |
|
19 : null |
|
20 ) |
|
21 ); |
|
22 if (typeof _data.meta.item !== "undefined" && _data.meta.item.name === "streamer") { |
|
23 _res.streamer = _data.meta.item.value; |
|
24 } |
|
25 _res.title = _data.meta["dc:title"]; |
|
26 _res.description = _data.meta["dc:description"]; |
|
27 _res.setDuration(_data.meta["dc:duration"]); |
|
28 return _res; |
|
29 }, |
|
30 serializer : function(_data, _source) { |
|
31 return { |
|
32 id : _source.unNamespace(_data.id), |
|
33 url : _data.video, |
|
34 meta : { |
|
35 "dc:title" : _data.title, |
|
36 "dc:description" : _data.description, |
|
37 "dc:duration" : _data.duration.milliseconds |
|
38 } |
|
39 } |
|
40 } |
|
41 }, |
|
42 tag : { |
|
43 serialized_name : "tags", |
|
44 model_name : "tag", |
|
45 deserializer : function(_data, _source) { |
|
46 var _res = new IriSP.Model.Tag(_data.id, _source); |
|
47 _res.title = _data.meta["dc:title"]; |
|
48 return _res; |
|
49 }, |
|
50 serializer : function(_data, _source) { |
|
51 return { |
|
52 id : _source.unNamespace(_data.id), |
|
53 meta : { |
|
54 "dc:title" : _data.title |
|
55 } |
|
56 } |
|
57 } |
|
58 }, |
|
59 annotationType : { |
|
60 serialized_name : "annotation-types", |
|
61 deserializer : function(_data, _source) { |
|
62 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
63 _res.title = _data["dc:title"]; |
|
64 _res.description = _data["dc:description"]; |
|
65 return _res; |
|
66 }, |
|
67 serializer : function(_data, _source) { |
|
68 return { |
|
69 id : _source.unNamespace(_data.id), |
|
70 "dc:title" : _data.title, |
|
71 "dc:description" : _data.description |
|
72 } |
|
73 } |
|
74 }, |
|
75 annotation : { |
|
76 serialized_name : "annotations", |
|
77 deserializer : function(_data, _source) { |
|
78 var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
79 _res.title = _data.content.title || ""; |
|
80 _res.description = _data.content.description || ""; |
|
81 if (typeof _data.content.img !== "undefined" && _data.content.img.src !== "undefined") { |
|
82 _res.thumbnail = _data.content.img.src; |
|
83 } |
|
84 _res.created = IriSP.Model.isoToDate(_data.meta["dc:created"]); |
|
85 if (typeof _data.color !== "undefined") { |
|
86 var _c = parseInt(_data.color).toString(16); |
|
87 while (_c.length < 6) { |
|
88 _c = '0' + _c; |
|
89 } |
|
90 _res.color = '#' + _c; |
|
91 } |
|
92 _res.setMedia(_data.media); |
|
93 _res.setAnnotationType(_data.meta["id-ref"]); |
|
94 _res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
|
95 _res.setBegin(_data.begin); |
|
96 _res.setEnd(_data.end); |
|
97 _res.creator = _data.meta["dc:creator"] || ""; |
|
98 _res.project = _data.meta.project || ""; |
|
99 if (typeof _data.meta["dc:source"] !== "undefined" && typeof _data.meta["dc:source"].content !== "undefined") { |
|
100 _res.source = JSON.parse(_data.meta["dc:source"].content); |
|
101 } |
|
102 return _res; |
|
103 }, |
|
104 serializer : function(_data, _source) { |
|
105 return { |
|
106 id : _source.unNamespace(_data.id), |
|
107 begin : _data.begin.milliseconds, |
|
108 end : _data.end.milliseconds, |
|
109 content : { |
|
110 title : _data.title, |
|
111 description : _data.description |
|
112 }, |
|
113 media : _source.unNamespace(_data.media.id), |
|
114 meta : { |
|
115 "id-ref" : _source.unNamespace(_data.annotationType.id), |
|
116 "dc:created" : IriSP.Model.dateToIso(_data.created), |
|
117 "dc:creator" : _data.creator, |
|
118 project : _source.projectId |
|
119 }, |
|
120 tags : IriSP._(_data.tag.id).map(function(_id) { |
|
121 return { |
|
122 "id-ref" : _source.unNamespace(_id) |
|
123 } |
|
124 }) |
|
125 } |
|
126 } |
|
127 }, |
|
128 mashup : { |
|
129 serialized_name : "mashups", |
|
130 deserializer : function(_data, _source) { |
|
131 var _res = new IriSP.Model.Mashup(_data.id, _source); |
|
132 _res.title = _data.meta["dc:title"]; |
|
133 _res.description = _data.meta["dc:description"]; |
|
134 for (var _i = 0; _i < _data.segments.length; _i++) { |
|
135 _res.addSegmentById(_data.segments[_i]); |
|
136 } |
|
137 return _res; |
|
138 }, |
|
139 serializer : function(_data, _source) { |
|
140 return { |
|
141 "dc:title": _data.title, |
|
142 "dc:description": _data.description, |
|
143 segments: _data.segments.map(function(_annotation) { |
|
144 return _source.unNamespace(_id); |
|
145 }) |
|
146 } |
|
147 } |
|
148 } |
|
149 }, |
|
150 serialize : function(_source) { |
|
151 var _res = {}, |
|
152 _this = this; |
|
153 _source.forEach(function(_list, _typename) { |
|
154 if (typeof _this.types[_typename] !== "undefined") { |
|
155 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
|
156 return _this.types[_typename].serializer(_el, _source); |
|
157 }); |
|
158 } |
|
159 }); |
|
160 return JSON.stringify(_res); |
|
161 }, |
|
162 loadData : function(_url, _callback) { |
|
163 IriSP.jQuery.getJSON(_url, _callback) |
|
164 }, |
|
165 deSerialize : function(_data, _source) { |
|
166 if (typeof _data !== "object" || _data === null) { |
|
167 return; |
|
168 } |
|
169 IriSP._(this.types).forEach(function(_type, _typename) { |
|
170 var _listdata = _data[_type.serialized_name]; |
|
171 if (typeof _listdata !== "undefined" && _listdata !== null) { |
|
172 var _list = new IriSP.Model.List(_source.directory); |
|
173 if (_listdata.hasOwnProperty("length")) { |
|
174 var _l = _listdata.length; |
|
175 for (var _i = 0; _i < _l; _i++) { |
|
176 _list.push(_type.deserializer(_listdata[_i], _source)); |
|
177 } |
|
178 } else { |
|
179 _list.push(_type.deserializer(_listdata, _source)); |
|
180 } |
|
181 _source.addList(_typename, _list); |
|
182 } |
|
183 }); |
|
184 |
|
185 if (typeof _data.meta !== "undefined") { |
|
186 _source.projectId = _data.meta.id; |
|
187 } |
|
188 |
|
189 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
190 _source.setCurrentMediaId(_data.meta.main_media["id-ref"]); |
|
191 } |
|
192 _source.setDefaultCurrentMedia(); |
|
193 } |
|
194 } |
|
195 |
|