1 /* data.js - this file deals with how the players gets and sends data */ |
1 /* data.js - this file deals with how the players gets and sends data */ |
|
2 define(["IriSP"], function() { |
|
3 IriSP.DataLoader = function() { |
|
4 this._cache = {}; |
|
5 }; |
2 |
6 |
3 IriSP.DataLoader = function() { |
7 IriSP.DataLoader.prototype.get = function(url, callback) { |
4 this._cache = {}; |
8 if (this._cache.hasOwnProperty(url)) { |
5 }; |
9 callback(this._cache[url]); |
|
10 } else { |
|
11 /* we need a closure because this gets lost when it's called back */ |
|
12 IriSP.jQuery.get(url, callback); |
|
13 /* |
|
14 IriSP.jQuery.get(url, (function(obj) { |
|
15 return function(data) { |
|
16 obj._cache[url] = data; |
|
17 callback(obj._cache[url]); |
|
18 }; |
|
19 })(this)); |
|
20 */ |
|
21 |
|
22 } |
|
23 } |
6 |
24 |
7 IriSP.DataLoader.prototype.get = function(url, callback) { |
25 /* the base abstract "class" */ |
8 if (this._cache.hasOwnProperty(url)) { |
26 IriSP.Serializer = function(DataLoader, url) { |
9 callback(this._cache[url]); |
27 this._DataLoader = DataLoader; |
10 } else { |
28 this._url = url; |
11 /* we need a closure because this gets lost when it's called back */ |
29 this._data = []; |
12 IriSP.jQuery.get(url, callback); |
30 }; |
13 /* |
31 |
14 IriSP.jQuery.get(url, (function(obj) { |
32 IriSP.Serializer.prototype.serialize = function(data) { }; |
15 return function(data) { |
33 IriSP.Serializer.prototype.deserialize = function(data) {}; |
16 obj._cache[url] = data; |
34 |
17 callback(obj._cache[url]); |
35 IriSP.Serializer.prototype.currentMedia = function() { |
18 }; |
36 }; |
19 })(this)); |
37 |
|
38 IriSP.Serializer.prototype.sync = function(callback) { |
|
39 callback.call(this, this._data); |
|
40 }; |
|
41 |
|
42 IriSP.SerializerFactory = function(DataLoader) { |
|
43 this._dataloader = DataLoader; |
|
44 }; |
|
45 |
|
46 IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { |
|
47 /* This function returns serializer set-up with the correct |
|
48 configuration - takes a metadata struct describing the metadata source |
20 */ |
49 */ |
21 |
|
22 } |
|
23 } |
|
24 |
|
25 /* the base abstract "class" */ |
|
26 IriSP.Serializer = function(DataLoader, url) { |
|
27 this._DataLoader = DataLoader; |
|
28 this._url = url; |
|
29 this._data = []; |
|
30 }; |
|
31 |
|
32 IriSP.Serializer.prototype.serialize = function(data) { }; |
|
33 IriSP.Serializer.prototype.deserialize = function(data) {}; |
|
34 |
|
35 IriSP.Serializer.prototype.currentMedia = function() { |
|
36 }; |
|
37 |
|
38 IriSP.Serializer.prototype.sync = function(callback) { |
|
39 callback.call(this, this._data); |
|
40 }; |
|
41 |
|
42 IriSP.SerializerFactory = function(DataLoader) { |
|
43 this._dataloader = DataLoader; |
|
44 }; |
|
45 |
|
46 IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { |
|
47 /* This function returns serializer set-up with the correct |
|
48 configuration - takes a metadata struct describing the metadata source |
|
49 */ |
|
50 |
|
51 if (metadataOptions === undefined) |
|
52 /* return an empty serializer */ |
|
53 return IriSP.Serializer("", ""); |
|
54 |
|
55 switch(metadataOptions.type) { |
|
56 case "json": |
|
57 return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); |
|
58 break; |
|
59 |
50 |
60 case "dummy": /* only used for unit testing - not defined in production */ |
51 if (metadataOptions === undefined) |
61 return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); |
52 /* return an empty serializer */ |
62 break; |
53 return IriSP.Serializer("", ""); |
63 |
54 |
64 case "empty": |
55 switch(metadataOptions.type) { |
65 return new IriSP.Serializer("", "empty"); |
56 case "json": |
66 break; |
57 return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); |
|
58 break; |
67 |
59 |
68 default: |
60 case "dummy": /* only used for unit testing - not defined in production */ |
69 return undefined; |
61 return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); |
70 } |
62 break; |
71 }; |
63 |
|
64 case "empty": |
|
65 return new IriSP.Serializer("", "empty"); |
|
66 break; |
|
67 |
|
68 default: |
|
69 return undefined; |
|
70 } |
|
71 }; |
72 |
72 |
73 |
73 |
74 IriSP.getMetadata = function() { |
74 IriSP.getMetadata = function() { |
75 |
75 |
76 IriSP.jQuery.ajax({ |
76 IriSP.jQuery.ajax({ |
77 dataType: IriSP.config.metadata.load, |
77 dataType: IriSP.config.metadata.load, |
78 url:IriSP.config.metadata.src, |
78 url:IriSP.config.metadata.src, |
79 success : function( json ){ |
79 success : function( json ){ |
80 |
80 |
81 IriSP.trace( "ajax", "success" ); |
81 IriSP.trace( "ajax", "success" ); |
82 |
82 |
83 // START PARSING ----------------------- |
83 // START PARSING ----------------------- |
84 if( json === "" ){ |
84 if( json === "" ){ |
85 alert( "Json load error" ); |
85 alert( "Json load error" ); |
86 } else { |
86 } else { |
87 // # CREATE MEDIA // |
87 // # CREATE MEDIA // |
88 // # JUSTE ONE PLAYER FOR THE MOMENT // |
88 // # JUSTE ONE PLAYER FOR THE MOMENT // |
89 //__IriSP.jQuery("<div></div>").appendTo("#output"); |
89 //__IriSP.jQuery("<div></div>").appendTo("#output"); |
90 var MyMedia = new __IriSP.Media( |
90 var MyMedia = new __IriSP.Media( |
91 json.medias[0].id, |
91 json.medias[0].id, |
92 json.medias[0].href, |
92 json.medias[0].href, |
93 json.medias[0]['meta']['dc:duration'], |
93 json.medias[0]['meta']['dc:duration'], |
94 json.medias[0]['dc:title'], |
94 json.medias[0]['dc:title'], |
95 json.medias[0]['dc:description']); |
95 json.medias[0]['dc:description']); |
96 |
96 |
97 IriSP.trace( "__IriSP.MyApiPlayer", |
97 IriSP.trace( "__IriSP.MyApiPlayer", |
98 IriSP.config.gui.width+" " |
98 IriSP.config.gui.width+" " |
99 + IriSP.config.gui.height + " " |
99 + IriSP.config.gui.height + " " |
100 + json.medias[0].href + " " |
100 + json.medias[0].href + " " |
101 + json.medias[0]['meta']['dc:duration'] + " " |
101 + json.medias[0]['meta']['dc:duration'] + " " |
102 + json.medias[0]['meta']['item']['value']); |
102 + json.medias[0]['meta']['item']['value']); |
103 |
103 |
104 // Create APIplayer |
104 // Create APIplayer |
105 IriSP.MyApiPlayer = new __IriSP.APIplayer ( |
105 IriSP.MyApiPlayer = new __IriSP.APIplayer ( |
106 IriSP.config.gui.width, |
106 IriSP.config.gui.width, |
107 IriSP.config.gui.height, |
107 IriSP.config.gui.height, |
108 json.medias[0].href, |
108 json.medias[0].href, |
109 json.medias[0]['meta']['dc:duration'], |
109 json.medias[0]['meta']['dc:duration'], |
110 json.medias[0]['meta']['item']['value']); |
110 json.medias[0]['meta']['item']['value']); |
111 |
111 |
112 // # CREATE THE FIRST LINE // |
112 // # CREATE THE FIRST LINE // |
113 IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" ); |
113 IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" ); |
114 IriSP.MyLdt = new __IriSP.Ligne( |
114 IriSP.MyLdt = new __IriSP.Ligne( |
115 json['annotation-types'][0].id, |
115 json['annotation-types'][0].id, |
116 json['annotation-types'][0]['dc:title'], |
116 json['annotation-types'][0]['dc:title'], |
117 json['annotation-types'][0]['dc:description'], |
117 json['annotation-types'][0]['dc:description'], |
118 json.medias[0]['meta']['dc:duration']); |
118 json.medias[0]['meta']['dc:duration']); |
119 |
119 |
120 // CREATE THE TAG CLOUD // |
120 // CREATE THE TAG CLOUD // |
121 IriSP.trace( "__IriSP.init.main","__IriSP.Tags" ); |
121 IriSP.trace( "__IriSP.init.main","__IriSP.Tags" ); |
122 IriSP.MyTags = new __IriSP.Tags( json.tags ); |
122 IriSP.MyTags = new __IriSP.Tags( json.tags ); |
123 |
123 |
124 // CREATE THE ANNOTATIONS // |
124 // CREATE THE ANNOTATIONS // |
125 // JUSTE FOR THE FIRST TYPE // |
125 // JUSTE FOR THE FIRST TYPE // |
126 /* FIXME: make it support more than one ligne de temps */ |
126 /* FIXME: make it support more than one ligne de temps */ |
127 IriSP.jQuery.each( json.annotations, function(i,item) { |
127 IriSP.jQuery.each( json.annotations, function(i,item) { |
128 if (item.meta['id-ref'] == IriSP.MyLdt.id) { |
128 if (item.meta['id-ref'] == IriSP.MyLdt.id) { |
129 //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation"); |
129 //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation"); |
130 IriSP.MyLdt.addAnnotation( |
130 IriSP.MyLdt.addAnnotation( |
131 item.id, |
131 item.id, |
132 item.begin, |
132 item.begin, |
133 item.end, |
133 item.end, |
134 item.media, |
134 item.media, |
135 item.content.title, |
135 item.content.title, |
136 item.content.description, |
136 item.content.description, |
137 item.content.color, |
137 item.content.color, |
138 item.tags); |
138 item.tags); |
139 } |
139 } |
140 //MyTags.addAnnotation(item); |
140 //MyTags.addAnnotation(item); |
141 } ); |
141 } ); |
142 IriSP.jQuery.each( json.lists, function(i,item) { |
142 IriSP.jQuery.each( json.lists, function(i,item) { |
143 IriSP.trace("lists",""); |
143 IriSP.trace("lists",""); |
144 } ); |
144 } ); |
145 IriSP.jQuery.each( json.views, function(i,item) { |
145 IriSP.jQuery.each( json.views, function(i,item) { |
146 IriSP.trace("views",""); |
146 IriSP.trace("views",""); |
147 } ); |
147 } ); |
148 } |
148 } |
149 // END PARSING ----------------------- // |
149 // END PARSING ----------------------- // |
150 |
150 |
151 |
151 |
152 }, error : function(data){ |
152 }, error : function(data){ |
153 alert("ERROR : "+data); |
153 alert("ERROR : "+data); |
154 } |
154 } |
155 }); |
155 }); |
156 |
156 |
157 } |
157 } |
|
158 }); |