equal
deleted
inserted
replaced
7 IriSP.DataLoader.prototype.get = function(url, callback) { |
7 IriSP.DataLoader.prototype.get = function(url, callback) { |
8 if (this._cache.hasOwnProperty(url)) { |
8 if (this._cache.hasOwnProperty(url)) { |
9 callback(this._cache[url]); |
9 callback(this._cache[url]); |
10 } else { |
10 } else { |
11 /* we need a closure because this gets lost when it's called back */ |
11 /* we need a closure because this gets lost when it's called back */ |
|
12 IriSP.jQuery.get(url, callback); |
|
13 /* |
12 IriSP.jQuery.get(url, (function(obj) { |
14 IriSP.jQuery.get(url, (function(obj) { |
13 return function(data) { |
15 return function(data) { |
14 obj._cache[url] = data; |
16 obj._cache[url] = data; |
15 callback(obj._cache[url]); |
17 callback(obj._cache[url]); |
16 }; |
18 }; |
17 })(this)); |
19 })(this)); |
|
20 */ |
18 |
21 |
19 } |
22 } |
20 } |
23 } |
21 |
24 |
22 /* the base abstract "class" */ |
25 /* the base abstract "class" */ |
25 this._url = url; |
28 this._url = url; |
26 }; |
29 }; |
27 |
30 |
28 IriSP.Serializer.prototype.serialize = function(data) { }; |
31 IriSP.Serializer.prototype.serialize = function(data) { }; |
29 IriSP.Serializer.prototype.deserialize = function(data) {}; |
32 IriSP.Serializer.prototype.deserialize = function(data) {}; |
|
33 |
|
34 IriSP.Serializer.prototype.currentMedia = function() { |
|
35 return {"meta" : {"dc:duration" : 10000000}}; /* dummy object for unit testing */ |
|
36 }; |
|
37 |
|
38 IriSP.Serializer.prototype.sync = function(callback) { |
|
39 callback.apply(this, []); |
|
40 }; |
30 |
41 |
31 IriSP.JSONSerializer = function(DataLoader, url) { |
42 IriSP.JSONSerializer = function(DataLoader, url) { |
32 IriSP.Serializer.call(this, DataLoader, url); |
43 IriSP.Serializer.call(this, DataLoader, url); |
33 } |
44 } |
34 |
45 |
42 return JSON.parse(data); |
53 return JSON.parse(data); |
43 }; |
54 }; |
44 |
55 |
45 IriSP.JSONSerializer.prototype.sync = function(callback) { |
56 IriSP.JSONSerializer.prototype.sync = function(callback) { |
46 /* we don't have to do much because jQuery handles json for us */ |
57 /* we don't have to do much because jQuery handles json for us */ |
|
58 |
|
59 /* a wrapper to get a closure because we lose this in callbacks */ |
47 var wrapper = function(obj) { |
60 var wrapper = function(obj) { |
48 return function(data) { |
61 return function(data) { |
49 obj._data = data; |
62 obj._data = data; |
50 callback(data); |
63 callback(data); |
51 } |
64 } |
52 }; |
65 }; |
53 |
66 |
54 this._DataLoader.get(this._url, wrapper(this)); |
67 this._DataLoader.get(this._url, wrapper(this)); |
|
68 }; |
|
69 |
|
70 IriSP.JSONSerializer.prototype.currentMedia = function() { |
|
71 return this._data.medias[0]; /* FIXME: don't hardcode it */ |
55 }; |
72 }; |
56 |
73 |
57 IriSP.SerializerFactory = function(DataLoader) { |
74 IriSP.SerializerFactory = function(DataLoader) { |
58 this._dataloader = DataLoader; |
75 this._dataloader = DataLoader; |
59 }; |
76 }; |