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