42 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
42 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
43 "dc:creator" : _data.creator || _source.creator, |
43 "dc:creator" : _data.creator || _source.creator, |
44 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
44 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
45 "dc:duration" : _data.duration.milliseconds |
45 "dc:duration" : _data.duration.milliseconds |
46 } |
46 } |
47 } |
47 }; |
48 _dest.medias.push(_res); |
48 _dest.medias.push(_res); |
49 var _list = { |
49 var _list = { |
50 id: IriSP.Model.getUID(), |
50 id: IriSP.Model.getUID(), |
51 meta : { |
51 meta : { |
52 "dc:title": _data.title || "", |
52 "dc:title": _data.title || "", |
56 "dc:creator" : _data.creator || _source.creator, |
56 "dc:creator" : _data.creator || _source.creator, |
57 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
57 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
58 "id-ref": _data.id |
58 "id-ref": _data.id |
59 }, |
59 }, |
60 items: _source.getAnnotationTypes().filter(function(_at) { |
60 items: _source.getAnnotationTypes().filter(function(_at) { |
61 return _at.media === _data; |
61 switch (typeof _at.media) { |
|
62 case "object": |
|
63 return (_at.media === _data); |
|
64 case "string": |
|
65 return (_at.media === _data.id); |
|
66 default: |
|
67 var _ann = _at.getAnnotations(); |
|
68 if (_ann) { |
|
69 for (var i = 0; i < _ann.length; i++) { |
|
70 if (_ann[i].getMedia() === _data) { |
|
71 return true; |
|
72 } |
|
73 } |
|
74 } |
|
75 } |
|
76 return false; |
62 }).map(function(_at) { |
77 }).map(function(_at) { |
63 return { |
78 return { |
64 "id-ref": _at.id |
79 "id-ref": _at.id |
65 } |
80 }; |
66 }) |
81 }) |
67 } |
82 }; |
68 _dest.lists.push(_list); |
83 _dest.lists.push(_list); |
69 _dest.views[0].contents.push(_data.id); |
84 _dest.views[0].contents.push(_data.id); |
70 } |
85 } |
71 }, |
86 }, |
72 tag : { |
87 tag : { |
73 serialized_name : "tags", |
88 serialized_name : "tags", |
74 model_name : "tag", |
|
75 deserializer : function(_data, _source) { |
89 deserializer : function(_data, _source) { |
76 var _res = new IriSP.Model.Tag(_data.id, _source); |
90 var _res = new IriSP.Model.Tag(_data.id, _source); |
77 _res.title = _data.meta["dc:title"]; |
91 _res.title = _data.meta["dc:title"]; |
78 return _res; |
92 return _res; |
79 }, |
93 }, |
80 serializer : function(_data, _source, _dest) { |
94 serializer : function(_data, _source, _dest) { |
|
95 if (_source.regenerateTags && !_data.regenerated) { |
|
96 return; |
|
97 } |
81 var _res = { |
98 var _res = { |
82 id : _data.id, |
99 id : _data.id, |
83 meta : { |
100 meta : { |
84 "dc:title": _data.title || "", |
101 "dc:title": _data.title || "", |
85 "dc:description": _data.description || "", |
102 "dc:description": _data.description || "", |
86 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
103 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
87 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
104 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
88 "dc:creator" : _data.creator || _source.creator, |
105 "dc:creator" : _data.creator || _source.creator, |
89 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
106 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
90 } |
107 } |
91 } |
108 }; |
92 _dest.tags.push(_res); |
109 _dest.tags.push(_res); |
93 } |
110 } |
94 }, |
111 }, |
95 annotationType : { |
112 annotationType : { |
96 serialized_name : "annotation-types", |
113 serialized_name : "annotation-types", |
107 "dc:description": _data.description || "", |
124 "dc:description": _data.description || "", |
108 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
125 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
109 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
126 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
110 "dc:creator" : _data.creator || _source.creator, |
127 "dc:creator" : _data.creator || _source.creator, |
111 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
128 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
112 } |
129 }; |
113 _dest["annotation-types"].push(_res); |
130 _dest["annotation-types"].push(_res); |
114 _dest.views[0].annotation_types.push(_data.id); |
131 _dest.views[0].annotation_types.push(_data.id); |
115 } |
132 } |
116 }, |
133 }, |
117 annotation : { |
134 annotation : { |
129 while (_c.length < 6) { |
146 while (_c.length < 6) { |
130 _c = '0' + _c; |
147 _c = '0' + _c; |
131 } |
148 } |
132 _res.color = '#' + _c; |
149 _res.color = '#' + _c; |
133 } |
150 } |
|
151 _res.content = _data.content; |
134 _res.setMedia(_data.media); |
152 _res.setMedia(_data.media); |
135 _res.setAnnotationType(_data.meta["id-ref"]); |
153 _res.setAnnotationType(_data.meta["id-ref"]); |
136 _res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
154 _res.setTags(IriSP._(_data.tags).pluck("id-ref")); |
137 _res.keywords = _res.getTagTexts(); |
155 _res.keywords = _res.getTagTexts(); |
138 _res.setBegin(_data.begin); |
156 _res.setBegin(_data.begin); |
151 var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
169 var _color = parseInt(_data.color.replace(/^#/,''),16).toString(); |
152 var _res = { |
170 var _res = { |
153 id : _data.id, |
171 id : _data.id, |
154 begin : _data.begin.milliseconds, |
172 begin : _data.begin.milliseconds, |
155 end : _data.end.milliseconds, |
173 end : _data.end.milliseconds, |
156 content : { |
174 content : IriSP._.defaults( |
157 title : _data.title || "", |
175 {}, |
158 description : _data.description || "", |
176 { |
|
177 title : _data.title, |
|
178 description : _data.description, |
159 audio : _data.audio, |
179 audio : _data.audio, |
160 img: { |
180 img: { |
161 src: _data.thumbnail |
181 src: _data.thumbnail |
162 } |
182 } |
163 }, |
183 }, |
|
184 _data.content, |
|
185 { |
|
186 title: "", |
|
187 description: "" |
|
188 } |
|
189 ), |
164 color: _color, |
190 color: _color, |
165 media : _data.media.id, |
191 media : _data.media.id, |
166 meta : { |
192 meta : { |
167 "id-ref" : _data.getAnnotationType().id, |
193 "id-ref" : _data.getAnnotationType().id, |
168 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
194 "dc:created" : IriSP.Model.dateToIso(_data.created || _source.created), |
169 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
195 "dc:modified" : IriSP.Model.dateToIso(_data.modified || _source.modified), |
170 "dc:creator" : _data.creator || _source.creator, |
196 "dc:creator" : _data.creator || _source.creator, |
171 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
197 "dc:contributor" : _data.contributor || _source.contributor || _data.creator || _source.creator, |
172 // project : _source.projectId |
198 // project : _source.projectId |
173 }, |
199 } |
174 tags : IriSP._(_data.tag.id).map(function(_id) { |
200 }; |
|
201 if (_source.regenerateTags) { |
|
202 _res.tags = IriSP._(_data.keywords).map(function(_kw) { |
|
203 return { |
|
204 "id-ref": _source.__keywords[_kw.toLowerCase()].id |
|
205 }; |
|
206 }); |
|
207 } else { |
|
208 _res.tags = IriSP._(_data.tag.id).map(function(_id) { |
175 return { |
209 return { |
176 "id-ref" : _id |
210 "id-ref" : _id |
177 } |
211 }; |
178 }) |
212 }); |
179 } |
213 } |
|
214 _res.content.title = _data.title || _res.content.title || ""; |
180 _dest.annotations.push(_res); |
215 _dest.annotations.push(_res); |
181 } |
216 } |
182 }, |
217 }, |
183 mashup : { |
218 mashup : { |
184 serialized_name : "lists", |
219 serialized_name : "lists", |
236 medias: [], |
271 medias: [], |
237 tags: [], |
272 tags: [], |
238 annotations: [] |
273 annotations: [] |
239 }, |
274 }, |
240 _this = this; |
275 _this = this; |
|
276 if (_source.regenerateTags) { |
|
277 _source.__keywords = {}; |
|
278 _source.getAnnotations().forEach(function(a) { |
|
279 IriSP._(a.keywords).each(function(kw) { |
|
280 var lkw = kw.toLowerCase(); |
|
281 if (typeof _source.__keywords[lkw] === "undefined") { |
|
282 _source.__keywords[lkw] = { |
|
283 id: IriSP.Model.getUID(), |
|
284 title: kw, |
|
285 regenerated: true |
|
286 }; |
|
287 } |
|
288 }); |
|
289 }); |
|
290 IriSP._(_source.__keywords).each(function(kw) { |
|
291 _this.types.tag.serializer(kw, _source, _res); |
|
292 }); |
|
293 } |
241 _source.forEach(function(_list, _typename) { |
294 _source.forEach(function(_list, _typename) { |
242 if (typeof _this.types[_typename] !== "undefined") { |
295 if (typeof _this.types[_typename] !== "undefined") { |
243 _list.forEach(function(_el) { |
296 _list.forEach(function(_el) { |
244 _this.types[_typename].serializer(_el, _source, _res); |
297 _this.types[_typename].serializer(_el, _source, _res); |
245 }); |
298 }); |
273 _source.addList(_typename, _list); |
326 _source.addList(_typename, _list); |
274 }); |
327 }); |
275 |
328 |
276 if (typeof _data.meta !== "undefined") { |
329 if (typeof _data.meta !== "undefined") { |
277 _source.projectId = _data.meta.id; |
330 _source.projectId = _data.meta.id; |
|
331 _source.title = _data.meta["dc:title"] || _data.meta.title || ""; |
|
332 _source.description = _data.meta["dc:description"] || _data.meta.description || ""; |
|
333 _source.creator = _data.meta["dc:creator"] || _data.meta.creator || ""; |
|
334 _source.contributor = _data.meta["dc:contributor"] || _data.meta.contributor || _source.creator; |
|
335 _source.created = IriSP.Model.isoToDate(_data.meta["dc:created"] || _data.meta.created); |
278 } |
336 } |
279 |
337 |
280 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
338 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
281 _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
339 _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
282 } |
340 } |
283 } |
341 } |
284 } |
342 }; |
285 |
343 |
286 /* END ldt-serializer.js */ |
344 /* End of LDT Platform Serializer */ |
287 |
|