src/js/serializers/JSONSerializer.js
author hamidouk
Thu, 20 Oct 2011 15:59:28 +0200
branchpopcorn-port
changeset 108 62da43e72e30
child 128 f3fec80dd31c
permissions -rw-r--r--
broke the serializers across multiple files. added a newline to the end of segmentsWidget.js.


IriSP.JSONSerializer = function(DataLoader, url) {
  IriSP.Serializer.call(this, DataLoader, url);
};

IriSP.JSONSerializer.prototype = IriSP.Serializer;

IriSP.JSONSerializer.prototype.serialize = function(data) {
  return JSON.stringify(data);
};

IriSP.JSONSerializer.prototype.deserialize = function(data) {
  return JSON.parse(data);
};

IriSP.JSONSerializer.prototype.sync = function(callback) {
  /* we don't have to do much because jQuery handles json for us */
  
  /* a wrapper to get a closure because we lose this in callbacks */
  var wrapper = function(obj) {
    return function(data) {    
      obj._data = data;
      // sort the data too
      obj._data["annotations"].sort(function(a, b) 
          { var a_begin = +a.begin;
            var b_begin = +b.begin;
            return a_begin - b_begin;
          });
      callback(data);
    }
  };
  
  this._DataLoader.get(this._url, wrapper(this));
};

IriSP.JSONSerializer.prototype.currentMedia = function() {  
  return this._data.medias[0]; /* FIXME: don't hardcode it */
};