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