|
1 /* SPEL Serializer */ |
|
2 |
|
3 if (typeof IriSP.serializers === "undefined") { |
|
4 IriSP.serializers = {}; |
|
5 } |
|
6 |
|
7 IriSP.serializers.spel = { |
|
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 = _data.url; |
|
14 _res.title = _data.meta["dc:title"] || _data.meta.title || ""; |
|
15 _res.description = _data.meta["dc:description"] || _data.meta.description || ""; |
|
16 _res.setDuration(_data.meta["dc:duration"] || _data.meta.duration || ""); |
|
17 return _res; |
|
18 } |
|
19 }, |
|
20 annotationType : { |
|
21 serialized_name : "annotation_types", |
|
22 deserializer : function(_data, _source) { |
|
23 var _res = new IriSP.Model.AnnotationType(_data.id, _source); |
|
24 _res.title = _data["dc:title"] || _data.title || _data.id; |
|
25 _res.description = _data["dc:description"] || _data.description || ("Annotation type: " + _data.id); |
|
26 return _res; |
|
27 } |
|
28 }, |
|
29 annotation : { |
|
30 serialized_name : "annotations", |
|
31 deserializer : function(_data, _source) { |
|
32 var _res = new IriSP.Model.Annotation(_data.id, _source); |
|
33 function shortenText(_text, _maxlength) { |
|
34 return (_text.length > _maxlength ? (_text.substr(0,_maxlength) + '…') : _text); |
|
35 } |
|
36 switch (typeof _data.content.data) { |
|
37 case "object": |
|
38 _res.description = IriSP._(_data.content.data).map(function(v, k) { |
|
39 return k + ": " + v; |
|
40 }).join("\n"); |
|
41 _res.title = shortenText(_data.content.data.titre || _data.content.data.ref_text || "", 40); |
|
42 break; |
|
43 case "string": |
|
44 _res.description = _data.content.data; |
|
45 _res.title = shortenText(_data.content.data, 40); |
|
46 break; |
|
47 } |
|
48 switch (_data.type) { |
|
49 case "performance": |
|
50 _res.color = '#ff8000'; |
|
51 break; |
|
52 case "discussion": |
|
53 _res.color = '#000080'; |
|
54 break; |
|
55 } |
|
56 _res.content = _data.content; |
|
57 _res.setMedia(_data.media); |
|
58 _res.setAnnotationType(_data.type); |
|
59 _res.setBegin(_data.begin); |
|
60 _res.setEnd(_data.end); |
|
61 return _res; |
|
62 } |
|
63 } |
|
64 }, |
|
65 deSerialize : function(_data, _source) { |
|
66 if (typeof _data !== "object" || _data === null) { |
|
67 return; |
|
68 } |
|
69 IriSP._(this.types).forEach(function(_type, _typename) { |
|
70 var _listdata = _data[_type.serialized_name], |
|
71 _list = new IriSP.Model.List(_source.directory); |
|
72 if (typeof _listdata !== "undefined" && _listdata !== null) { |
|
73 if (_listdata.hasOwnProperty("length")) { |
|
74 var _l = _listdata.length; |
|
75 for (var _i = 0; _i < _l; _i++) { |
|
76 var _element = _type.deserializer(_listdata[_i], _source); |
|
77 if (typeof _element !== "undefined" && _element) { |
|
78 _list.push(_element); |
|
79 } |
|
80 } |
|
81 } else { |
|
82 var _element = _type.deserializer(_listdata, _source); |
|
83 if (typeof _element !== "undefined" && _element) { |
|
84 _list.push(_element); |
|
85 } |
|
86 } |
|
87 } |
|
88 _source.addList(_typename, _list); |
|
89 }); |
|
90 |
|
91 if (typeof _data.meta !== "undefined") { |
|
92 _source.projectId = _data.meta.id; |
|
93 _source.title = _data.meta["dc:title"] || _data.meta.title || ""; |
|
94 _source.description = _data.meta["dc:description"] || _data.meta.description || ""; |
|
95 _source.creator = _data.meta["dc:creator"] || _data.meta.creator || ""; |
|
96 _source.contributor = _data.meta["dc:contributor"] || _data.meta.contributor || _source.creator; |
|
97 _source.created = IriSP.Model.isoToDate(_data.meta["dc:created"] || _data.meta.created); |
|
98 } |
|
99 |
|
100 if (typeof _data.meta !== "undefined" && typeof _data.meta.main_media !== "undefined" && typeof _data.meta.main_media["id-ref"] !== "undefined") { |
|
101 _source.currentMedia = _source.getElement(_data.meta.main_media["id-ref"]); |
|
102 } |
|
103 } |
|
104 }; |
|
105 |
|
106 /* End of SPEL Serializer */ |