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