src/js/serializers/JSONSerializer.js
branchpopcorn-port
changeset 108 62da43e72e30
child 128 f3fec80dd31c
equal deleted inserted replaced
107:2edab45f0e90 108:62da43e72e30
       
     1 
       
     2 IriSP.JSONSerializer = function(DataLoader, url) {
       
     3   IriSP.Serializer.call(this, DataLoader, url);
       
     4 };
       
     5 
       
     6 IriSP.JSONSerializer.prototype = IriSP.Serializer;
       
     7 
       
     8 IriSP.JSONSerializer.prototype.serialize = function(data) {
       
     9   return JSON.stringify(data);
       
    10 };
       
    11 
       
    12 IriSP.JSONSerializer.prototype.deserialize = function(data) {
       
    13   return JSON.parse(data);
       
    14 };
       
    15 
       
    16 IriSP.JSONSerializer.prototype.sync = function(callback) {
       
    17   /* we don't have to do much because jQuery handles json for us */
       
    18   
       
    19   /* a wrapper to get a closure because we lose this in callbacks */
       
    20   var wrapper = function(obj) {
       
    21     return function(data) {    
       
    22       obj._data = data;
       
    23       // sort the data too
       
    24       obj._data["annotations"].sort(function(a, b) 
       
    25           { var a_begin = +a.begin;
       
    26             var b_begin = +b.begin;
       
    27             return a_begin - b_begin;
       
    28           });
       
    29       callback(data);
       
    30     }
       
    31   };
       
    32   
       
    33   this._DataLoader.get(this._url, wrapper(this));
       
    34 };
       
    35 
       
    36 IriSP.JSONSerializer.prototype.currentMedia = function() {  
       
    37   return this._data.medias[0]; /* FIXME: don't hardcode it */
       
    38 };