29 if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") { |
29 if (typeof _data.meta.img !== "undefined" && _data.meta.img.src !== "undefined") { |
30 _res.thumbnail = _data.meta.img.src; |
30 _res.thumbnail = _data.meta.img.src; |
31 } |
31 } |
32 return _res; |
32 return _res; |
33 }, |
33 }, |
34 serializer : function(_data, _source) { |
34 serializer : function(_data, _source, _dest) { |
35 return { |
35 var _res = { |
36 id : _data.id, |
36 id : _data.id, |
37 url : _data.video, |
37 url : _data.video, |
38 meta : { |
38 meta : { |
39 "dc:title" : _data.title, |
39 "dc:title": _data.title || "", |
40 "dc:description" : _data.description, |
40 "dc:description": _data.description || "", |
|
41 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
42 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
43 "dc:creator" : _data.creator || _source.creator, |
|
44 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
41 "dc:duration" : _data.duration.milliseconds |
45 "dc:duration" : _data.duration.milliseconds |
42 } |
46 } |
43 } |
47 } |
|
48 _dest.medias.push(_res); |
|
49 var _list = { |
|
50 id: IriSP.Model.getUID(), |
|
51 meta : { |
|
52 "dc:title": _data.title || "", |
|
53 "dc:description": _data.description || "", |
|
54 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
55 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
56 "dc:creator" : _data.creator || _source.creator, |
|
57 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
58 "id-ref": _data.id |
|
59 }, |
|
60 items: _source.getAnnotationTypes().filter(function(_at) { |
|
61 return _at.media === _data; |
|
62 }).map(function(_at) { |
|
63 return { |
|
64 "id-ref": _at.id |
|
65 } |
|
66 }) |
|
67 } |
|
68 _dest.lists.push(_list); |
|
69 _dest.views[0].contents.push(_data.id); |
44 } |
70 } |
45 }, |
71 }, |
46 tag : { |
72 tag : { |
47 serialized_name : "tags", |
73 serialized_name : "tags", |
48 model_name : "tag", |
74 model_name : "tag", |
49 deserializer : function(_data, _source) { |
75 deserializer : function(_data, _source) { |
50 var _res = new IriSP.Model.Tag(_data.id, _source); |
76 var _res = new IriSP.Model.Tag(_data.id, _source); |
51 _res.title = _data.meta["dc:title"]; |
77 _res.title = _data.meta["dc:title"]; |
52 return _res; |
78 return _res; |
53 }, |
79 }, |
54 serializer : function(_data, _source) { |
80 serializer : function(_data, _source, _dest) { |
55 return { |
81 var _res = { |
56 id : _data.id, |
82 id : _data.id, |
57 meta : { |
83 meta : { |
58 "dc:title" : _data.title |
84 "dc:title": _data.title || "", |
59 } |
85 "dc:description": _data.description || "", |
60 } |
86 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
87 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
88 "dc:creator" : _data.creator || _source.creator, |
|
89 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
90 } |
|
91 } |
|
92 _dest.tags.push(_res); |
61 } |
93 } |
62 }, |
94 }, |
63 annotationType : { |
95 annotationType : { |
64 serialized_name : "annotation-types", |
96 serialized_name : "annotation-types", |
65 deserializer : function(_data, _source) { |
97 deserializer : function(_data, _source) { |
66 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
98 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
67 _res.title = _data["dc:title"]; |
99 _res.title = _data["dc:title"]; |
68 _res.description = _data["dc:description"]; |
100 _res.description = _data["dc:description"]; |
69 return _res; |
101 return _res; |
70 }, |
102 }, |
71 serializer : function(_data, _source) { |
103 serializer : function(_data, _source, _dest) { |
72 return { |
104 var _res = { |
73 id : _data.id, |
105 id : _data.id, |
74 "dc:title" : _data.title, |
106 "dc:title": _data.title || "", |
75 "dc:description" : _data.description |
107 "dc:description": _data.description || "", |
76 } |
108 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
109 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
110 "dc:creator" : _data.creator || _source.creator, |
|
111 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
112 } |
|
113 _dest["annotation-types"].push(_res); |
|
114 _dest.views[0].annotation_types.push(_data.id); |
77 } |
115 } |
78 }, |
116 }, |
79 annotation : { |
117 annotation : { |
80 serialized_name : "annotations", |
118 serialized_name : "annotations", |
81 deserializer : function(_data, _source) { |
119 deserializer : function(_data, _source) { |
107 if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
145 if (typeof _data.content.audio !== "undefined" && _data.content.audio.href) { |
108 _res.audio = _data.content.audio; |
146 _res.audio = _data.content.audio; |
109 } |
147 } |
110 return _res; |
148 return _res; |
111 }, |
149 }, |
112 serializer : function(_data, _source) { |
150 serializer : function(_data, _source, _dest) { |
113 return { |
151 var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
|
152 var _res = { |
114 id : _data.id, |
153 id : _data.id, |
115 begin : _data.begin.milliseconds, |
154 begin : _data.begin.milliseconds, |
116 end : _data.end.milliseconds, |
155 end : _data.end.milliseconds, |
117 content : { |
156 content : { |
118 title : _data.title, |
157 title : _data.title || "", |
119 description : _data.description, |
158 description : _data.description || "", |
120 audio : _data.audio |
159 audio : _data.audio, |
121 }, |
160 img: { |
|
161 src: _data.thumbnail |
|
162 } |
|
163 }, |
|
164 color: _color, |
122 media : _data.media.id, |
165 media : _data.media.id, |
123 meta : { |
166 meta : { |
124 "id-ref" : _data.getAnnotationType().id, |
167 "id-ref" : _data.getAnnotationType().id, |
125 "dc:created" : IriSP.Model.dateToIso(_data.created), |
168 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
126 "dc:creator" : _data.creator, |
169 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
127 project : _source.projectId |
170 "dc:creator" : _data.creator || _source.creator, |
|
171 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
|
172 // project : _source.projectId |
128 }, |
173 }, |
129 tags : IriSP._(_data.tag.id).map(function(_id) { |
174 tags : IriSP._(_data.tag.id).map(function(_id) { |
130 return { |
175 return { |
131 "id-ref" : _id |
176 "id-ref" : _id |
132 } |
177 } |
133 }) |
178 }) |
134 } |
179 } |
|
180 _dest.annotations.push(_res); |
135 } |
181 } |
136 }, |
182 }, |
137 mashup : { |
183 mashup : { |
138 serialized_name : "lists", |
184 serialized_name : "lists", |
139 deserializer : function(_data, _source) { |
185 deserializer : function(_data, _source) { |
145 _res.description = _data.meta["dc:description"]; |
191 _res.description = _data.meta["dc:description"]; |
146 _res.creator = _data.meta["dc:creator"]; |
192 _res.creator = _data.meta["dc:creator"]; |
147 _res.setAnnotationsById(_data.items); |
193 _res.setAnnotationsById(_data.items); |
148 return _res; |
194 return _res; |
149 }, |
195 }, |
150 serializer : function(_data, _source) { |
196 serializer : function(_data, _source, _dest) { |
151 return { |
197 var _res = { |
152 meta : { |
198 meta : { |
153 "dc:title": _data.title, |
199 "dc:title": _data.title || "", |
154 "dc:description": _data.description, |
200 "dc:description": _data.description || "", |
|
201 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
|
202 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
|
203 "dc:creator" : _data.creator || _source.creator, |
|
204 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
155 listtype: "mashup" |
205 listtype: "mashup" |
156 }, |
206 }, |
157 items: _data.segments.map(function(_annotation) { |
207 items: _data.segments.map(function(_annotation) { |
158 return _annotation.annotation.id; |
208 return _annotation.annotation.id; |
159 }), |
209 }), |
160 id: _data.id |
210 id: _data.id |
161 } |
211 } |
|
212 _dest.lists.push(_res); |
162 } |
213 } |
163 } |
214 } |
164 }, |
215 }, |
165 serialize : function(_source) { |
216 serialize : function(_source) { |
166 var _res = { |
217 var _res = { |
167 meta: { |
218 meta: { |
168 "dc:creator": _source.creator, |
219 "dc:creator": _source.creator, |
|
220 "dc:contributor" : _source.contributor || _source.creator, |
169 "dc:created": IriSP.Model.dateToIso(_source.created), |
221 "dc:created": IriSP.Model.dateToIso(_source.created), |
170 "dc:title": _source.title, |
222 "dc:modified" : IriSP.Model.dateToIso(_source.modified), |
171 "dc:description": _source.description, |
223 "dc:title": _source.title || "", |
172 "id": _source.projectId || _source.id |
224 "dc:description": _source.description || "", |
|
225 id: _source.projectId || _source.id |
173 }, |
226 }, |
174 views: [] |
227 views: [ |
|
228 { |
|
229 id: IriSP.Model.getUID(), |
|
230 contents: [], |
|
231 annotation_types: [] |
|
232 } |
|
233 ], |
|
234 lists: [], |
|
235 "annotation-types": [], |
|
236 medias: [], |
|
237 tags: [], |
|
238 annotations: [] |
175 }, |
239 }, |
176 _this = this; |
240 _this = this; |
177 _source.forEach(function(_list, _typename) { |
241 _source.forEach(function(_list, _typename) { |
178 if (typeof _this.types[_typename] !== "undefined") { |
242 if (typeof _this.types[_typename] !== "undefined") { |
179 _res[_this.types[_typename].serialized_name] = _list.map(function(_el) { |
243 _list.forEach(function(_el) { |
180 return _this.types[_typename].serializer(_el, _source); |
244 _this.types[_typename].serializer(_el, _source, _res); |
181 }); |
245 }); |
182 } |
246 } |
183 }); |
247 }); |
184 return JSON.stringify(_res); |
248 return JSON.stringify(_res); |
185 }, |
|
186 loadData : function(_url, _callback) { |
|
187 IriSP.jQuery.getJSON(_url, _callback) |
|
188 }, |
249 }, |
189 deSerialize : function(_data, _source) { |
250 deSerialize : function(_data, _source) { |
190 if (typeof _data !== "object" || _data === null) { |
251 if (typeof _data !== "object" || _data === null) { |
191 return; |
252 return; |
192 } |
253 } |