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 |
2 |
3 IriSP.getMetadata = function() { |
3 IriSP.DataLoader = function() { |
4 |
4 this._cache = {}; |
5 IriSP.jQuery.ajax({ |
5 |
6 dataType: IriSP.config.metadata.load, |
6 /* |
7 url:IriSP.config.metadata.src, |
7 A structure to hold callbacks for specific urls. We need it because |
8 success : function( json ){ |
8 ajax calls are asynchronous, so it means that sometimes we ask |
9 |
9 multiple times for a ressource because the first call hasn't been |
10 IriSP.trace( "ajax", "success" ); |
10 received yet. |
11 |
11 */ |
12 // START PARSING ----------------------- |
12 this._callbacks = {}; |
13 if( json === "" ){ |
13 }; |
14 alert( "Json load error" ); |
|
15 } else { |
|
16 // # CREATE MEDIA // |
|
17 // # JUSTE ONE PLAYER FOR THE MOMENT // |
|
18 //__IriSP.jQuery("<div></div>").appendTo("#output"); |
|
19 var MyMedia = new __IriSP.Media( |
|
20 json.medias[0].id, |
|
21 json.medias[0].href, |
|
22 json.medias[0]['meta']['dc:duration'], |
|
23 json.medias[0]['dc:title'], |
|
24 json.medias[0]['dc:description']); |
|
25 |
|
26 IriSP.trace( "__IriSP.MyApiPlayer", |
|
27 IriSP.config.gui.width+" " |
|
28 + IriSP.config.gui.height + " " |
|
29 + json.medias[0].href + " " |
|
30 + json.medias[0]['meta']['dc:duration'] + " " |
|
31 + json.medias[0]['meta']['item']['value']); |
|
32 |
|
33 // Create APIplayer |
|
34 IriSP.MyApiPlayer = new __IriSP.APIplayer ( |
|
35 IriSP.config.gui.width, |
|
36 IriSP.config.gui.height, |
|
37 json.medias[0].href, |
|
38 json.medias[0]['meta']['dc:duration'], |
|
39 json.medias[0]['meta']['item']['value']); |
|
40 |
|
41 // # CREATE THE FIRST LINE // |
|
42 IriSP.trace( "__IriSP.init.main","__IriSP.Ligne" ); |
|
43 IriSP.MyLdt = new __IriSP.Ligne( |
|
44 json['annotation-types'][0].id, |
|
45 json['annotation-types'][0]['dc:title'], |
|
46 json['annotation-types'][0]['dc:description'], |
|
47 json.medias[0]['meta']['dc:duration']); |
|
48 |
|
49 // CREATE THE TAG CLOUD // |
|
50 IriSP.trace( "__IriSP.init.main","__IriSP.Tags" ); |
|
51 IriSP.MyTags = new __IriSP.Tags( json.tags ); |
|
52 |
|
53 // CREATE THE ANNOTATIONS // |
|
54 // JUSTE FOR THE FIRST TYPE // |
|
55 /* FIXME: make it support more than one ligne de temps */ |
|
56 IriSP.jQuery.each( json.annotations, function(i,item) { |
|
57 if (item.meta['id-ref'] == IriSP.MyLdt.id) { |
|
58 //__IriSP.trace("__IriSP.init.main","__IriSP.MyLdt.addAnnotation"); |
|
59 IriSP.MyLdt.addAnnotation( |
|
60 item.id, |
|
61 item.begin, |
|
62 item.end, |
|
63 item.media, |
|
64 item.content.title, |
|
65 item.content.description, |
|
66 item.content.color, |
|
67 item.tags); |
|
68 } |
|
69 //MyTags.addAnnotation(item); |
|
70 } ); |
|
71 IriSP.jQuery.each( json.lists, function(i,item) { |
|
72 IriSP.trace("lists",""); |
|
73 } ); |
|
74 IriSP.jQuery.each( json.views, function(i,item) { |
|
75 IriSP.trace("views",""); |
|
76 } ); |
|
77 } |
|
78 // END PARSING ----------------------- // |
|
79 |
|
80 |
|
81 }, error : function(data){ |
|
82 alert("ERROR : "+data); |
|
83 } |
|
84 }); |
|
85 |
14 |
|
15 IriSP.DataLoader.prototype.get = function(url, callback, force_reload) { |
|
16 var base_url = url.split("&")[0]; |
|
17 if (typeof force_reload != "undefined" && force_reload && this._cache.hasOwnProperty(base_url)) { |
|
18 delete this._cache[base_url] |
|
19 } |
|
20 if (this._cache.hasOwnProperty(base_url)) { |
|
21 callback(this._cache[base_url]); |
|
22 } else { |
|
23 if (!this._callbacks.hasOwnProperty(base_url)) { |
|
24 this._callbacks[base_url] = [callback]; |
|
25 /* we need a closure because this gets lost when it's called back */ |
|
26 |
|
27 // uncomment you don't want to use caching. |
|
28 // IriSP.jQuery.get(url, callback); |
|
29 |
|
30 var func = function(data) { |
|
31 this._cache[base_url] = data; |
|
32 var i = 0; |
|
33 |
|
34 for (i = 0; i < this._callbacks[base_url].length; i++) { |
|
35 this._callbacks[base_url][i](this._cache[base_url]); |
|
36 } |
|
37 delete this._callbacks[base_url]; |
|
38 }; |
|
39 |
|
40 /* automagically choose between json and jsonp */ |
|
41 if (url.indexOf(document.location.hostname) === -1 && |
|
42 url.indexOf("http://") !== -1 /* not a relative url */ ) { |
|
43 // we contacting a foreign domain, use JSONP |
|
44 |
|
45 IriSP.jQuery.get(url, {}, IriSP.wrap(this, func), "jsonp"); |
|
46 } else { |
|
47 |
|
48 // otherwise, hey, whatever rows your boat |
|
49 IriSP.jQuery.get(url, IriSP.wrap(this, func)); |
|
50 } |
|
51 |
|
52 } else { |
|
53 /* simply push the callback - it'll get called when the ressource |
|
54 has been received */ |
|
55 |
|
56 this._callbacks[base_url].push(callback); |
|
57 |
|
58 } |
|
59 } |
86 } |
60 } |
|
61 |
|
62 /* the base abstract "class" */ |
|
63 IriSP.Serializer = function(DataLoader, url) { |
|
64 this._DataLoader = DataLoader; |
|
65 this._url = url; |
|
66 this._data = []; |
|
67 }; |
|
68 |
|
69 IriSP.Serializer.prototype.serialize = function(data) { }; |
|
70 IriSP.Serializer.prototype.deserialize = function(data) {}; |
|
71 |
|
72 IriSP.Serializer.prototype.currentMedia = function() { |
|
73 }; |
|
74 |
|
75 IriSP.Serializer.prototype.getDuration = function() { |
|
76 }; |
|
77 |
|
78 IriSP.Serializer.prototype.sync = function(callback) { |
|
79 this._DataLoader.get(this._url, callback, force_refresh); |
|
80 }; |
|
81 |
|
82 IriSP.SerializerFactory = function(DataLoader) { |
|
83 this._dataloader = DataLoader; |
|
84 }; |
|
85 |
|
86 IriSP.SerializerFactory.prototype.getSerializer = function(metadataOptions) { |
|
87 /* This function returns serializer set-up with the correct |
|
88 configuration - takes a metadata struct describing the metadata source |
|
89 */ |
|
90 |
|
91 if (metadataOptions === undefined) |
|
92 /* return an empty serializer */ |
|
93 return IriSP.Serializer("", ""); |
|
94 |
|
95 switch(metadataOptions.type) { |
|
96 case "json": |
|
97 return new IriSP.JSONSerializer(this._dataloader, metadataOptions.src); |
|
98 break; |
|
99 |
|
100 case "dummy": /* only used for unit testing - not defined in production */ |
|
101 return new IriSP.MockSerializer(this._dataloader, metadataOptions.src); |
|
102 break; |
|
103 |
|
104 case "empty": |
|
105 return new IriSP.Serializer("", "empty"); |
|
106 break; |
|
107 |
|
108 default: |
|
109 return undefined; |
|
110 } |
|
111 }; |